The ">" symbol redirects standard output to a file.
- 1. Create a file by typing cat > myfile and
pressing Return. Then type in the following text and press
Ctrl-D. The ">" symbol informs your shell to redirect
output of the cat command to a file, "myfile." The cat command reads
from the standard input in this example.
cj> cat > myfile
Someone:916 Hawk Street::Austin:Texas:78749
Anyone:Eagle Avenue:Suite 100:Dallas:Texas:75218
- 2. Now type cat myfile and press
Return to display the contents of the file.
- 3. Create a directory by typing mkdir temp and
pressing Return. Then type ls and press
Return. Notice that temp is now listed in your directory.
cj> mkdir temp
- 4. Type ls -l and press Return to
produce a long listing of your directory. Notice the temp line starts
with a "d" and the myfile line starts with a "-". The "d" signifies a
directory. The "-" siginifies a normal file.
- 5. Now set up a directory structure in your HOME
directory for later use. Type mkdir letters bin tmp and press
Return. This creates the "letters," "bin," and "tmp" subdirectories
in your HOME directory.
Using an editor
There are three popular editors on UNIX that can be used to create files.
They are ed, ex, and vi; please refer to the module that
describes each of these editors (Module 39, Module 43, and Module 151).
COPYING AND COMBINING FILES
UNIX provides multiple commands to copy files. The following commands are
the most commonly used.
- 1. Copy myfile to phone.db by typing cp myfile
phone.db and pressing Return. The cp command does not
display information if it was successful.
- 2. Combine two files using the cat command by typing
cat myfile phone.db > myph and pressing Return. A new
file called "myph" is created.
- 3. Display the contents of the myph file by typing
cat myph and pressing Return.
RENAMING AND MOVING FILES AND
The following command renames files or moves them to another directory.
- 1. Rename the phone.db file to phone by typing mv
phone.db phone and pressing Return. Again no response if
mv was successful.
- 2. Type mv temp db and press Return
to rename the temp directory to "db."
- 3. Type mv phone db and press
Return to move the phone file to the db directory.
To move around from directory to directory you use the cd
- 1. Type cd and press Return to make
sure you are in your HOME directory.
- 2. Type pwd and press Return to
display your present working directory.
- 3. Type cd db and press Return to
change to the db directory.
- 4. Type pwd and press Return.
Notice you are now in the db directory.
- 5. Type cd ../bin and press Return
to change to the "bin" directory that you created earlier.
- 6. Again type pwd and press Return
to display your present working directory.
- 7. Type cd and press Return to
change back to your HOME directory.
DELETING FILES AND DIRECTORIES
The following commands remove files or directories.
- 1. Remove the files myfile and myph by typing rm
myfile myph and pressing Return. The rm command does
not respond if it was successful.
- 2. Type ls -x and press Return to
see that myfile was removed.
cj> ls -x
bin db letters tmp
- 3. Type rmdir tmp and press Return
to remove the tmp directory.
- 4. Type ls -x and press Return to
display the contents of your directory.
cj> ls -x
bin db letters
OTHER USEFUL COMMANDS
There are many other commands that make life easy on the UNIX System; the
more popular ones are included in the following examples.
- 1. Type cd db and press Return to
change directories to db.
- 2. Type wc phone and press Return
to display how many characters, words, and lines are in the file.
cj> wc phone
3 7 131 phone
There are 3 lines, 7 words, and 131 characters in the file.
- 3. Select the line containing "Austin" from the file by
typing grep Austin phone and pressing Return. Notice the
line containing "Austin" is displayed on your terminal.
- 4. Sort the "phone" file by typing sort phone
and pressing Return. Notice that the order of the lines are
rearranged and displayed on your terminal in alphabetical order.
System V and BSD with System V extensions
- 5. Cut out the first field of the "phone" file by typing
cut -f1 -d: phone and pressing Return. Your screen should
look like the following display:
cj> cut -f1 -d: phone
- 6. Type cd and press Return to
return to your HOME directory.