Your Internet Consultant - The FAQs of Life Online
3.30. How do I manipulate files with UNIX?
Following are some important commands for manipulating files and directories.
I've put them more or less in the order of most common use. First thing's
first, though: use and love the man (manual) command. Typing man
cp, for instance, will tell you everything you could want to know about the
cp command. Type man man and man intro for general system
help. Most of the following commands take special options, called
arguments, for tweaking how they work. There isn't room here to list
each command's options and arguments, so make judicious use of the man
- pwd. Stands for Present Working Directory. It will tell you
what directory you're currently in. Log on to your system and type pwd
to find out what your home directory is called. Mine is
- ls. Lists all the files and directories under your present
working directory. There's a problem, though: the ls command doesn't
tell you whether you're looking at the names of files or directories. Not to
worry: if you type ls -CF, you'll get a nicely formatted list, with
executable files (programs) indicated by an asterisk and directories indicated
by a slash.
Note: Some files in UNIX are normally invisible (or
hidden files). Any filename that begins with a period, such as
.newsrc and .login, isn't normally shown with the ls
command. You can see them, however, if you explicitly ask to see all files by
adding the a argument to the ls command: type ls -a or
ls -aCF (yes, capitalization matters!) to see your invisible files.
Invisible files usually specify your system configuration and preferences
information--or, perhaps you simply have something to
- cd. Stands for change directory. You can move to a
directory that is under your present directory by typing something like cd
mystuff. To move to the directory above your current one, type cd ..
(that's two dots. Why two dots? It's a mystery to me). If you know exactly what
directory you want to go to, you can type a command like cd /lib/sys.
- cp. An abbreviation for copy. Not surprisingly, the
cp command lets you copy a file. Typing cp file1 file2 will
create an exact copy of file1 in your present directory. Typing cp
file1 /files/home/wombat will create a copy of file1 in another
- mv. An abbreviation for move. Lets you move files
around directories. Moving a file copies a file to your specified directory,
then deletes the original.
- rm. Stands for remove. This command will let you erase
files that you no longer need. Be careful! There is no "undelete" command in
UNIX; once your file is gone, it's gone forever. rm file2 will erase one
file in your present directory. Typing rm * will delete every file in
the directory. In UNIX, like in DOS, the asterisk means all files.
- cat. Stands for catenate, an obscure word meaning
to form a chain or series. In its most basic use, cat works just
like DOS' TYPE command: it displays the contents of a text file.
Actually, you can use it to display the contents of any file, but binary files
(like programs and digitized pictures) will only appear as garbled data. To
display a file, just type cat letter_to_grandma and the computer will
dump the letter to your screen. If the text in the file is too long, the
beginning will scroll off the top of the screen faster than you can read it.
This brings us to the next command.
- more. Shows you the contents of a text file one page at a
time. To use it, type more letter_to_grandma. After each screenfull of
text, you'll see the word more. Strike the space bar to see the next
page of text. Your system may also have a program called less, which
does the same as more, only better. Just as they say, less is more.
:-) As always, type man less or man more for complete
- chmod. Can be used to change the permissions
of files. UNIX permissions can be tricky. Remember that UNIX is a timesharing
system that can be used by many people simultaneously. You might want to keep
some of your files--for instance, your electronic mail--private, but let other
users read or modify certain files. So chmod, which stands for change
mode, makes it possible to allow or deny yourself, all system users or
certain users to read, write, or execute your files. For more information (you
saw this coming, right?) type man chmod.
Table of Contents | Previous Section | Next Section