Share

Showing posts with label Best Practice. Show all posts
Showing posts with label Best Practice. Show all posts

Tuesday, December 29, 2015

listing directories only from tar file

Recently I faced one requirement where i had to list only certain level of directories with "tar -tvf" (or) "jar -tvf" output.

Here is my sample tar file. where I need to list only two levels of files/directories.

bash-3.2# tar -tvf content.tar
drwxr-xr-x   0/0        0 Dec 29 16:58 2015 direcotry2/
drwxr-xr-x   0/0        0 Dec 29 16:58 2015 direcotry2/directory2a/
drwxr-xr-x   0/0        0 Dec 29 17:00 2015 direcotry2/directory2a/directory2a_media/
-rw-r--r--   0/0       33 Dec 29 17:01 2015 direcotry2/directory2a/directory2a_media/home.html
drwxr-xr-x   0/0        0 Dec 29 16:58 2015 direcotry2/directory2a/directory2a_business/
drwxr-xr-x   0/0        0 Dec 29 16:58 2015 direcotry2/directory2b/
drwxr-xr-x   0/0        0 Dec 29 16:58 2015 direcotry2/directory2c/
drwxr-xr-x   0/0        0 Dec 29 16:56 2015 directory1/
drwxr-xr-x   0/0        0 Dec 29 16:57 2015 directory1/directory1_a/
drwxr-xr-x   0/0        0 Dec 29 16:57 2015 directory1/directory1_a/directory1a_media/
-rw-r--r--   0/0       33 Dec 29 17:00 2015 directory1/directory1_a/directory1a_media/media.html
-rw-r--r--   0/0       33 Dec 29 17:00 2015 directory1/directory1_a/directory1a_media/home.html
drwxr-xr-x   0/0        0 Dec 29 16:57 2015 directory1/directory1_a/directory1a_press/
-rw-r--r--   0/0        0 Dec 29 16:57 2015 directory1/directory1_a/directory1a_press/press.html
-rw-r--r--   0/0        0 Dec 29 16:57 2015 directory1/directory1_a/directory1a_press/welcome.html
drwxr-xr-x   0/0        0 Dec 29 16:55 2015 directory3/


The "awk" way:

Listing the parent directories alone:


bash-3.2# tar -tvf content.tar |awk -F/ '{if(NF==3) print}'
drwxr-xr-x   0/0        0 Dec 29 16:58 2015 direcotry2/
drwxr-xr-x   0/0        0 Dec 29 16:56 2015 directory1/
drwxr-xr-x   0/0        0 Dec 29 16:55 2015 directory3/



Listing the Parent directories with its sub - directories(or) files
bash-3.2# tar -tvf content.tar |awk -F/ '{if(NF==4) print}'
drwxr-xr-x   0/0        0 Dec 29 16:58 2015 direcotry2/directory2a/
drwxr-xr-x   0/0        0 Dec 29 16:58 2015 direcotry2/directory2b/
drwxr-xr-x   0/0        0 Dec 29 16:58 2015 direcotry2/directory2c/
drwxr-xr-x   0/0        0 Dec 29 16:57 2015 directory1/directory1_a/



Another level down
bash-3.2# tar -tvf content.tar |awk -F/ '{if(NF==5) print}'
drwxr-xr-x   0/0        0 Dec 29 17:00 2015 direcotry2/directory2a/directory2a_media/
-rw-r--r--   0/0       33 Dec 29 17:01 2015 direcotry2/directory2a/directory2a_media/home.html
drwxr-xr-x   0/0        0 Dec 29 16:58 2015 direcotry2/directory2a/directory2a_business/
drwxr-xr-x   0/0        0 Dec 29 16:57 2015 directory1/directory1_a/directory1a_media/
-rw-r--r--   0/0       33 Dec 29 17:00 2015 directory1/directory1_a/directory1a_media/media.html
-rw-r--r--   0/0       33 Dec 29 17:00 2015 directory1/directory1_a/directory1a_media/home.html
drwxr-xr-x   0/0        0 Dec 29 16:57 2015 directory1/directory1_a/directory1a_press/
-rw-r--r--   0/0        0 Dec 29 16:57 2015 directory1/directory1_a/directory1a_press/press.html
-rw-r--r--   0/0        0 Dec 29 16:57 2015 directory1/directory1_a/directory1a_press/welcome.html


Just change the "NF" value according to your requirement.

you can use this in case of  "jar -tvf" as well

Hope it helps. Comments welcome.


Saturday, October 31, 2015

Create PDF quickly just with browser. Replace your notepad with your browser


When there is urgent requirement to make a note of  something important..  We used to rush to desktop (or) Run prompt to get the notepad app..

There is an easy and simplest way to do this just with browser. Replace your notepad now.

Additionally, You can save your notes as PDF too.  Say bye to old .txt files and save your notes as PDF.

Here you go..

Open the browser  ( I have taken chrome here )

Set the font (optional)
 
Generally Browsers will be coming with their default  fonts. If you want to change it.

Before exploring it change the default font of  your browser.

In firefox:  it will be under options/content section as shown below.
in chrome:  Goto Settings-> Advanced Settings  ->Customize fonts







Open a new tab and copy/type the below lines in address bar (as it is)

data:text/html, <html contenteditable>


 

Now start typing..



In most cases we are not really saving the notepad documents. if you would like to save..

here is the way.

you should be having the print pdf addon.  it comes as builtin with modern browsers but if you don't have it get the add-on and install..

for firefox: it can be downloaded here.
in chrome:  Its built in !! 

Now Just "CTRL+p" and save as PDF  thats it!!!...

 
Here is your document in PDF.. Have fun :)






follow us at  https://www.facebook.com/middlewareinventory/


Comments welcome !!.