Setting up a Friendly Environment
At the command line, type
{ecelinux:1} tcsh {ecelinux:1}
or simply visit this site to change your shell to your shell to tcsh by selecting it in the drop down menu.
Shell Commands
Having typed tcsh, you have issued a command to the shell. Each command passed to the shell via the terminal program has the form
{ecelinux:1} command_name -option1 -option2 -... argument1 argument2 ...
The preamble {ecelinux:1} is called a prompt. This lets the user know that the terminal is ready to process another command, that is, it prompts the user for another command. Associated with each prompt, in this case, is a unique integer.
The command name (command_name) is either the name of an executable file (e.g., date) or a built-in command (e.g., exit). In some cases, the executable file is located in the working directory, though in other cases, it is located elsewhere, for example, the directory /usr/local/bin. In Unix, bin stands for binary, or binary files.
Additional arguments are separated into two categories:
- options, and
- arguments.
Options are usually flags which determine the behaviour of the executable program while additional arguments are often file names or other arguments.
Comand Line Editing
Suppose you start typing a command. If you make a mistake, you can use the left and right arrows (← and →) to move around the command line. To access the previous command, you can use the up arrow (↑). You can also use the down arrow (↓) to move to a more recent command.
You can copy highlighted text in an Ssh terminal by using Ctrl-Insert. You can then paste that text at the cursor by using Shift-Insert. This allows you to cut-and-paste to and from other programs.
One short-cut you may wish to use if you are only cutting-and-pasting between the shell (e.g., highlighting a file name and pasting it onto the command line) is to simply highlight the text and then click the middle mouse button to paste the highlighted text at the cursor.
Some Unix Commands
We will now look at a number of commands which are useful in a Unix terminal.
date
Print the current date and time.
exit
This terminates the shell and disconnects the terminal from the system.
pwd
Like Windows Explorer, the shell stores the working directory in the variable (the name of which is PWD).
The command pwd, or print working directory, echos the variable PWD to the terminal. The value of this variable will change as you change the working directory.
Typing pwd after I log into the account ece250 on ecelinux, I get:
{ecelinux:1} pwd /home/ece250 {ecelinux:2}
The working directory is read as slash home slash ece250. Any time any files or directories are referenced in a command, the operating system will interpret the file relative to the working directory.
ls
Next, we will list the contents of the working directory:
{ecelinux:2} ls bin/ mailhome@ public_html@ tmp/ handin/ marking/ readme mail@ moss_results/ src/ {ecelinux:3}
The /home/ece250 directory contains one file (readme) and nine directories. Directories are designated by trailing the name with either a / or an @.
You may explicitly list the contents of one of the directories by passing the directory name as an argument to ls:
{ecelinux:3} ls public_html C++/ details/ index.html platforms/ LIF/ final/ intro/ projects/ TheBook/ homework/ labs/ requirements/ Unix/ howtos/ lectures/ slides/ classes/ ides/ marking/ tour/ css/ images/ midterm/ testing/ {ecelinux:4}
The path of, for example, the file index.html would be /home/ece250/public_html/index.html.
The first option we will look at is adding the -l option to ls. The this specifies long, indicating that additional information should be listed for each file:
{ecelinux:4} ls -l total 9 drwx------ 2 ece250 ece250 512 Nov 1 2005 bin/ drwxr-x--- 26 ece250 ece250-t 1024 Apr 26 16:00 handin/ lrwxrwxrwx 1 root other 26 May 7 2005 mail -> /var/mail/home/ece250/mail/ lrwxrwxrwx 1 root other 21 May 7 2005 mailhome -> /var/mail/home/ece250/ drwxr-x--- 8 ece250 ece250-t 512 Apr 12 15:47 marking/ drwx------ 3 ece250 ece250 512 Apr 15 22:34 moss_results/ lrwxrwxrwx 1 root other 23 May 8 2005 public_html -> /web/ece250/public_html/ -rwx------ 1 ece250 ece250 2804 Apr 12 16:52 readme* drwx------ 2 ece250 ece250 3072 Dec 3 2005 src/ drwx------ 2 ece250 ece250 512 Apr 25 13:21 tmp/ {ecelinux:5}
To determine what the figures in the columns indicates, please read further about the man command, however, it should be obvious that the third and subsequent columns represent the size (in bytes); the month, date, and time the file was last modified; and the name. At the end of three of the entries, you will note that the directories point (->) to other paths. This simply indicates that while it appears that there is a directory named, for example, public_html, it is linked to a different directory, in this case, the directory with the path /web/ece250/public_html/.
man
To get help on Unix commands, use the man command (from manual) together with the command in question as an argument.
{ecelinux:5} man ls Reformatting page. Please Wait... done User Commands ls(1) NAME ls - list contents of directory SYNOPSIS /usr/bin/ls [ -aAbcCdfFgilLmnopqrRstux1 ] [ file ... ] /usr/xpg4/bin/ls [ -aAbcCdfFgilLmnopqrRstux1 ] [ file ... ] DESCRIPTION For each file that is a directory, ls lists the contents of the directory; for each file that is an ordinary file, ls . . . .
mkdir
The first command we will use which modifies the directory structure is mkdir, or make directory. This is equivalent to, in Windows, selecting from the right-click menu New → Folder.
We will begin by creating a project directory called ece250. You should do this in your own account.
{ecelinux:6} mkdir ece250 {ecelinux:7} ls bin/ mail@ moss_results/ src/ ece250/ mailhome@ public_html@ tmp/ handin/ marking/ readme {ecelinux:8} mkdir ece250/p1 {ecelinux:9}
The second command makes a subdirectory in ece250 called p1 (for Project 1).
rmdir
The command rmdir removes the directory. A directory will only be removed if it does not contain any files or sub-directories, otherwise, it will issue an error:
{ecelinux:9} rmdir tmp rmdir: `tmp/': File exists {ecelinux:10}
The abbreviation tmp is often used for temporary directories in unix.
The Home Directory
Each unix account is associated with a default home directory. The default home directory for your account will look something like /home/dwharder where dwharder is replaced with your UW User ID. To print the home directory, type:
{ecelinux:10} echo $HOME /home/ece250 {ecelinux:11}
The echo command simply prints information to the screen while $HOME is a special variable recognized by the terminal.
Navigation: cd
In Windows, you moved between a directory and its sub-directories by double clicking on the appropriate diagram while you moved to the parent directory by clicking the Up icon. Alternatively, you could select a directory directly from the tree structure.
The command to do this in Unix is cd, from change directory. The term see dee is often used as a verb: "cd to your home directory".
cd (home)
If you enter cd without any arguments, the working directory will be changed to your home directory as specified by the variable HOME. An abbreviation for the home directory is ~.
cd .. (parent)
Because each directory has a unique parent directory, the parent directory within any directory may be referred to by the special name ... Thus, cd .. means change to the parent directory.
cd directory_name
If directory_name is a sub-directory of the working directory, then cd directory_name will change the working directory to the specified directory.
cd path
If you specify a full path, that will take you to that directory.
The following three commands are all the same:
{ecelinux:11} cd {ecelinux:12} cd ~ {ecelinux:13} cd $HOME {ecelinux:14} cd /home/ece250
To get to the ece250 directory, you may use:
{ecelinux:15} cd ece250 {ecelinux:16} ls p1 {ecelinux:17} ls p1 {ecelinux:18} ls .. bin/ mail@ moss_results/ src/ ece250/ mailhome@ public_html@ tmp/ handin/ marking/ readme {ecelinux:19}
Command 17 indicates that the directory p1 is empty.
Summary
In this topic, we have covered some of the basics of creating and navigating the directories of the Unix file system using the shell. In the next topic, we will look at creating text files using the pico editor.
Copyright ©2005-2008 by Douglas Wilhelm Harder. All rights reserved.