Friday, May 11, 2012

Basic Unix Commands

1) Command : man
Use : This command is used for getting help about UNIX commands.
Syntax : man <command name>

2) Command : grep
Use : This command is used to search for a particular expression in the given input.
Syntax : grep [OPTION]... PATTERN [FILE]...
e.g. : grep <pattern> <file> ---> It can be used to search from lines matching pattern from file.
grep -v <pattern> <file> --> It can be used to search for lines not matching pattern from file.

3) Command : ps
Use : This command is used to see the processes running on the system.
Syntax : ps [options]
e.g. : ps -ef ---> It can used to see the all processes from all users.
ps -ef | grep <process_name> | grep -v grep ---> It can be used to check whether a particular process is running or not.
ps -fu <user_name> ---> It can be used to see all processes started by a particular user.

4) Command : uptime
Use :This command is used check the server/system run duration and number of users currently logged on.
Syntax : uptime
e.g. : user@machine :~$ uptime
17:16:31 up 7:34, 1 user, load average: 0.83, 0.87, 1.03

5) Command : whatis
Use : This command displays manual page descriptions.
Syntax : whatis <command_name>
e.g. : user@machine :~$ whatis firefox
firefox (1) - a free and open source web browser from Mozilla

6) Command : kill
Use : This command send a signal ( default SIGTERM ) to a process.
Syntax : kill <process_id>
e.g. : kill 123 543 2341 3453 ---> Send the default signal, SIGTERM, to all those processes.

7) Command : ls
Use : This command is used to list directory contents.
Syntax : ls [OPTION]... [FILE]...
e.g. : ls -l ---> It shows a log list of all files in the current directory.

8) Command : rm
Use : This command is used to remove files or directories.
Syntax : rm [OPTION]... [FILE]...
e.g. : rm <file_name> ---> It removes the <file_name> .
rm -r <directory_name> --> It removes <directory_name> and all the files/directory inside it.

9) Command : xargs
Use : This command build and execute command lines from standard input.
Syntax : <some_command> | xargs <another_command >
e.g. : ls <file_name_pattern> | xargs rm ---> It is used to delete all files as shown by  output of ls <file_name_pattern> .