UNIX Commands





Note:  This document is intended for use by my professional writing students and is not an official document of the NKU Information Technology department.

The following  tables will help you to work more easily in a UNIX environment by showing you UNIX commands that will permit you to accomplish specific tasks. Below the following conversion tables are explanations and examples of how to use the UNIX commands.
 
Directory commands
The UNIX Command
Show current path/directory pwd
Create/make a directory mkdir
Delete/remove a directory rmdir
List contents of directory ls
Change directory cd
File commands
The UNIX Command
Find a file find
Move or rename mv
Copy cp
Delete/remove rm
List contents more
Print lp
Other commands
The UNIX Command 
Help man
Show users  who
Show processes  ps
Show Quota  quota -v
Show printer  lpstat -a
Kill a process  kill
Set password passwd
Log Off  exit 


Unix Commands

pwd

This command shows you your current path in Unix (also known as what directory you are currently in). All paths at NKU start with /home/. Your home directory is at /home/username. That is the path to your directory. If you are in a subdirectory called documents, then your path when you are in that directory is /home/username/documents. 

mkdir

This command allows you to make a subdirectory. The command is typed

mkdir dirname

Example: to create a subdirectory named documents, you would type:

mkdir documents 

rmdir

This command allows you to remove a directory. If you type rmdir dirname by itself, the directory named must be an empty directory. If it is not empty, you must remove the files from that directory before using this command. You may also use the command rm -rf dirname to remove all files in the directory and then the directory itself. It is not a good idea to use the -rf option unless you are absolutely sure you do not want any of the files that are in the directory! Remember, UNIX never asks the question, "Are you sure?"

Example: rmdir documents 

ls

This command will list the files in your current directory. If you type ls -A, it will list all files, including ones that start with . (a period), which you can think of as "hidden files". An example would be your .login file, which is equivalent to your login.com file under VMS.

if you want to list files of a certain type or name, you can use the wildcard, * (an asterisk). for example, ls *.htm would list files that have a filetype of .htm. you can also use the find command to find files. Note that in unix, filenames do not require a filetype. Also, there are no version numbers in Unix files. 

cd

The cd command is the change directory command. It allows you to change your current directory, or path. To move into a subdirectory, you type:

cd dirname

For example: cd documents

To move up one directory you type cd ... To move from anywhere back to your home directory, type cd.

You can either use absolute paths with the cd command or relative paths.

Examples:

User jldoe is in a subdirectory of his home directory called documents and wants to move to another subdirectory of his home directory called programs.

His current path is: /home/jldoe/documents

He can use the cd command with the following absolute path:

cd /home/jldoe/programs

OR, he can use the following relative path:

cd ../programs

This command works because he is already at the path /home/jldoe/documents. Therefore, he only needs to move up one level (which is why he uses the ..) and down one level into programs (which is why he uses /programs). 

find

This command searches downward through subdirectories for files that match the specifications that you list. There are many options on the find command, but used simply, you can find files that match a name or part of a name.

Example: find *html will find any filenames that end in html.
Example: find proj* will find any filenames that start with "proj" 

mv

The mv command allows you to move or rename a file. For example, the following command renames a file from one.txt to two.txt:
mv one.txt two.txt

You can also use the mv command to move a file from one directory to another. For example, the following command moves a file called one.txt from the current directory into a subdirectory called documents:

mv one.txt documents

You can also give the file a new name when you move it. The following command moves a file called one.txt into a subdirectory named documents and gives it the name two.txt:

mv one.txt documents/two.txt

NOTE: You should take care when using the mv command, since it does OVERWRITE any file with the same name. If you do not feel comfortable using the mv command, you should use the copy command, which is cp. It makes a copy of a file and does not change the name of the file. 

cp

The cp command allows you to make a copy of a file. For example, to make a copy of a file called one.txt and call the copy two.txt the command is:

cp one.txt two.txt

You may also specify another directory for the copy. For example, to make a copy of the file one.txt and place it in the subdirectory called documents, you would type:

cp one.txt documents

You can also specify a new name for the copy, as in this example:

cp one.txt documents/two.txt 

rm

This command allows you to remove (or delete) a file. In UNIX you do not have version numbers, so you simply specify the filename. For example, to remove the file called one.txt you would type:

rm one.txt

You may also specify a path to the filename as in this example, which removes the file called two.txt from the documents subdirectory:

rm documents/two.txt 

more

This command lists the contents of the file to the screen, one screen full at a time. You press the spacebar to see the next screen of information. For example, to see what is in the file called one.txt you would type:

more one.txt 

man

The man command is used to get help, or view the manual pages for a particular topic or command. For example, to get help on the rmdir command you would type:

man rmdir

You can also specify a keyword to search for help on. For example, if you type the following command you will get a list of topics that have to do with printing:

man -k print 

who

The who command is used to show who is currently logged onto the same unix computer you are using. Example:

who 

ps

The ps command shows you the processes you currently have running. If you have not exited some processes correctly, you might have processes running that you are not aware of. A process that has not been terminated correctly can be killed with the kill command. You should note the Process ID (PID) numbers that are assigned to your username when you type ps, if you suspect that you might have orphaned processes running. 

lpstat -a

This command will show you a list of the printers that are currently accepting unix print jobs. You might want to use the pipe command and pipe this to the more command so you can see one screen full of information at a time. The command would then be:

lpstat -a|more

Whenever you use the more command you should use the spacebar to see the next screen full of information. 

kill

The kill command allows you to stop a process that you own. To find out what processes you own, use the ps command. The command to kill a process is:

kill -9 PID

You must supply the PID number, as shown when you type the ps command. You must be careful to kill the right process and not your current process! If you kill your current process, then you will have to log back in. Killing a process is something that you should NOT have to do very often, just as you probably didn't do it very often (if ever) on the VMS system. 

passwd

The passwd command is used to change your unix password. When you type the command you will be prompted for your old password. This is the password you used to login to your account, and is initially set to the last 8 digits of the ISO number on your ID card. Once you type in your old password you will be prompted for a new password. You are encouraged to use a combination of letters, numbers, and even punctuation. You can mix capital letters and small letters; it does make a difference in unix. Once you type in your new password, you will be prompted to verify it by typing it in again. After you verify the password, it will be changed and that will be your password until you change it again.