more
or less
: To read a file. Use less
.
Usage :
less file
nedit
, kdedit
, vi
, emacs
:
To edit a file.
Usage : nedit file
cp
: To copy a file.
Usage :
cp original copy
copies original
to copy
.
If original
is a file but copy
is a directory,
a copy of original
with the same name will be made in that directory.
rm
: To remove a file.
Usage : To remove a file
rm file
To remove all files excluding subdirectories (Be careful with this!)
rm *
mv
: To move a file or a directory
Usage :
mv old_name new_name
renames original
to copy
.
If original
is a file but copy
is a directory,
original
will be moved to that directory.
You can move directories around in exactly the same fashion,
rmdir
: To remove an empty directory.
Usage :
rmdir sub_dir
As I told you, you can use more
or less
to read a file. When using
more
or less
,
the space bar usually takes you one page further, pressing b
will get you to the previous page, and you can search for a
word by doing
[contents of a file displayed] :/fooHere the colon means the command line (It's given at the bottom. If you see it, you don't need to type that. If you don't, it doesn't hurt to type that.), the slash means search forward for the word `foo'. To search backward, use
?
instead of /
. To search the same word again, just press
n
for `next'. To get out, press q
for `quit'.
To write a file, you need an editor. Under the `K' button, you should see a
menu item labeled `editors'. There are many choices. It is up to you and your
taste to settle on a particular one. Perhaps the easiest one is
nedit
or kdedit
. But for anything that is more complicated
than simple text, you need an advanced editor like vi
or
emacs
. Try them out. At the command prompt, just say
HAL9000> nedit fileto edit
file
(new or old).
There is a neat feature in the Unix X-windows: Two-click copy and paste. If you want to copy any text that's displayed in any windows (except the previewers), put the cursor at the beginning of the text, press and hold the left mouse button and scan the text. This highlights the scanned text. Now release the left mouse, move the cursor to the position where you want a copy to be pasted and then click the middle mouse button. That's it.
To remove a file, do
HAL9000> rm foo.txtTo remove a directory, first
rm
all files in that directory. This can be accomplished
by going into the directory, say, foo_dir
HAL9000> cd foo_dirand issuing the command
HAL9000> rm *The star
*
in Unix means ``anything" or the ``wild card".
For instance, if you want to remove all
files that start with corrupted
and
end with .txt
, you can do
rm corrupt*.txtHowever, this will not remove any subdirectory of
foo_dir
.
In such cases, you have to repeat these steps.
Now go up to the parent directory,
HAL9000> cd ..and issue the command
HAL9000> rmdir foo_dirYou can also do, from the parent directory of the one you want remove,
HAL9000> rm -r foo.dirHere,
-r
means ``recursively", and it will wipe out all the files and
subdirectories under foo_dir
including foo_dir
.
If you do this in your home directory, you can easily wipe out all your work! And in Unix, unless there is a backup tape made (by the system operator and these are usually days old), there is no way you can recover rm'ed files. I repeat: There is no way you can recover rm'ed files! So always make copies of your important files.
To copy a file,
HAL9000> cp foo.txt goo.txtThis copies
foo.txt
to goo.txt
.
foo.txt
is not destroyed. However, if
goo.txt
was an existing file, its old content is now
destroyed and replaced by the new content. So, be careful.
To copy a directory, you should first make a directory
HAL9000> mkdir copy_dirand copy the content
HAL9000> cp original_dir/* copy_dir/This will copy all the files in
original_dir
to copy_dir
.
If you want to copy the directories as well, you can do
HAL9000> cp -r original_dir copy_dirwithout first making
copy_dir
. The option -r
here means
`recursively'.
However, this is dangerous. If you have linked directories that
happened to form a loop, the copying process
will not end until it fills up the
whole disk! If you are unsure, do the safe thing. Copy each directory
manually.
To change a file name,
HAL9000> mv foo.txt goo.txtThis renames
foo.txt
to goo.txt
.
Again if goo.txt
was an existing file,
its content will be replaced.
To move a file to another directory,
HAL9000> mv foo.txt foo_dir/This moves
foo.txt
to the subdirectory foo_dir
. If you now do
HAL9000> ls foo_dir
foo.txt
will show up there. If you do,
HAL9000> mv foo.txt foo_dir/goo.txtthen this moves
foo.txt
to the subdirectory foo_dir
and rename it to goo.txt
.
You can move directories around in exactly the same way.