/):
Click here to view code image
matthew@seymour:~$ mv filename /newdirectory/newfilename
Or you can use relative paths from the current directory (starting without a
slash). This is generally entered in the source directory, but it doesn’t have to
be; you can use an absolute path to indicate the source directory, too:
Renaming Files with rename
We often use mv to rename a single file. This would be tedious, however, for
renaming multiple files. For this, you use rename. The basic syntax is
simple:
Click here to view code image
matthew@seymour:~$ rename 's/filename/newfilename/'
The part in the single quotes is a Perl expression, which means the command
is far more powerful than this example suggests. Let’s say you have a
directory filled with files that end with the extension .htm, and you want to
rename them all to .html:
Click here to view code image
matthew@seymour:~$ rename 's/.htm/.html/' *.htm
Notice here that the . characters must be preceded with a \ to let the
command know they are part of the text being searched and replaced rather
than part of the command. This is called “escaping” the characters. Next,
notice that the replace part of the command is followed by a wildcard
character (*) and the remainder of the filename to search for in the directory.
Anything matching the combination of filename.htm will be renamed to
filename.html.
rename is incredibly powerful. See the man page for more.
Deleting Files and Directories with rm
The rm command has only one parameter of interest: —preserve-root.
By now, you should know that issuing rm -rf / with sudo destroys your
Linux installation because -r means recursive and -f means force (that is,
do not prompt for confirmation before deleting). It is possible for a clumsy
person to issue this command by accident—not by typing the command on
purpose but by putting a space in the wrong place. For example:
Click here to view code image