A quick guide to the unix toolset
This page is a "cheat sheet" for Unix/Linux. It quickly explains the more common commands, and shows you how to use them.
General Commands
- man man - read the 'man'
manual page.
- man command - read the 'command' manual page.
- man bash - read the 'bash' manual page.
- man -k file - list all programs that deal with files.
- date - print the current date and time.
- cal - print this month's calendar.
- cal 2004 - print calendar for 2004.
- finger - display information about other users on the system who are logged on.
- finger username - look up information about the named user.
- who - show who is currently on the system and what they are doing.
File Manipulation
- ls - list the names of all the files in the current directory.
- ls -l - list the names of all the files in the current directory in long format.
- ls -a - list all the files, including hidden files, in the current directory.
- ls -lrt list the names of all the files in the current directory in long format and
reverse chronological order.
- ls
*.pl - list all the files that have the extension pl.
- cat file1 - print the contents of file1 onto the terminal screen.
- more file1 - look at file1 one page at a time. Press the space bar to see another
page, the return key to see another line. Type q to quit.
- head file1 - print the first 10 lines of file1.
- tail file1 - print the last 10 lines of file1.
- head -30 file1 - print the first 30 lines of file1.
- cp file1 file2 - make a copy of file1 and call it file2.
- mv file1 file2 - change the name of file1 to be file2.
- gzip large-file - compresses large-file using gzip. gunzip large_file restores original file condition.
File Processing
- grep word file1 -
look through file1 for case sensitive match on word and print the line that contains word.
- grep -i word file1 - look through file1 for case insensitive match on word and print the line that contains word.
- grep -v word file1-
look through file1 for case sensitive match on word and print the line that do not contain
word.
- grep -l word * - look through all the files in the current directory and print
the names of those files which contain word.
- wc file1 - count lines, words, and characters in file1.
- wc -l file1 - count lines in file1.
- wc -l /usr/dict/words - count the number of lines (words ) in /usr/dict/words
- spell file1 - list spelling errors in file1
- sort file1 - sorts the contents of file1. See man sort for details.
File System
- pwd - print the current working directory
- cd dir1 - change directory to dir1. cd with no argument changes back to the user's home
directory.
- mkdir myfiles - create a new directory named myfiles.
- rmdir myfiles - deletes a directory named myfiles (must be empty).
- rm file1 - deletes file1
- touch file1 - creates and empty file called file1
- chmod - change protection of files. chmod o-r file1 makes file1 unreadable
to people outside of the owner's group. See man chmod for more details.
- chown - change ownership of files. See man chown for more details.
- find . -name file1.pl -print - searches down through all your directories
to find
files named file1.pl Prints their path names when it finds them.
See man find for more details.
- quota -v - displays the quota you have available. Note: you will only have quota on your own partition.
- du -k - list your disk usage in kilobytes.
System and Process Commands
- jobs - show any background
jobs.
- fg %1 - bring job 1 to the foreground.
- kill %1 - kill background job number 1.
- passwd - change your password.
- ps - list all your running processes.
- ps -ef - list all running processes on the system.
- kill 12345 - kills process 12345. Note: you can only kill processes you own.
- groups - list the unix group you are a member of.
- groups username - list the unix groups username is a member of.
- telnet hostname - connects you to a remote system called hostname.
- ssh hostname - connects you to a remote system called hostname using secure shell.
Control Characters
- ctrl c - kill job.
- ctrl d - end of file.
- ctrl s - stop output.
- ctrl q - continue output.
- ctrl u - erase to beginning of line.
- ctrl z - suspend current job.
Piping and Redirection
- tail -20 file1 > file2 -
take the last 20 lines from file1 and dump them into file 2. Contents of
file2 will be overritten.
- tail -20 file1 >> file2 - take the last 20 lines from file1 and append them to file 2.
- ps -ef | grep bash - list all the users running bash proceses.
- ps -ef | grep bash| sort - list all the users running bash proceses and sort on the first column (username).
- ps -ef | grep root | wc -l - count the number of processes being run by root.
- grep cie /usr/share/dict/words | wc -l - how many words in /usr/share/dict/words have i before
e after c?