Commands in UNIX are also commonly referred to as "utilities". Commands
are entered into the system through a command-line terminal. Although there are literally
hundreds of utilities, there is only a handful that you will need to be
familiar with to work in the Geospatial Science Teaching Laboratory. Some of the most
commonly used utilities are described below: (Note: UNIX commands are always lowercase.)
cd <target directory> : Change Directory. Use cd to move to different directories on the network, similar to DOS command cd. When using cd, you can either give complete pathnames to the directory you wish to move to or use some of the following options:
cd .. moves you "up" one directory. For example, if you were in the directory /home/gis77/homework and issued the cd .. command you would now be in the directory /home/gis77
cd ~ (or cd by itself) will move you to your home directory. So if you are user gis77 and are in the directory /home/gis67/homework/feb/data and issued the command cd ~ you would now be in the directory /home/gis77 (your home directory). Likewise, you can follow the "~" with the name of another user to go to his/her home directory, e.g. a command of cd ~gis24 would put you in the gis24 home directory /home/gis24/
chmod <options> <file> : Change Mode. Changes the permissions status of a file or directory. There are three levels of protection, and each can be set separately. The levels correspond to a hierarchy of control with the highest being at the entire system level, the next being a group (students are in the student group), and finally the user level (such as user bbanner). To determine the current permissions for a file or directory, perform a ls -l command. The permissions will be listed at the far left similar to this: -rw-r--r--. The list uses the first character for a directory, the next three for the user, the next three for the group, and the last three for others. In other words, a listing of -rw-rw-r-- indicates that a user and his group have read and write privileges, whereas others can only read the file. To change permissions, use chmod followed by the access level indicator, then add or remove the permissions by type. If changing permissions of an entire directory and subdirectories, use the -fR switch to force a recursive change through all files and subdirectories.
Access Levels
u user
g group
o othersPermissions
r permission to read
w permission to write
x permission to executeChange Operators
+ add permission
- remove permission
= assign permission absolutely
Examples:
chmod o-r myfile.txt will remove read privileges from others for myfile.txt
chmod -fR g+x mydocs will add execute permissions for all files and subdirectories in the mydocs directory
cp <source> <destination> : Copy. Copies a specified file or files to a specified location (directory). You must give both the file (or files) to copy and the destination. Using the period "." will put the file in the specified directory and give the new file the same name. Using the period without a path will put the file in your current directory.
Examples:
cp /home/gisdata/hisfile.txt /home/mydata/myfile.txt copies the text file called hisfile.txt and renames it myfile.txt
cp ~paxton/recipes/shoeflypie . copies the file to your directory and keeps the same name
cp -r /home/fiction/public_html/images . copies the images directory to your directory and keeps the same name
cp -r /home/public_html/images /home/fiction/photos copies a directory to a new location with a new name
df . : Shows mount point, free blocks, and number of files for the disk of the current working directory.
df -k . : Shows disk space in kilobytes and percent capacity for the disk of the current directory. Use df -k (without the dot) to show the disk space of all mounted volumes.
du -sk <directory> : Shows number of kilobytes stored in that directory.
file <filename> : Reveals the file type of the specified filename.
ln -s <source> <destination> : Link. Creates a symbolic link from the source to destination. A symbolic link is a pointer file. This pointer associates a filename with a directory on a hard drive, similar to a Windows shortcut or a Mac alias.
Example:
ln -s /home/bbanner/temp temp creates a file at the current working directory which when incorporated in a command will path to /home/bbanner/temp. If the user is located in the directory with the link they can type cd temp and the current working directory will be changed to /home/bbanner/temp
lpr <filename> : Prints a file to the default printer.
Example:
lpr apples.txt will send the file apples.txt to the default printer
lpq : Shows print jobs and # in the printer queue.
lprm <job#> : Removes the print job # from the print queue.
ls : List. Use ls to see the contents of the current directory, or specify a pathname to another directory to see its contents. Similar to DOS command dir.
ls -a : List, All option. Lists the entire contents of the current directory, including "hidden" files. In UNIX, a hidden file is preceded by a period, e.g. /home/gis80/.hideme
ls -l : List, Long option. Use ls -l to see the contents of your current directory, file size in bytes, date of creation and permissions for all files and subdirectories. (The command ll is a shortcut to ls -l)
man <command> :
Manual.
Give this command along with the command you need more information on, and a
series of manual pages will appear that describe how to use the specified
utility.
Example:
man cd will describe the use of the cd utility
Hit return to scroll down my lines, spacebar to scroll by page through the entry
Type q to get out of the man page and back to your UNIX prompt
mkdir <dir name> : Make Directory. Makes a new directory, either in the current directory or in a path you specify.
Example:
mkdir project1 will make a directory named project1 within the current working directory
mv <file> <destination> : Move. Will move a file or directory to a new location. Since there is no rename utility in UNIX, use mv to rename files and directories.
Examples:
mv apples.txt oranges.txt will rename the file apples.txt to oranges.txt
mv images photos will rename the directory images to photos
mv tmcache.gif /home/rsclass/data/tm30cache.gif will move the tmcache.gif file to the data directory and rename it as tm30cache.gif
more <filename> : Will display the contents an ASCII text file on the screen.
Example:
more apples.txt will print on the screen the contents of file apples.txt
ps : Process Status. Shows process ID numbers (PID) for processes running in the current terminal window. Useful for dealing with frozen or halted processes.
ps -a : Show PID's for all processes running on the host.
pwd : Present
Working Directory. Use pwd to see the name of the current directory if it isn't already echoed at the prompt.
Most users will see a prompt similar to this: gis80@valinor:/home/gis80>_
But on some hosts, it might appear like this: valinor#_
In the case of the latter, pwd comes in handy.
rm <filename> :
Remove files. After you issue the
rm
command, you will be prompted as to whether you really want to delete the
specified file(s). With rm,
you must specify a file or group of files to remove. You can either give
a file name or use the wildcard
*. USE WITH CAUTION--THERE IS NO UN-DELETE IN UNIX!!!
Examples:
rm myfile.txt will remove only the file named myfile.txt
rm *.txt will remove all files that end with .txt
rm -r mydir removes the directory named mydir, but still prompts you to confirm deletion for each file within that directory(You can also delete files using CDE's file manager. Like Windows or MacOS, it will temporarily store deleted files in a "trash can" until you purge them permanently.)
I REPEAT: USE WITH CAUTION--THERE IS NO UN-DELETE IN UNIX!!!
ssh <hostname> : Secure Shell. Allows you to connect to another machine (host). Password authentication is required, and all activity is logged. Use ssh to access a frozen or stalled machine from another one. (Please see UNIX help pages for more information on fixing frozen programs and machines.)
top : Shows
the top 15 running processes, including the username that initiated it and the CPU load for each process. (Type q to exit top.)
zap <pid#> : Kills a stalled process. You must first use ps or top to learn the PID of a frozen or stalled process. (Please see UNIX help pages for more information on killing unwanted processes.)