You typically log into Copland from a PC via SSH (secure shell) or Exceed. After logging in, you see a UNIX prompt. Your current directory is your home directory
By UNIX convention, stdin (standard input) is your keyboard, and stdout (standard output) is your display. stderr (standard error) also defaults to the display.
Unix makes extensive use of hierarchical inverted-tree directory structures. The path to any directory or file is defined from the root directory (/). Subsequent / characters in a path separate directory and subdirectory names. For example, /home/grumpy/myfiles/letters/whiny_letter.draft specifies the absolute path from the root directory to a file named "whiny_letter.draft." Or, supposing you are in grumpy's home directory (/home/grumpy), you could specify the relative path from there: myfiles/letters/whiny_letter.draft (no leading / character).
UNIX file names can be pretty much any practical length, but should not contain spaces or other reserved characters. The UNIX shell interprets the space character as a separator between commands or parameters. It is good practice to use only lower-case characters in UNIX filenames. The . (period) character has no special meaning in a filename unless it is the first character in the name, which causes it to be hidden from routine directory listings.
The pwd command prints the path of your current directory to stdout
The ls command lists the names of files and subdirectories in your current directory. ls -l prints a longer listing including file and subdirectory permissions, ownerships, file sizes for each entry in the current directory. ls -a lists all files, including "hidden" files whose names begin with a period such as .cshrc and .login (these are two files in your home directory which set default paths, environment variables, command aliases, etc.). You can combine flags associated with any command: e.g., ls -al prints a long listing of all files. You can list the contents of any other directory if you specify the correct path to it: ls -l /home/grumpy/otherfiles
You can use wildcard characters to reference files and directories. The * character represents any string of zero or more characters. The ? character represents any one character. So you could list all files and subdirectories whose names begin with the string dat using the command ls dat* or all files with 4-character names beginning with d using the command ls d???
You can specify square-bracketed ranges of characters to match to: ls [a-f]* lists all files with names beginning with the characters a through f. The command ls *[!a-f] lists all files with names which do not end with the characters a through f.
The leftmost character in each line of a long listing (ls -l) tells you whether the directory entry is a file (-), subdirectory (d) link (l) or whatever. The next nine characters indicate the presence or absence of read (r), write (w) and execute (x) permissions for three classes of user: owner, other group members and all other users. An absent permission is marked with a hyphen (-).
You can modify permissions on files you own with the chmod
command. Here's the quickest way: a read permission is represented by a
4; a write permission by a 2; an execute permission by a 1. Each
combination
of permissions sums to a unique number between 0 (no permissions set)
and
7 (all 3 permissions set) for each class of user. So you can set all
nine
permissions for your file myfile, for example, with the
command
chmod
754 myfile
This would set read, write and execute permissions for you, read and
execute permissions for other group members, and read-only permission
for
all other users, so the first 10 characters in the long listing are
changed
to -rwxr-xr--. Obviously you want to be careful about giving
write
permissions to other users. If this method of changing
permissions
doesn't make sense to you, use the man command to read
the
on-line manual entry for the chmod command, which explains
other
techniques for changing permissions: man chmod
Every UNIX command has a detailed man entry explaining its
syntax,
options and usage; just type man and
the name of the command you need help with.
The command cd /new/directory/path changes your current directory to the absolute path /new/directory/path defined from the root directory /.
Typing cd without a path returns you to your home directory. You can reference your home directory as ~ and any other user's home directory as ~username. When using relative paths, you can reference the parent of your current directory as .. (2 dots), and the current directory itself as . (1 dot). cd ~username/data switches you to the data subdirectory within username's home directory (assuming username has given you read permissions). cd ../../otherdir/junk takes you two levels up the directory tree from your current directory, then to otherdir and its subdirectory junk.
The rm command removes (erases) a file. UNIX does not have easy file recovery capabilities like DOS, so be careful, particularly when using wildcards to remove multiple files.
The cp command copies a file. The command cp myfile /home/grumpy/myotherdir/newfile copies myfile from the current directory as newfile in the (existing) directory myotherdir (assuming there isn't a subdirectory named newfile). The command cp myfile /home/grumpy/myotherdir copies myfile to the directory myotherdir.
The mv command moves (renames) a file in pretty much the same way. The command mv myfile newfile renames myfile in the current directory (assuming there isn't a subdirectory named newfile). The command mv myfile /home/grumpy/myotherdir moves myfile from the current directory to the (existing) subdirectory myotherdir.
The commands mkdir and rmdir create and remove directories. rmdir won't let you remove a directory containing files, but you can remove a directory junkdir and all the files in it with the recursive remove command rm -r junkdir.
You can print the contents of any file to stdout in several ways. The command cat myfile prints the entire contents of a myfile. If it's a long file, it will go scrolling by faster than you can read. The command more myfile works like cat, but prints the file one screenful at a time so you can read it all. The Enter key moves you through the file one line at a time; the Spacebar key moves you one screenful at a time. The command head -12 myfile prints just the first 12 lines of myfile. The command tail -16 myfile prints just the last 16 lines of myfile.
Unix lets you "pipe" output from one command or process as input to another command or process. The pipe character is | (vertical bar) . For example, you can pipe the output stream from the cat command to the more command: cat myfile | more
A less trivial example is scanning myfile for lines with a particular character string charstring using the grep ("global regular expression print") utility. The command cat myfile | grep charstring will print only the lines from myfile containing the string charstring. If charstring contains spaces or other special characters, put it in quotes.
Unix also lets you "redirect" output with the > character or input with the < character. For example, you could redirect the output of cat to a file rather than to stdout: the command cat myfile > newfile creates a new copy of myfile. Most users will have a "noclobberr" option set in their .cshrc file, which prevents a redirection from overwriting an existing version of newfile. You can override this with cat myfile >! newfile. Or you can append the contents of myfile to the stuff already in newfile with the command cat myfile >> newfile.
The command cat < myfile >> newfile does the same thing, using the input redirect as well.
cat can be used concatenate multiple files or parts of files into one (hence its name). For example, the command cat file1 file2 file3 | grep "string" > newfile extracts all lines containing string from the three input files and catenates them into newfile.
The ps command lists running processes. The command ps -au username lists all running processes owned by username. You may occasionally have runaway processes tying up the CPU. You identify process ID's with ps, and then can kill unwanted processes with the kill command, e.g., kill -9 12345 kills (the -9 flag means forcefully) the process with PID 12345.
By default, commands entered at the shell prompt run in "foreground," and tie up the shell until completed. But you can run any job in "background" and free your shell for other simultaneous processes. Appending the & character at the end of a command starts it as a background process and returns you to the shell prompt immediately. You can suspend an already-running foreground job with ctrl-Z and then restart it in background with the bg command, or in foreground with the fg command. The jobs command lists the status of all currently running jobs.
On an X-terminal, you can also open multiple shell windows to support simultaneous processes.
The tar command lets you archive multiple files, or even whole directory trees, into a single file for backup or moving to another computer or disk system. For example, the command tar cvf myarchive.tar * will archive everything in the current directory, including all sub-directories and their contents, into a single file called "myarchive.tar." To un-tar this file again, use the command tar xvf myarchive.tar, which will unpack everything into the current directory. .
The Gnu zip/unzip utilities gzip and gunzip
can be used to compress and uncompress large files such as tar files,
so
you can FTP them more quickly, or perhaps squeeze them onto
diskettes.
The command gzip myarchive.tar replaces "myarchive.tar" with
the
compressed version "myarchive.tar.gz." gunzip
myarchive.tar.gz
uncompresses it to "myarchive.tar" again.