Help, Output Redirection & Pipelining


Man
Every Linux system has some well documented Manuals to help users get information about commands and services. These manuals can be accessed using the command

# man  command/file
syntax
# man ls
shows the manual of the command ‘ls’
# man resolv.conf

shows the manual of the file ‘/etc/resolv.conf’

Some manuals contain further references at the bottom. These references usually contain page numbers that can be accessed using –
# man 5 resolv.conf
shows page no. 5 of resolv.conf

whereis, whatis & which

whatis displays an overview of the command. whereis & whatis have similar output that contains the location where the command is stored, as well as files related to the command.
# whatis pwd
pwd                  (1p)  - return working directory name
pwd                  (1)  - print name of current/working directory
pwd [builtins]       (1)  - bash built-in commands, see bash(1)
pwd.h [pwd]          (0p)  - password structure

# whatis cp
cp                   (1)  - copy files and directories
cp                   (1p)  - copy files

# whereis pwd
pwd: /bin/pwd /usr/share/man/man1/pwd.1.gz /usr/share/man/man1p/pwd.1p.gz

# which pwd
/bin/pwd


Output Redirections

Output can be redirected from one place to another by using the”>” sign. For example:

# echo hello
Shows hello in the terminal
# echo hello > /root/greetings
Instead of showing hello in the terminal, creates a new file /root/greetings and dumps ‘hello’ there.
# cat /etc/passwd
Shows the content of the file in the terminal
# cat /etc/passwd> /root/user_info
Instead of showing the file in the terminal, creates a new file /root/user_info and dumps the output there.

Redirecting output this way always overwrites the output file. To append in the output file, the sign “ >> ” is used.
# echo hello >> /root/user_info
Appends hello at the bottom the file /root/user_info

Pipelining

Pipelining ( | ) is applied to use the output of one command as input of the next command. For example-
# cat /etc/passwd | grep root
The first command’s output is the entire content of the file /etc/passwd. The second command filters ‘root’ from the output of the first command.
# tailf /var/log/maillog | grep palash
The output of the first command shows entries of the mail log in real time, and the second command filters the output and shows ‘palash’ only

Comments