266 Managing Files and Directories
You can also use wildcards for more than searching: they can come in handy when you want to move
and rename files. And regular expressions can help you rename files with characters like * and ? in
them.
For more on that, read on.
17.5 Copying, Moving and Renaming Files and Directo-
ries
By now, you’ve learned a little about the structure of the filesystem; and you’ve learned how to create
files and directories.
But just because you know how to create files and directories doesn’tmeanthatyou’re stuck with
the changes you’ve made. What if you want to rename and/or move files and directories?
Let’s start with the copy command.
17.5.1 Copying Files
Like so many Linux features, you have a variety of options from which to choose when you want
to manipulate files and directories. You can also use wildcards when you’re copying, moving, or
deleting files and directories.
Basically, the copy command is not much more complex than typing:
cp <source> <destination>
so to copy the file sneakers.txt to the directory tigger in your login directory, just type:
cp sneakers.txt tigger
Notice that you also used relative pathnames to copy the file. You can use both relative and absolute
pathnames with cp. Our login directory is the parent of the directory tigger; meaning that tigger
is one directory down from ours.
Read the cp man page (man cp) for a full list of the options available with cp. But among the options
you can use with cp are:
-i – interactive. Prompts you to confirm if the file is going to overwrite a file in your destina-
tion. This is a handy option because it can help prevent you from making mistakes.
-r – recursive. Rather than just copying all the files and directories, copies the whole directory
tree, subdirectories and all, to another location.
Comments to this Manuals