du, find, Redirection, Pipes, tar, gzip, gunzip, bzip2, bunzip2, compress, uncompress commands:

To view the size of Current working directory:

du -sh


To view the size of specified directory:

du -sh /parent-directory/dir1


Redirection:

cat file1 > newfile          
(Redirects the output of the file1 to a file 'newfile')

cat file2 >> existfile
(Appends the output of file2 to the end of 'existfile')

 

Note:
The redirection directives, > and >> can be used on the output of most commands to direct their output to a file.

 

Pipes:
The pipe symbol "|" is used to direct the output of one command to the input of another.

 

For example:

ls -l | more
(This commands takes the output of the long format directory list command "ls -l" and pipes it through the more command (also known as a filter). In this case a very long list of files can be viewed a page at a time.

 

du -sc * | sort -n | tail

 

(The command "du -sc" lists the sizes of all files and directories in the current working directory. That is piped through "sort -n" which orders the output from smallest to largest size. Finally, that output is piped through "tail" which displays only the last few (which just happen to be the largest) results.


Command Substitution
You can use the output of one command as an input to another command in another way called command substitution. Command substitution is invoked when by enclosing the substituted command in backwards single quotes. For example:

cat `find . -name aaa.txt`
(which will cat ( dump to the screen ) all the files named aaa.txt that exist in the current directory or in any subdirectory tree. )

 

Note:
. (dot) = current directory

 

Searching for strings in files: The grep  command
grep string filename    prints all the lines in a file that contain the string

 

Searching for files : The find command
find search_path -name filename

 

find . -name aaa.txt   
(Finds all the files named aaa.txt in the current directory or any subdirectory tree.

 

find / -name vimrc     
(Find all the files named 'vimrc' anywhere on the system.)

 

find /usr/local/games -name "*xpilot*"
(Find all files whose names contain the string 'xpilot' which exist within the '/usr/local/games' directory tree)

 

Reading and writing tapes, backups, and archives: The tar command 
The tar command stands for "tape archive". It is the "standard" way to read and write archives (collections of files and whole directory trees).

 

Often you will find archives of stuff with names like stuff.tar, or stuff.tar.gz.  This is stuff in a tar archive, and stuff in a tar archive which has been compressed using the gzip compression program respectivly.

 

Chances are that if someone gives you a tape written on a UNIX system, it will be in tar format,
and you will use tar (and your tape drive) to read it.

 

Likewise, if you want to write a tape to give to someone else, you should probably use tar as well.

 

Tar examples:

tar xv     
(Extracts (x) files from the default tape drive while listing (v = verbose) the file names to the screen.

tar tv     
(Lists the files from the default tape device without extracting them)

 

tar cv file1 file2     
(Write files 'file1' and 'file2' to the default tape device)

 

tar cvf archive.tar file1 [file2...]  
(Create a tar archive as a file "archive.tar" containing file1, file2...etc.)

 

tar xvf archive.tar  extract from the archive file

tar cvfz archive.tar.gz dname   
(Create a gzip compressed tar archive containing everything in the directory 'dname'. This does not work with all versions of tar.)

 

tar xvfz archive.tar.gz         
(Extract a gzip compressed tar archive, does not work with all versions of tar.)

 

tar cvfI archive.tar.bz2 dname  
Create a bz2 compressed tar archive. Does not work with all versions of tar.)

 

File compression: compress, gzip, and bzip2
The standard UNIX compression commands are compress and uncompress. Compressed files have a suffix .Z added to their name. For example:

 

compress part.igs   
(Creates a compressed file part.igs.Z)

 

uncompress part.igs 
(Uncompresses part.igs from the compressed file part.igs.Z)

 

Note:  The .Z is not required.

Another common compression utility is gzip (and gunzip). These are the GNU compress and uncompress utilities.  gzip usually gives better compression than standard compress, but may not be installed on all systems.  The suffix for gzipped files is .gz

 

gzip part.igs
(Creates a compressed file part.igs.gz)

 

gunzip part.igs
(Extracts the original file from part.igs.gz)

 

The bzip2 utility has (in general) even better compression than gzip, but at the cost of longer times to compress and uncompress the files. It is not as common a utility as gzip, but is becoming more generally available.

 

bzip2 part.igs
(Create a compressed Iges file part.igs.bz2)

 

bunzip2 part.igs.bz2
(Uncompress the compressed iges file)

Connect With Us
Instant Query
Your Name :

Email Address :

Message :