Beginner's Unix Commands


This page is (very slightly) adapted from www.cs.appstate.edu/~jtw/cs1440/ux_cmds1.html . For alternative beginner's guides, search google with "Beginner's Unix Commands".

There are many Unix commands that you might find useful, and there are many opinions about what commands you should make an effort to learn when you start. This page offers some suggestions for getting started with Unix.

Preliminaries

To begin with, you need to have some notions about the files, directories, and the Unix file system. You should know what your home directory is.

You need to know some things about passwords, about connecting to the system, about logging in and logging out.

Sources of Information

Most Unix systems have documentation on-line. You should note these items:

man word
If the on-line manual contains a "page" about word, this command will display it on your screen. For example, man man displays information about the man command.

apropos keyword
The apropos command locates commands by keyword lookup. When you type the command apropos word you will see a list of one-line descriptions of entries in the manual that contain word (in their one-line description). Follow up by using the man command to display one of the manual pages.

If you have lots of time and energy on your hands, you may want to learn more about Unix on your own. There are lots of books about using Unix; you might want to get one and study it. Books about Unix vary widely in quality. Before you buy a book about Unix, you might want to ask your instructor for recommendations.


Some commands to learn about

If you think you need more information, use the man command (see above), or talk to your instructor.
cd
The command
        cd directory_name 
changes your current (working) directory to the named directory. The command
        cd
(i.e., with no arguments) changes your current directory to be your home directory.
logout
Logs you out of the system.


ls
The command
        ls
(with no arguments) lists the names of files in your current directory.

Adding the options -CF, i.e., typing the command

        ls -CF
lists the names of the files in your current directory, listing them in multiple columns and appending a '*' to executable files and '/' to directories.

The command

        ls -l
shows a long-form listing which includes a character indicating whether the file is a directory ('d') or an ordinary file ('-'), 9 characters describing the file permissions, the name of the file's owner, the file's size in bytes, when the file was last modified, and the file's name.

Any of these forms can have wildcarded file names appended to them; that is, you can type things like:

        ls -l  file_name
        ls -l  wildcarded_file_name
        ls -CF file_name
        ls -CF wildcarded_file_name
These forms restrict the listing to files whose names match the wildcarding.

There are lots of other things ls can do; consult the manual page (type the command man ls) for details.

mkdir
The command
        mkdir directory_name
creates a directory with the given name.

passwd
The command passwd (with no arguments) can be used to change your password. You will be prompted to enter your old password and to enter a new one twice. Nothing will be echoed. If the command doesn't generate error messages, your password has been changed to the new one.

pwd
The command pwd (with no arguments) displays the name of your current directory on the screen. If what you see appears to be an error message, consult your instructor.

rm
The command
        rm file_name
removes (deletes, erases) the named file. The argument file_name can be replaced with a wildcarded file name description; the command will remove all files that match the wildcarded name. Use wildcards here with great caution; there is typically no way to recover a file that you have removed.

A variation on this command is the command

        rm -i file_name
The difference between this form and the first is that when the -i is there, the rm command will ask you whether to remove a file before it actually removes it. You can say no ('n').
Here are some other commands that you might find useful. They're here in alphabetical order. If you think you need more information, use the man command (see above), or talk to your instructor.
cat file_name
This command displays the named file on the screen. Actually that is a special case of what the cat command does. The command line:
        cat file_1 file_2 ... file_n
Reads the named files (file_1, file_2, ...) and combines them into a single file (concatenates them) which it sends to "standard output" -- the screen. The command line:
        cat file_1 file_2 ... file_n > destination_file
concatenates the named files and puts the result in the file named destination_file.

cp
The command
          cp file_1 file_2
copies the content of file_1 to a file named file_2. After the operation you have two independent copies of the same information.

The command

          cp file_1 file_2 ... directory_name
puts copies of the files, file_1, file_2, ..., in the directory directory_name. After the copy file_1 and directory_name/file_1 are independent copies of the same information. Likewise with file_2 and directory_name/file_2, and so on.

date
The date command (with no arguments) prints the current date and time. The output includes the day of the week too. For example, if I now type the command, I'll see this on my screen:
% date
Wed Sep 11 14:50:39 EDT 1996
% 

finger
The command
        finger
(with no arguments) displays some information about people who are currently logged on.

The command

        finger user_name
displays some information about the named user. The command
        finger real_name
where real_name is part of some user's real name, should show some information about that user.

The command

        finger user@internet_address
asks the system at internet_address for finger information on user. What happens depends on the system at internet_address; that system might send the information, might send some other message (perhaps a refusal), might "refuse the connection", or just might not respond (generating a long delay followed by a "connection timed out" message.

lpr printer file_name
Sends the file to the specified printer.

more file_name
less file_name
These two commands are "pagers". A "pager" is a program that displays a file on your screen a screen-full at a time. More is the older program, and there are many versions of it. Currrent versions are usually capable of scrolling both forward and backward in the file and of doing searches. Less is more only more-so ;-). There are lots of versions of less around. Typically, less has more features than more.

If you type a lower case 'h' to either of these programs, you should see a "help screen".

mv
The command
        mv file_1 file_2
moves file_1 to a file named file_2. After the operation file_1 is gone and file_2 contains the information. The effect is that file_1 is renamed as file_2.

The command

        mv file_1 file_2 ... directory_name
moves the files, file_1, file_2, ..., to the directory directory_name. After the move, files file_1, file_2, ... appear in the named directory rather than where they were.

rmdir
The command line
        rmdir directory_name
will remove the named directory if the directory is empty. If there are files in the named directory, the command will tell you that the directory isn't empty and will not remove the directory.

who
The who command, without an argument, lists the login name, terminal name, and login time for each current UNIX user. With two arguments, as in who am I who tells who you are logged in as.