CUT AND PASTE WITH UNIX COMMANDS
One editing area in which non-programmers
is in what might be called
`cut and paste' operations _
changing the name of a file,
making a copy of a file somewhere else,
moving a few lines from one place to another in a file,
inserting one file in the middle of another,
splitting a file into pieces,
splicing two or more files together.
Yet most of these operations are actually quite easy,
if you keep your wits about you
The next several sections talk about cut and paste.
for moving entire files around,
for operating on pieces of files.
Changing the Name of a File
and you want it to be called
program that renames files
it `moves' the file from one name to another, like this:
That's all there is to it:
from the old name to the new name.
Warning: if there is already a file around with the new name,
its present contents will be
by the information from the other file.
The one exception is that you can't move a file
Sometimes what you want is a copy of a file _
an entirely fresh version.
This might be because you want to work on a file, and
yet save a copy in case something gets fouled up,
or just because you're paranoid.
In any case, the way to do it is with the
is big on short command names,
which are appreciated by heavy users,
but sometimes a strain for novices.)
Suppose you have a file called
you want to save a copy before you make some
dramatic editing changes.
might be acceptable _ then type
and you now have two identical copies of the file
previously contained something,
Now if you decide at some time that you want to get
back to the original state of
(if you're not interested in
if you still want to retain a safe copy.
Both of them clobber the `target' file
if it already exists, so you had better
be sure that's what you want to do
If you decide you are really done with a file
forever, you can remove it
throws away (irrevocably) the file called
Putting Two or More Files Together
The next step is the familiar one of collecting two or more
This will be needed, for example,
when the author of a paper
decides that several sections need to be combined
There are several ways to do it,
of which the cleanest, once you get used to it,
programs have two-letter names.)
`concatenate', which is exactly
Suppose the job is to combine the files
into a single file called
will get printed on your terminal.
be printed on your terminal,
combines the files, all right,
but it's not much help to print them on the terminal _
Fortunately, there is a way.
that instead of printing on your terminal,
you want the same information put in a file.
The way to do it is to add to the command line
where you want the output to go.
you're putting something into
and anything that was already there is destroyed.)
`capture' the output of a program
is one of the most useful aspects of
Fortunately it's not limited to the
program that prints on your terminal.
We'll see some more uses for it in a moment.
Naturally, you can combine several files,
cat file1 file2 file3 ... >bigfile
is there any difference between
Answer: for most purposes, no.
You might reasonably ask why there are two programs
is obviously all you need.
will do some other things as well,
which you can investigate for yourself
For now we'll stick to simple usages.
Adding Something to the End of a File
Sometimes you want to add one file to the end of another.
We have enough building blocks now that you can do it;
in fact before reading further it would be valuable
which is probably most direct.
You should also understand why
(Don't practice with a good `good'!)
The easy way is to use a variant of
except that instead of clobbering the old file,
it simply tacks stuff on at the end.