Texas A&M Supercomputing Facility Texas A&M University Texas A&M Supercomputing Facility

Basic UNIX Commands

The basic form of any UNIX command is: command_name options argument(s)

File and Directory Handling Commands

Task Command
Lists your files ls
Lists your files in 'long format', which information such as the exact size of the file, who owns the file, who has the right to look at it, and when was it last modified. ls -l
List all the files, including the ones whose filenames begin in a dot, which you do not always want to see. ls -a
Move a file into a different directory, or rename the file. mv file1 file2
Copy a file cp file1 file2
Removes a file. Preferably use rm -i which will ask you for confirmation before deleting the file rm filename
Tells you how many lines, words, and characters there are in a file wc filename
Lets you change the read, write, and execute permissions on your files. chmod o+r filename will make the file readable for everyone, and chmod o-r filename will make it unreadable for others. chmod option file
Make a new directory mkdir dirname
Change to a directory. Use 'cd ..' if you wish to go to the parent of the current directory. cd dirname
Tells you which directory you are currently browsing. pwd

Viewing and Searching Files

Task Command
Display a file. cat filename
View a file one page at a time. Press
[space-bar]
if you want to see another page, type
[q]
if you want to quit reading, or
[b]
to go back a page.
less filename
View the first ten lines of a file. Use the -N option where N is a positive nonzero integer to specify the number of lines to display. head filename
View the last ten lines of a file. Use the -N option where N is a positive nonzero integer to specify the number of lines to display. tail filename
Searching for a keyword in a file using less less filename
/keyword
Search for all lines containing a keyword in a given file. Use the -i option to ignore upper/lower case distinctions. To search for a phrase, you must enclose the phrase with single quotes. grep keyword filename

About Yourself and Other People

Task Command
List your processes. Contains information such as the process ID, which you might need to kill a particular process which would be creating difficulties on your computer ps -u yourusername
Ends the process, whose process ID you typed in. kill processID
Show what your disk quota is, how much you're using, and incase you have exceeded your quota. quota -v
Shows the disk usage of the files and the directories in filename, du -sk will give a total of all files and directories on the disk. du filename
Lists your last logins. last yourusername
Gives you lots of information about that user, e.g. when they last read their mail and whether they're logged in. finger username
Tells you who's logged in, and what they're doing. w
Tells you who's logged on, and which computer they are logged on to. who

Miscellaneous Commands

Task Command
Shows the current date and time date
Shows a calendar of the current month. If you type in cal 10 1995 you will get the calendar for the month of October in the year 1995. cal
Shows you the manual page for the command man commandname
Refreshes or clears your screen. clear OR Ctrl + l
Stops running program or the command Ctrl + c
Suspends the currently running program or command Ctrl + z
Ends your login session exit OR logout

More information on almost any of the commands that have been mentioned above or you know of can be found in the online manual pages. Type man commandname at the shell prompt to look a the manual page for that particular command.

We have a UNIX tutorial. Another good tutorial can be found here: UNIX Tutorial for Beginners.