Web design tools - CHAPTER 13 INTRODUCING THE BASH SHELL 215
CHAPTER 13 INTRODUCING THE BASH SHELL 215 One important command-line option for cpis r. This stands for recursive and tells BASH that you want to copy a directory and its contents (as well as any directories within this directory). Most commands that deal with files have a recursive option. Note Only a handful of BASH commands default to recursive copying. Even though it s extremely common to copy folders, you still need to specify the -r command option most of the time. One curious trick is that you can copy a file from one place to another but, by specifying a filename in the destination part of the command, change its name. Here s an example: cp myfile /home/keir/myfile2 This will copy myfileto /home/keir, but rename it as myfile2. Be careful not to add a final slash to the command when you do this. In the example here, doing so would cause BASH to think that myfile2 is a directory. This way of copying files is a handy way of duplicating files. By not specifying a new location in the destination part of the command, but still specifying a different filename, you effectively duplicate the file within the same directory: cp myfile myfile2 This will result in two identical files: one called myfile and one called myfile2. Moving Files The mv command is similar to cp, except that rather than copying the file, the old one is removed. You can move files from one directory to another, for example, like this: mv myfile /home/keir/ You can also use the mv command to quickly rename files: mv myfile myfile2 Figure 13-4 shows the results of using mv to rename a file. Note Getting technical for a moment, moving a file in Linux isn t the same as in Windows, where a file is copied and then the original deleted. Under Ubuntu, the file s absolute path is rewritten, causing it to simply appear in a different place in the file structure. However, the end result is the same.