Basic Unix Commands

There are several flavors of Unix: IRIX, Solaris, Linux, etc. For this class, your programs must compile and run on Linux. When you log onto GL, be sure that you connect to the host named gl.umbc.edu or linux.gl.umbc.edu. Connecting to these host names ensures that you are actually working on one of the three Linux servers, linux1.gl.umbc.edu, linux2.gl.umbc.edu, or linux3.gl.umbc.edu; which of the three Linux servers you are connected to depends on the current load for each machine.

Simple UNIX Commands

ls
Lists the files in the current directory

ls -l gives more information about files. -l stands for "long" output.

cp
Copies a file

cp sample.cpp example.cpp makes a copy of sample.cpp and names the new copy example.cpp.
The file sample.cpp is unchanged.

mv
Renames (“moves”) a file

mv average.cpp mean.cpp changes the name of the file from average.cpp to mean.cpp.
The file average.cpp no longer exists.

rm
Removes or deletes a file

rm olddata.dat deletes the file olddata.dat.

more
Displays the contents of a file on the screen one page at a time

more example.txt shows the contents of the file example.txt one screenful at a time.
You must press the spacebar to advance to the next page.
You may type q to quit or b to go back to the beginning of the file.

mkdir
Makes a new subdirectory in the current directory.

mkdir cmsc202 will create a new directory called cmsc202 in the current directory.

rmdir
Removes an empty subdirectory from the current directory

You must delete all of the files from a subdirectory before you are allowed to delete it with this command.

cd
Change the working directory

The command cd with no arguments will return you to your home directory.
cd followed by a subdirectory name found in the current directory, such as cd cmsc202,
will change from the current directory to the subdirectory called cmsc202, if that subdirectory exists.
cd .. changes to the directory one level up in the directory tree.

man
Gives a description of a UNIX command.

man cat will describe the cat command.
If you don't know the name of a command, but you do know what you want to do, use man -k.
For example, if you've forgotten the command for copy, type man -k copy and you wil be shown
a list of commands with the word "copy" in their description.
The man command uses the more command to present the information, so you must press the
spacebar to advance to the next page. You may type q to quit or b to go back to the beginning of the file.