Sunday 15 April 2012

Redirecting Input /Output,Symbolic links,Checking Free Space In Linux


Redirecting Input /Output:-



The standard Output of command , which normally display on the terminal can be redirected into a file. Similarly standard error, which normally display on the terminal can be redirected into a file.
Common redirection operator

>          :           command>file                        :           output command to file
>>        :           command>>file          :           Append output of command to file
<          :           command>file                        :           receive input from file
2>        :           command2>file          :           error from command to file
2>>      :           command2>>file        :           append

Example:
#find /etc –name passwd
this command will search for all file name passwd in /etc and its subdirectories
now we can redirtect the standard outpout
#find /etc –name passwd > output
output is a file where command output will be stored. Standard error is still displayed on the screen
#cat output
If the target file of the file redirection with > already exists, the existing file will be overwritten. To append data to an existing file use >> to redirect instead of >
#find /etc –name passwd >> output

Redirecting standard Error
We can redirect standard error with 2>
#find /etc –name passwd 2>errorfile
standard output is displayed on the screen , redirect further standard error, appending to the same file with 2>>
#find /etc/ -name passwd 2>>errorfile
#cat errorfile

Symbolic links: 

A symbolic link point to another file. We can display the link name and the referenced file by ‘ls –l’
#ls –l pf
lrwxrwxrwx 1 root root        pf->/etc/passwd
file type:          l for symbolic link
the content of the symbolic link is the name of the file that is referenced
Syntax:
            Ln –s filename [linkname]
Example:
            Ln –s /etc/passwd password
There are seven fundamental file type
-           :           regular file
d          :           symbolic link
b          :           block special file
c          :           character special file
p          :           named file
s           :           socket

character special file are used to communicate with hardware one character at a time. Block special file is used to communicate with hardware a block of data at a time : 512 bytes, 1024 bytes, 2048 bytes
ls –l /dev |less  { to check c and b files}
named pipe type of file that passes data between processes. It stores no data itself socket file are used for inter process communication.

Checking Free Space:

In order to check the free and usage space per file system and directory and each sub directory we have two command
    1. df
    2. du
the ‘df’ command reports on a per file system basis. It report total disk space , disk space used , disk space free
#df –h
-h         : used multipliers such as G or M for gigabytes and Megabytes

The ‘du’ command reports the number of kilobytes contained by the items within a directory
#du –s
#du –h
-s         :           used to request only the summary directory information
#du –s /etc
Thanks,

No comments:

Post a Comment