Some Unix/Linux commands for the real beginner

Basic commands

There are a number of Unix commands which the user should become familiar with from the outset:

passwd
This command allows you to change your login password. You are prompted to enter your current password, and then prompted (twice) to enter your new password. On Linux systems (like Magrathea) passwords should exceed 6 characters in length, and contain at least one non-alphanumeric character (such as #, %, *, ^, [, or @ etc.)

chmod
This command allows you to change the permissions on your files.
Example use <$>chmod 755 filename
This will give -rwxr-xr-x permisions to a file named filename
cd
This command, as in DOS, changes directories. You can use .. to represent the directory above the current directory. You can use ~ to represent your root directory (also called your home or top directory). Example: cd maindir to move into the maindir directory, cd .. to move to the directory above, or cd ~ to move to your root directory.

pwd
This command tells you which directory you are currently working in. Your home directory is represented by the tilde ~ symbol. To go to your home directory from anywhere, type cd ~, however typing cd without the ~ also works on Linux systems.

ls
This gives you a listing of all files in a directory. You can't tell which are files and which are directories.

ls -F
This shows which files are text files (they have no special symbols at the end), which are directories (they end in a / character), and which are executables (they end in a * character). These symbols are NOT part of the file name.

ls -l
"Long" format. Gives more details about files and directories in the current directory.

ls -a
Lists "hidden" files in current directory (those starting with a . character).

ls -la
Options may usually be combined. This particular combination would list both hidden and unhidden files in the long format

mv
The "move" command is how you rename files. Example: mv oldfile.txt newfile.txt

cp
Allows you to copy one or more files. Example: cp myfile.c backup.c

rm
Deletes a file. BE CAREFUL!! There's no "undelete" command. Example: rm janfiles.*

cat
Sends the contents of a file to stdout (usually the display screen). The name comes from "concatenate." Example: cat index.html

more
Like cat but displays a file one page at a time. Example: more long_file.txt

wc
Counts the number of lines, words, and characters in a file. Example: wc essay.rtf

tail -n
Displays the last n lines of a file. Example: tail -5 myfile

head -n
Displays the first n lines of a file. Example: head -5 myfile

mkdir
Creates a new directory, located below the present directory. (Use pwd first to check where you are!) Example: mkdir new_dir

rmdir
Deletes a directory. Example: rmdir old_dir

man
The most important Unix command! It displays the manual pages for a chosen Unix command. Press [Enter] to advance one line, [Spacebar] to advance one page, and the [Q] key to quit and return to the Unix prompt. Example: man ls

man -k
Displays all Unix commands related to a given keyword. Example: man -k date will list all Unix commands whose man pages contain a reference to the word date.

date
Shows the current time and date.

logout
Terminates the current login session, (and returns you to your telnet client, if that is how you established the session originally).

The commands above are those you will use 90% of the time. However you should consult one of the Unix tutorials below if you need details of the use of a command not listed above.


I/O Redirection

<
Input redirection. This allows you to take input from a file rather than stdin. Example: tr a z <text

>
Output redirection. This allows you to send output to a file rather than stdout. Example: ls -l >listing

|
Pipe. This allows you to connect stdout from one command with stdin of another. Example: ls -la | more


Editors

To create files on a Unix system you usually use a text editor.

A number of editors are available on Magrathea, including vi and emacs, both referred to in the bash textbook. A full description of each can be obtained by typing man vi or man emacs. These are both full function editors, and as such are not easily learnt without regular use and practice in using the various commands.

The pico editor (which is the editor included with the pine email program) on the other hand is extremely simple to learn and use, and for all of the text editing activities you will encounter in this subject, it is perfectly adequate. Type man pico for an overview, and then use the on-line help in the program itself, or use one of the pico tutorials below.

Alternatively, you can create files locally using a text editor like Windows Notepad, or Wordpad. You can even use your favorite wordprocessor such as Word6 or Word97, (but if so make sure you save the files as ascii text files NOT Word files). You can then use ftp to transfer the files to Magrathea.


Unix tutorials

There are a number of excellent Unix tutorials on the Web, including:

Pico tutorials

The Web also has some quick introductions to the Pico editor: