Prev | Current Page 222 | Next

Christopher Negus

"Linux Bible, 2008 Edition: Boot up to Ubuntu, Fedora, KNOPPIX, Debian, openSUSE, and 11 Other Distributions"


Moving, Copying, and Deleting Files
Commands for moving, copying, and deleting files are fairly straightforward. To change the location
of a file, use the mv command. To copy a file from one location to another, use the cp command.
To remove a file, use the rm command. Here are some examples:
$ mv abc def
$ mv abc ~
$ cp abc def
$ cp abc ~
$ rm abc
$ rm *
Of the two move (mv) commands, the first moves the file abc to the file def in the same directory
(essentially renaming it), whereas the second moves the file abc to your home directory (~). The
first copy command (cp) copies abc to the file def in the same directory, whereas the second
copies abc to your home directory (~). The first remove command (rm) deletes the abc file; the
second removes all the files in the current directory (except those that start with a dot).
For the root user, the mv, cp, and rm commands are aliased to each be run with the -i
option. This causes a prompt to appear asking you to confirm each move, copy, and
removal, one file at a time, and is done to prevent the root user from messing up a large group of files
by mistake.
Another alternative with mv is to use the -b option. With -b, if a file of the same name exists at the
destination, a backup copy of the old file is made before the new file is moved there.


Pages:
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234