Unix Commands
Common Commands
The following is a very brief introduction to some useful Unix commands, including examples of how to use each command. For more extensive information about any of these commands, use the man command as described below.
cd
This command changes your current directory location.
cd ..
Changes your working directory to the parent of the directory that you are in when you issue this command. If you are at the root, you will remain there.
cd dirname
Changes your working directory to dirname. If you are not in dirname's parent directory, you must use dirname's full pathname.
chmod
This command changes the permission information associated with a file ("change mode"). Learn more about viewing and modifying permissions in Unix.
cp
This command copies a file, preserving the original and creating an identical copy. Because cp will overwite and destroy duplicate files, we recommend that you enter this command with the -i option, so that you'll be asked to confirm each file deletion.
cp file1 file2
Makes a copy of a file called file1 and names the copy file2. If there already is a file called file2, it will be replaced (overwritten).
cp -i file1 file2
Makes a copy of file1 and calls the copy file2. If there already is a file called file2, the system will ask you if you want to replace it before overwriting the file.Â
ls
This command will list the files stored in a directory.
ls -a
Lists the files in your working directory and shows your hidden "dot" files, as well, including your .login file.
ls -l
Lists the files in your working directory, giving lengthier information about them—including file protection and access privileges.
ls -lt
Same as ls -l, but orders the files by time modified.
man
This command displays additional information for a particular command. If you're unsure how to use a command or want to find out all its options, we suggest you use the man command to view the manual page.
Navigating:
- Press the spacebar to scroll to the next screenful of content.
- Tybe b to scroll back a screenful.
- Type q to quit the man facility.
man -k key
Obtains online information when you don't know the command name. Replace key with a keyword for the function you wish to perform.
rm
This command will remove (destroy) a file. We recommend that you enter this command with the -i option, so that you'll be asked to confirm each file deletion.
Note: Using rm will remove a file permanently, so be sure you really want to delete a file before you use rm.
rm filename
Deletes a file called filename.
rm -i filename
Deletes a file after confirmation. Type y to confirm or n to cancel.
rmdir
This command will remove a subdirectory. We recommend that you enter this command with the -i option, so that you'll be asked to confirm each file deletion.
rmdir dirname
Deletes a directory called dirname, if the directory is completely empty. If you're not in dirname's parent directory, you must use dirname's full pathname.
rm -rf dirname
Deletes a directory called dirname, and everything that is included in the directory. If you are not in dirname's parent directory, you must use dirname's full pathname.
ctrl + z
Suspends the execution of a process ("a job"). To have the process continue in the background (type bg immediately after). Type fg to resume the job or bring it to the foreground. To kill a suspended job, type jobs, then kill %n, where n is the number of the suspended job.
Use of this suspend character should be avoided until you have some familiarity with the system.