Top 50 Unix commands

1. alias
Alias allows you to substitute a small or more familiar name in place of a long string.

Example: This usage will tailor the du command to use 1k units:

# alias du=du -k

2. awk
Awk searches for patterns in a file and processes them. It enables a programmer to write small programs in the form of statements to make changes in text files when certain patterns appear or extract data from those files. This command simplifies a process historically done in C or Pascal languages. (Learn more in this Linux shell scripting tutorial on awk.)

Example: This will count the number of lines in the file – similar to wc –l

 # awk ‘END{print NR}’

3. cat
Abbreviated from the word “concatenate,” which means to link things together, cat is used in Unix to link file contents and output them for viewing or printing. It is also used to display a file.

Example: This will view the /etc/hosts file.

 # cat /etc/hosts

4. cd
The cd command sets the working directory of a process.

Example: This usage will change the directory to your home directory, assuming your HOME variable is defined

 #  cd $HOME

5. chmod
Chmod is a utility that changes the permission of a file.

Example: This will change the permission of the file called newfile to read, write and execute (rwx) for owner, group and other.

 # chmod 777 newfile

6. chown
A utility used to change file ownership.

Example: This usage will change the ownership of the file called newfile to frank.

 # chown frank newfile

7. cp
The cp command is used to copy files.

Example: This usage will copy the file testdb to another directory on the system.

 # cp /tmp/testdb /home/frank/testdb

8. cpio
This command is used to copy and move around files and directories. It also backs up empty directories which restores files from an archive or creates an archive.

Example: This will copy all files and directories in the current directory to another directory called /user/newfiles.

 # find ./ -depth | cpio –pdmv /usr/newfiles

9. crontab
Crontab is used for manipulating cron – used to schedule tasks.

Example: This usage displays your crontab file:

 # crontab -l

10. df
The df command reports filesystem disk space usage.

Example: This example displays disk space in kilobytes.

# df -k

11. du
The du command reports back the sizes of directory trees.

Example: This command reports summarizes the file size from the directory which you are running the command from.

# du –s

12. env
The env command displays information about your current environment.

Example: This command displays all your environment variables

# env

13. echo
This command lets you echo a string variable to standard output.

Example: This reports back “Hello World”

#  echo Hello World

14. enable
Enables or disables a printer.

Example: This enables printer1.

# enable printer1

15. exit
Allows you to exit from a program, shell or UNIX network.

Example: This exits the shell.

# exit

16. export
Export sets the value of a variable so it is visible to all sub-processes that belong to the current shell.

Example: This command exports the TERM variable.

# TERM=vt220 ; export $TERM

17. exportfs
This command maintains a list of NFS exported file systems.

Example: This usage exports all directories

# exportfs -a

18. find
Find searches the directory tree rooted at each given file name by evaluating the given expression from left to right, according to the rules of precedence (see section OPERATORS), until the outcome is known (the left hand side is false for and operations, true for or), at which point find moves on to the next file name.

Example: This command searches for all the files and directories in a given directory and sends them to standard output.

# find ./ -depth

19. ftp ftp allows for the copying of files back and forth on different host machines.

Example: This command starts up ftp

# ftp

20. grep
Grep is a command used for searching one or more files for a given character string or pattern. It can also be used to replace the character string with another one.

Example: this usage searches for instances of hello within the file text.txt

# grep hello text.txt

21. gzip
gzip is a compression utility designed to be a replacement for compress. Its main advantages over compress are much better compression and freedom from patented algorithms. It has been adopted by the GNU project and is now relatively popular on the Internet. gzip was written by Jean-loup Gailly and Mark Adler for the decompression code.

Example: This usage compresses the file and renames it to test2 in gzip format. gunzip is used to uncompress a gzip file.

# gzip -c testfile  > test2.gz

22. id
This command prints out real and effective UIDs and GIDs.

Example: This usage shows all the uids and gids which show in your /etc/passwd.

# id

23. ifconfig
ifconfig checks a network interface configuration. It can be used, for example, to verify a user’s configuration if the user’s system has been recently configured or if the user’s system cannot reach the remote host while other systems on the same network can.

Example: This usage shows all the adapter information.

# ifconfig –a

24. ifup
Starts up a network interface.

Example: This usage brings up the interface en0

# ifup en0

25. ifdown
Shuts down the network interface.

Example: This usage brings down all interfaces which are up.

# ifdown -a

26. head
This outputs the first part of a file

Example: This usage displays the first ten lines in the /etc/hosts file.

#  head -10 /etc/hosts

27. last
The last command shows the last users who logged into the system.

Example: This usage lists out the shutdown times and run-level changes

#  last -x

28. ln
The ln command establishes links between files.

Example: This usage establishes a symbolic link between two files.

#  ln -s sourcefile newfile

29. ls
The ls command shows information about files. With it, system administrators can list the contents of a directory in order to determine when the configurations files were last edited. There are many subcommands under ls, such as ls-r, which can reverse the order in which files are displayed. (The ls command is also discussed in this tip on troubleshooting tools.)

Example: This usage shows a long listing of file information in the data directory.

# ls –l data

30. man
Short for “manual,” man unveils information about commands and a keyword search mechanism for needed commands. (The man command is also discussed in this tip on troubleshooting tools.)

Example: This usage prints out information on the tar command

# man tar

31. mv
This command moves a file to a different directory or filesystem.

Example: This usage moves the file test to the /tmp directory

#  mv test /tmp

32. netstat
The netstat command shows the network status by symbolically displaying the contents of various network-related data structures. There are a number of output formats, depending on the options for the information presented.

Example: This usage shows the routing table.

#  netstat –r

33. ping
The ping command (named after the sound of an active sonar system) sends echo requests to the host you specify on the command line, and lists the responses received their round trip time. When you terminate ping (probably by hitting control-C) it summarizes the results, giving the average round trip time and the percent packet loss. This command is used constantly to determine whether there is a problem with the network connection between two hosts.

Example: This usage sends echo requests to hosta.

#  ping hosta

34. ps
The ps command reports back process status. There are two ways that this is used – the System V way and the Berkeley method. The Berkeley method does not use the dash (-) before flags.

Example: This usage reports pack process info using the System V method

#  ps –ef

35. pwd
pwd is short for print working directory. The pwd command displays the name of the current working directory.

Example: This usage reports back the directory you are currently in

#  pwd

36. rsync
rsync is focused on synching data from one disk location to another. It was created by Andrew Tridgell, one of Samba’s core team.

Example: This usage will transfer all files matching the pattern *.d from the current directory to the directory data on the machine hosta. (Learn more from this tip on Rsync and Amanda

# rsync *.d hosta:data/

37. rm
The rm command is used to remove a file or a group of files.

Example: This usage will prompt the user to make sure they want to delete the files in the directory before doing so

#  rm –i *

38. sed
sed (streams editor) isn’t really a true text editor or text processor. Instead, it is used to filter text, i.e., it takes text input and performs some operation (or set of operations) on it and outputs the modified text. Sed is typically used for extracting part of a file using pattern matching or substituting multiple occurrences of a string within a file.

Example: This usage inserts a blank line below every line which matches “test”.

# sed ‘/test/G’

39. shutdown
Shutdown is a command that turns off the computer and can be combined with variables such as -h for halt or -r for reboot.

Example: This usage reboots the box in AIX. Because the flags are a bit different between Unix flavors – do a man before running shutdown on your flavor.

# shutdown -Fr

40. sudo
Sudo (superuser do) allows a system administrator to give certain users (or groups of users) the ability to run some (or all) commands as root or another user while logging the commands and arguments.

Example: Assuming the user that is using sudo has already been configured to do so, this command allows him to run the adduser command as if he were root.

$ sudo -u root adduser testuser

41. ssh
Ssh is used for secure network connections and tunneling of TCP services. OpenSSH is one open source SSH version. (See these examples of how to use ssh with Unix).

Example: This usage connects user ken to

# ssh -l ken

42. tar
The tar program provides the ability to create tar archives, as well as various other kinds of manipulation. For example, you can use tar on previously created archives to extract files, store additional files, or update or list files. Initially, tar archives were used to store files on magnetic tape. The name “tar” comes from this use; it stands for “tape archiver.” Despite the utility’s name, tar can direct its output to available devices, files, or other programs. Tar may even access remote devices or files.

Example: This usage creates a tar archive to tape device st0 – with the contents of /home:

# tar -cvf /dev/st0 /home

43. tail
The tail command outputs the last part of a file.

Example: This usage displays the last ten lines of the /etc/hosts file.

#  tail -10 /etc/hosts

44. traceroute
traceroute determines a route to the host and is very useful for distinguishing network/router issues. If the domain does not work or is not available you can traceroute an IP.

Example: This usage runs a traceroute to an inaccessible domain to try to determine the cause of the problem.

#  traceroute

45. uname
uname prints system name and other related information about your system.

Example: This usage displays a long-listing of system information.

# uname -a

46. vi
vi is a screen-based editor preferred by the vast majority of Unix users.

Example: This usage brings up vi in editor mode – to edit the /etc/hosts file.

#  vi /etc/hosts

Learn more in this tutorial: Mastering the vi editor

47. vmstat
The vmstat command is used to get a snapshot of everything going on in the system – helping systems administrators determine whether the bottleneck is CPU, memory or I/O. Run this command to get virtual memory statistics.

Example: This usage starts up vmstat and runs it every two seconds for ten iterations.

# vmstat 2 10

48. w
The w command prints a summary of current system and user information, while also letting you know who is logged in to the system and what they are doing.

Example: this usage prints out a short version of information.

# w –s

49. who
The who command displays the users who are logged on to the system.

Example: This usage lists all the available output of the who command for each user.

# who –a

50. whoami
The whoami command displays who the user is that you are logged on as. This is very useful for those of you that have different logins.

Example: This usage displays the name of the user that you are presently logged in as.

# whoami




About PiroNet

Didier Pironet is an independent blogger and freelancer with +15 years of IT industry experience. Didier is also a former VMware inc. employee where he specialised in Datacenter and Cloud Infrastructure products as well as Infrastructure, Operations and IT Business Management products. Didier is passionate about technologies and he is found to be a creative and a visionary thinker, expressing with passion and excitement, hopefully inspiring and enrolling people to innovation and change.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s