Managing Your Own Files and
Directories
Managing files : Commands covered in this section: mkdir, rmdir, cp, mv, rm,chmod Let's begin with directories. You create directories with mkdir and remove them with rmdir. Exercise 1.1 Create two new directories with the mkdir command (use
the ls command to confirm the new directories were created).
Now remove the second directory you just created (and
list the files in the current directory again to see if the second directory
was removed).
rmdir will only remove empty directories. If a directory contains files, you must remove them first before using rmdir. Alternatively, you can recursively delete the directory and its contents using the appropriate option with the rm command as discussed later in this section. Let's move on to working with files. First, you'll need to copy some existing files from elsewhere in the filesystem into your test directory. You use the cp command to do this. Exercise 1.2 Before going on, move into the new "test" directory you
just created. You will use this area to experiment (thus minimizing any
potential damage to other files in your home directory!).
Now you can copy some files into your test directory with
cp.
The three cp commands above copy existing files from the "/etc" directory into the current directory (repesented by "."). Now remove (delete) a file using the rm command. % rm group
Finally, move (rename) one of the files using mv.
Since cp, mv, and rm have the potential to destroy data, they offer an interactive option which prompts you before proceeding. This is invoked with the "-i" option. Your system administrator may have already configured your account to use this option by default. Both cp and mv require two arguments: the existing location and the destination of the file to be copied or moved. The destination can be another file or a directory. Let's compare the results in each case. Exercise 1.3 First, let's make a new directory within the test directory.
Then try the following command:
The result in this case is a second copy of the file (called
"hosts2") in the current directory. Now try the following:
This time, the file was copied to the "junk" directory, keeping the same name as the original ("hosts"). The shell allows the use of wildcards to reference more than one file at a time. The "?" character stands for a single character with any value and the "*" character stands for any number of characters with any value. For example, "host*" would match "hosts" and "hosts2" in the above example.
Have a Unix Problem
Unix Books :-
Return to : - Unix System Administration Hints and Tips (c) www.gotothings.com All material on this site is Copyright.
|