This tutorial document assumes you've already read the first document in this series entitled "Navigating Directories with UNIX".
# view the file "readme.txt": % more readme.txtto view the file "readme.txt". The more utility displays one page of text at a time on your screen. At the more prompt
--more--(7%)press the spacebar to display the next page, or press the question mark (?) to see a list of options and commands. (The "7%" means you've already viewed 7% of the text file.)
The more command is especially useful at the end of a pipe. For instance, the command
# concatenate three files and view a page at a time: % cat file1 file2 file3 | moreconcatenates three files and pipes the output through more.
The mv command is used to move one or more files to a different location (no new files are created in the process). For example, type
# move file "sidebar.gif" to "tmp" directory: % mv sidebar.gif tmpto move the file "sidebar.gif" from the current directory to the "tmp" directory. (By the way, the command
% mv tmp/sidebar.gif .reverses the previous operation, since the dot "." refers to the current directory.) Multiple files are moved by listing them on the command line. For example, the command
# move files to the parent directory: % mv *.bin *.hqx ..moves all files with extension "bin" or "hqx in the current directory to the parent directory.
The mv command is also used to rename files. For instance, the command
# rename file "README.TXT" to "readme.txt": % mv README.TXT readme.txtrenames the file "README.TXT" to "readme.txt". Directory names are changed similarly.
Entire directories may be moved with the mv command. For example, the command
# move directory "tmp/Alpha" to a new location: % mv tmp/Alpha /usr/local/archives/public/users/trscavoessentially prunes "tmp/Alpha" and grafts it onto the target directory.
The cp command is almost identical to the mv command. The only difference is that duplicate copies of the source files are created. To copy an entire directory tree from one location to another, use the "-r" option:
# recursively copy "tmp/Alpha" to a new location: % cp -r tmp/Alpha /usr/local/archives/public/users/trscavoThus the following two commands
cp -r dirname1 dirname2 rm -r dirname1are identical to
mv dirname1 dirname2but since it's not possible to move files across file systems, the latter is not always possible.
See the next section for more information about the rm command.
To remove a single file, for example, type
# remove file "strings.html": % rm strings.htmlTo remove a bunch of files, type
# remove all files with suffix "html": % rm *.htmlbut be careful! If you type
# remove all files in the current directory BY MISTAKE!: % rm * .htmlby mistake, you've just wiped out an entire directory! This can be avoided by typing the "-i" option:
# remove all files with suffix "html" interactively: % rm -i *.htmlwhich prompts you before deleting a file. Of course, this takes longer, but it's safer. Indeed, system administrators often make "-i" a default option.
To remove all files in a certain directory, as well as all files in all subdirectories, use the -r option:
# recursively remove files and directories: % rm -r tmp/*But beware! You could mistakenly wipe out your entire account if you're not careful!
# view filename one page at a time: % more filename # move filename to dirname: % mv filename dirname # rename filename1 to filename2: % mv filename1 filename2 # move dirname1 to dirname2: % mv dirname1 dirname2 # copy filename to dirname: % cp filename dirname # copy filename1 to filename2: % cp filename1 filename2 # recursively copy dirname1 to dirname2: % cp -r dirname1 dirname2 # remove file filename: % rm filename # remove file filename interactively: % rm -i filename # remove all files in the current directory: % rm * # prune the directory tree at subdirectory dirname: % rm -r dirnameThe next in this series of tutorial documents is entitled "Manipulating Directories with UNIX".