Several years ago, I wrote a tip introducing the top Linux commands and utilities and also contributed to TechTarget's effort identifying and describing the commands. During this go-around, we'll

Continue Reading This Article

Enjoy this article as well as all of our content, including E-Guides, news, tips and more.

do the same with Unix. Some of you not as familiar with Unix, might ask the question, "isn't Unix and Linux basically the same thing?" The short answer is, "No."

Differentiating Unix from Linux: Some history
Let's briefly outline the fundamental differences. We'll start with Linux. Linux roots trace back to 1983, when Richard Stallman started the GNU project. The goal was to create a free Unix-like system. The GNU General Public License (GPL) was also created by Stallman. In 1987, Andrew Tanenbaum released MINIX, a Unix-like system, which unfortunately was not well adapted to the 32-bit features of the Intel 386 architecture and lacked a fully-functioning kernel. This spawned Linux in 1991. Linus Torvalds actually wrote the program on a 386 processor using the GNU C compiler on MINIX.

The roots of Unix go back much further, into the 1960s, when AT&T's Bell Labs partnered with MIT and GE to develop a multi-user operating system called Multics. Dennis Ritchie and Ken Thompson worked on this project up until the time that AT&T withdrew from it. This OS was developed in an attempt to port a computer game to a DEC PDP-7 computer. This version was named Unics, which eventually evolved into Unix. Unix would evolve into two branches, BSD and System V. The BSD model, developed by the University of California Berkeley – was considered more academic while System V was perceived as being more commercial. Interestingly enough, the original Sun OS was based on BSD but the pendulum swung the other way with the release of Solaris V5, where it was based on System V, release V. Today, there are three popular Unix flavors that dominant this market – HP-UX, AIX and Solaris. Solaris and HP-UX are System V based, while AIX is an interesting Hybrid of both. An example of this is printing. AIX offers lpr (BSD version), lp (System V) and even their own propriety way of printing using qprt. In many ways this is very typical of AIX, though all of these flavors have many proprietary differences, from kernel, monitoring and tuning commands, to networking configuration, virtualisation and other processes.

Perhaps the most fundamental difference between Unix and Linux is that the bulk of the work on Linux (though Red Hat or Novell might dispute this) is really performed by the community: the thousands of programmers around the world that use Linux and send in their suggested improvements. Without a doubt, the top companies that commercially sell Linux distributions contribute to the development of the kernel, while also adding added-value software that is shipped with the OS, but the kernel itself is maintained by Linus and his team. For all intents and purposes - Torvalds (who owns the Linux trademark) remains the ultimate authority on the new code which is incorporated into the standard Linux kernel This is not the case with Unix – each of the hardware vendors pretty much do there own thing with their versions of Unix – Solaris, HP-UX and AIX, though interestingly enough, Novell owns the actual rights to Unix.

Top 50 Unix commands
Disclaimer: The 50 Unix commands presented here will only discuss commands that are available on all flavors. A following article will discuss some fundamental differences between these flavors and also detail some of the command-line differences on how to administrate and configure essential processes on each system. Why is it important to do this? There are literally thousands of commands that a UNIX administrator has at their disposal. The reality is that even the most advanced administrators will only use a finite number of tools and utilities on an ongoing basis. They also try to master these specific commands and utilities that help them become better administrators. Are some of the commands similar to the Linux in our original top 50? Absolutely, but there are enough differences to warrant a new revised list as well as a revised numbering order. We'll also add some content to the changes in that original list as appropriate to Unix. A small sampling of some of the commands we'll see here, which you won't find on the original list, include – ps, w, who, uname, id. Some of the commands you'll find on both lists include, cron, vmstat, vi, netstat and find.

 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 historicaly 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 summarises 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 summarises 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 hostb.com

 # ssh -l ken hostb.com

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 hostc.org

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 THE AUTHOR: Ken Milberg is a systems consultant with two decades of experience working with Unix and Linux systems. He is a SearchEnterpriseLinux.com Ask the Experts advisor and columnist.


Looking for information about a Unix user group? Read the UK directory for server, platform users: Windows, Unix, Linux user groups.

This was first published in July 2009

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.