UNIX File Management
Shell
When you login you run what is known as a shell. This is the basic program that allows you to interface with the computer. There are several different shells, and each one varies slightly.
It is recommended that you use tcsh since it has many useful features. All new accounts are now created with tcsh as the default. However, some older accounts may still have csh. If your prompt is >, then you are running tcsh. To change shells type chsh and enter /sh/tcsh when prompted for the shell name.
Path
Absolute path refers to the complete location of a file, or the path the system uses to find it. For instance, given that a username hunter, located on /usr2, has a file called pizza in a sub-directory called FOOD, the absolute path is /usr2/hunter/FOOD/pizza. This path is used by the system to find the file, in much the same way that you use a map to find a destination.
Relative path is the path to a file from the directory you are currently located in. For example, if you are in /usr2, hunter/FOOD/pizza is the relative path from the above example.
You don't know what drive someone is on? No problem, there's a shortcut. The ~ character can be used before a username to tell the system to look for the drive on its own. In this way /usr2/hunter can be abbreviated as ~hunter, and your own home directory may be abbreviated as ~/.
Understanding how paths work is important as they are used in conjunction with many commands. Using the above example, at any time you can type cd ~hunter to change to that directory, or more ~hunter/FOOD/pizza to read that file. cd is the change directory command, and more is a program used to view text files one screen at a time. Use cd path to change to a new directory, and cd alone at any time returns you to your home directory. This doesn't mean that you can enter any directory, or read any file, just those that have the permissions set to allow it.
Directories
Your home directory is simply the top directory in your account. It is the directory you default to when you login. A sub-directory is simply a directory within another directory. Continuing the example, FOOD is a subdir of ~hunter.
If you want to create a new directory the command is mkdir.
There are two ways to create a subdir in one of your directories. The first is to cd to the directory in which you wish to create the subdir and enter mkdir directory -name. This will create the subdir with the name you supply.
The other way is to use mkdir /path/directory-name from any directory. This will create the new directory at the end of the path specified. If you were to enter mkdir ~/Eris you would create a new dir called Eris under your home directory.
To remove a directory the command is rmdir, used in the same way as mkdir. However, the directory must be emptied of files first for this to work.
Files
These are the basic dealt with in any computer system.
Files can be stored text, a program, a digital picture, basically anything, but all are handled in the same way. In fact, under Unix, a directory is simply a special file. To move a file you use mv path/file path/newfile. For example, mv ~/stuff ~/subdir/oldstuff will move the file stuff from the home directory into a file named oldstuff in the directory subdir. If you leave the last filename off the file will be moved to the new directory, but retain its original name.
Note: Be careful when using mv, as it will overwrite any files with the same name that are in the destination directory!
To make a copy of a file use the command cp in the same way as mv. This will create a new copy of the file in the specified location, while leaving the original file in place.
Remove files with the rm command, as in rm filename. When rm prompts you with rm: remove filename?, simply press y and Return.
Note: This prompting is not standard, so don't expect this to be the same at all sites. At WPI all new accounts are created with rm aliased to rm -i which triggers this prompting.
You can list your files with the ls command. On its own, ls will list your normal named files and directories. There are also dot-files with are normally used by the system to store information used by applications. To see all the files use ls - a. For information such as file size and date of last change use ls -l filename. These flags can be combined, as in ls -al, which will provide complete information for all the files in the directory.
This may be more than a screen in length. To counter this problem you can pipe the output through the more program. This is done with the | symbol, as in ls -al | more.
For information on changing the file permissions under UNIX, please see the Help Desk's chmod command page.
Wildcards
If you've ever played card games, you probably know the principle behind a wildcard. It is something that can assume different values, other than what it normally would be. There are several wildcards that makes life easier on the system.
The most commonly used is the asterisk, *. When an asterisk is used in a command, the system looks for all possible completions from 0 characters up. Examples: rm n* will remove all files with n for a first letter, while rm q*m will remove all files that start with q and end with m.
The question mark, ?, is also a wildcard. It is used for single character replacement. Whereas the asterisk replaces a string, ? will replace one, and only one, character. If you had files hw1, hw2, and hw3, you could delete them using rm hw?.
The bracket pair, [ and ], can also be used for wildcards.
These are used for pattern matching. Using the previous example, you could also remove the files with rm hw[1-3]. If you wanted to keep hw2, you could use rm hw[1,3]. Or you could use the negation available.
Instead of file[pattern] you use file[^pattern]. The caret, ^, means to perform the operation on all the matching files except those named by the user. The ^ must be the first character inside of the brackets In this example you would use rm hw[^2].
Flags
This is the term used to refer to options available with commands, such as -r, -l, etc. All the dash-* options are called flags.
Odd files
At some point you may accidentally create a filename with a special character in it, i.e. home*ork. If you tried normal commands to move, or remove the file, they wouldn't work. There are ways around this; enclose the filename in single or double quotes, ie rm 'home*ork' or rm "home*ork", or use the backslash, \, as in rm home\*ork. A backslash will de-specialize the following character allowing commands to function normally.
A special case is creating a file with a hyphen, - as the first character. This will cause commands, such as rm or mv, to view the filename as a flag. To solve this problem, separate the command and filename with an isolated hyphen, as in rm - -kallisti.
Manual pages
If you want to learn more about a command there are manual pages, or man pages, online. Simply enter man command, such as man rm, to display the online manual for that command. Most of the common commands will have a manual page. It is a good idea to do this once you understand the basic command, as most commands have several flags.
Man can also be used to research new commands via the -k flag. Typing man -k keyword will return all commands with keyword in their description. Simply use keywords you feel are related to the topic you're interested in.
Maintained by itweb.Last modified: May 18, 2004, 09:11 EDT
