Wednesday, 15 April 2015

How to Extract (untar) an archive

Extract a *.tar file using option xvf

Extract a tar file using option x as shown below:
tar xvf archive_name.tar
  • x – extract files from archive

Extract a gzipped tar archive ( *.tar.gz ) using option xvzf

Use the option z for uncompressing a gzip tar archive.
tar xvfz archive_name.tar.gz

Extracting a bzipped tar archive ( *.tar.bz2 ) using option xvjf

Use the option j for uncompressing a bzip2 tar archive.
tar xvfj archive_name.tar.bz2
 
Note: In all the above commands v is optional, which lists the file being processed.

How to create a bzipped tar archive

tar cvfj archive_name.tar.bz2 dirname/
  • j – filter the archive through bzip2
gzip vs bzip2: bzip2 takes more time to compress and decompress than gzip. bzip2 archival size is less than gzip.
Note: .tbz and .tb2 is same as .tar.bz2

How to create a tar gzipped archive

tar cvzf archive_name.tar.gz dirname/

z – filter the archive through gzip

gzip vs bzip2: bzip2 takes more time to compress and decompress than gzip. bzip2 archival size is less than gzip.
Note: .tbz and .tb2 is same as .tar.bz2

How to Create an uncompressed tar archive

tar cvf archive_name.tar dirname/

In the above command:
  • c – create a new archive
  • v – verbosely list files which are processed.
  • f – following is the archive file name

How to count all files and directories in a Linux directory

count of all files and directories in the current directory - echo * | wc
count of only the directories in the current directory - echo */ | wc
count of just the files in a directory - echo *.* | wc

What is the command of finding smallest files in a directory

Answer:-
ls -AlSr|head -4

What is the command to find largest files in a directory

Answer:-
ls -AlS|head -4

What is the command to find last accessed file in a directory

Answer:-
ls -Alu|head -2

What is command to find last modified file in a directory

Answer:-
ls -Alt|head -2

What is the command to find largest file within multiple subdirectories

Answer:-
find . -printf '%s %p\n'|sort -nr|head