Simple UNIX Command Guide

This guide is intended for someone who has never seen or worked with a UNIX terminal before. The UNIX environment can be very intimidating if you don't know what your doing on it.

It's important to keep in mind that you have tab-completion available to you. This is useful when you can't quite remember the command while you're starting out, and saves you a lot of time for lengthy commands, when you're already proficient without a graphical interface.

The very first command that you're going to want to learn is 'man'. The 'man' command looks to see if there is a manual page for another command, and shows it to you. The manual page for any command will give you a good description of what the command does, the proper syntax for using the command, along with any possible flags that the command will accept.

For Example:
When you type in 'man man', it retrieves the manual page for the 'man' command. After your done reading this guide, this is the most important command for you to remember, as it will allow you to learn how to use all the other commands that are built into your terminal. :q will exit out of the manual page entry.

The next thing you need to know how to do is to navigate around the filesystem. In case you are not familiar with the format, '~' refers to your home directory. By default, when you login to one of the department servers, you will be in your home directory.
PWD is a useful command to show you where your terminal is currently pointed at on the filesystem. If you were to type '
pwd
' into the console upon connecting to one of the login server, it will spit out /home/ugrad/username.

LS will list all of the files and folders in your current directory (Similar to dir, if you have used DOS in the past). Some clients, like putty, will color code things for you so that you know what kind of file you're looking at. ls has a lot of useful flags, depending on what you want to do with it.

For Example:
'ls -l' Will display your files in a "long" format, telling you useful information, like which user owns each file, how much space it is taking up, and what the permissions are on it.
'ls -a' Will display *all* of your files (Including hidden files that you didn't even know were there!)
'ls -la' Combines the two flags, and will display the "long" version of *all* of your files.

CD is another very important command that you should become familiar with, it stands for change directory. If you are in your home directory, you should have a 'www' directory already (If you don't, type 'mkdir www'). To change to the www directory, you type 'cd www'. If you want to return back to your home directory, type 'cd ..' to go back one level on the file system tree. cd will also take the full path of a directory, in case your not in a parent directory of where you want to go. (IE: cd /home/ugrad/username)

Pipes


Lets say you type 'ls -la' and there is a lot more information there than you were looking for, there are a couple useful commands that you can pipe(|) onto the end of the ls command in order to optimize it for your needs. 'grep' will search through the results of your first command and output only the things that contain the phrase you specify. '

For example:
'ls -la |grep www' Will output any directory or file with the string 'www' inside the name.
'ls -la |less' Will let you easily scroll through all of the returned entries, making it much easier to read.

Those commands, in my opinion, are the most vital to be efficient on a UNIX terminal. Below is a list of a lot of other useful commands that didn't quite make the list, in no particular order.

mkdir - Creates a new directory with the specified name. Syntax is 'mkdir directoryname'

passwd - Change the password for a user. By default, it will change the password for the user you run the command as. As root, you can specify the user that you want to change the password for. It will prompt you to type your current password, then the new password twice.

chmod - Change the file permissions for a file. Syntax is 'chmod xxx filename.ext', where xxx is the octal value of the permissions that you want to give the file.

chown - Change the owner of a file. Syntax is 'chown username:usergroup filename'. The default usergroup for students is ugrad.

hostname - Prints out the full hostname of the machiene that you are currently logged into.

whoami - Prints out what user you are currently logged in as.

date - Shows the current server time and date.

uptime - Shows how long the machiene has been running for.

du -h - Shows the disk usage of the current directory in human-readable format, Gives the size of every file, recursively, and a total directory size.

cat - Prints out a single text file to the screen. Syntax is 'cat filename.ext'. If the text file is large, you can pipe it through to 'less' to view one page at a time. (cat filename.ext |less)

cp - Copies a single file. If you want to copy a directory, you can give -R to copy a directory recursively. Syntax is 'cp filename.ext /path/to/new/filename.ext' or 'cp -R directoryname /path/to/new/directory'

screen - A very useful tool that allows you to continue running something after you are no longer logged in. Type 'screen' to start a screen session. Ctrl-A + D to detach a screen, 'screen -r' to resume a screen session. By default when you close your terminal window that is running screen, the screen session is automatically detached.

rm - Removes a file, you can give the -R flag to remove a directory recursively. Syntax is 'rm filename' or 'rm -R directoryname'

./ - Run an executable. Syntax is './filename'

text-editors - There are a lot of command-line text editors available to use. 'Pico' and 'Nano' are very straight forward, and good for a beginner. More advanced users will tend to prefer 'vi', 'vim' or 'emacs', due to their high functionality. To open any of these editors, simply type the name into your terminal window.