342
Networking: A Beginner's Guide
File Management and Manipulation
This section provides an overview of the basic command-line tools for managing files
and directories. Most of this overview should be familiar if you have used a command-
line interface before. Basically, you use the same old functions, just with new commands.
cp: Copy Files
The cp command is used to copy files. By default, this command works silently, displaying
status information only if there is an error condition. For example, to copy index.html to
index-orig.html, type the following:
[root@ford /root]# cp index.html index-orig.html
The cp command has a large number of options, which are detailed on its man
page. The most common options are -f to force copy (do not ask for verification) and
-1
for an interactive copy (ask for verification before copying). For example, to copy
interactively all files ending in .html to the /tmp directory, type the following:
[root@ford /root]# cp -i *.html /tmp
mv: Move Files
Use the mv command to move files from one location to another. The command can
move files across partitions as well; however, realize that when moving a file between
partitions that you are actually copying the file to the other partition, and then erasing
the original, so it can take longer than moving a file within a partition. Moving a file
within a single partition just tells the system that the file is in a different directory; the
file isn't copied or physically moved on the disk.
For example, to move a file from /usr/src/myprog/bin/* to /usr/bin, type the
following:
[root@ford /root]# mv /usr/src/myprog/bin/* /usr/bin
The most common options are -f to force a move and -l to move interactively.
Although Linux has no explicit rename tool, you can use mv to accomplish this
task. To rename /tmp/blah to /tmp/bleck, type the following:
[root@ford /root]# mv /tmp/bleck /tmp/blah
ln: Link Files
The ln command allows you to establish a hard link or a soft link. (See the "About Files
and Directories" section earlier in this chapter for additional information.) The general
format of this command is as follows:
[root@ford /root]# ln original_file new_file
The ln command has many options, most of which you'll never need to use. The
most common option is -s, which creates a symbolic link instead of a hard link. For