268 Managing Files and Directories
If you want to move a file out of your home directory and into another directory, you would type:
mv sneakers.txt tigger
or, mv sneakers.txt /home/billy /home/billy/tigger using absolute pathnames.
17.5.3 Renaming Files
Actually, we’ve already covered half of renaming, because when you copy or move files, you can also
rename.
To copy the file sneakers.txt from our login directory to our tigger subdirectory, just type:
cp sneakers.txt tigger
To copy and rename that file from sneakers.txt to piglet.txt,type:
cp sneakers.txt tigger/piglet.txt
To move and rename the file, just substitute mv for cp in the above example.
If you cd to tigger and use ls,you’ll see the file piglet.txt.
If you just want to rename the file and keep its location, just mv in your current directory:
mv sneakers.txt piglet.txt
17.5.4 Deleting Files and Directories
We talked about creating files with the touch command and by using redirection in Chapter 16 on
page 217. And we created the directory tigger using mkdir.
But we haven’t discussed how to delete files and directories.
Deleting files and directories with the rm command (man rm) is a straightforward process.
Let’s take our new file piglet.txt, and delete it from the tigger directory with the rm command:
rm piglet.txt
What happens if we didn’t really want to get rid of it? Too late! Again, that’swherethe-i (interac-
tive) option comes in handy, because with it, we have the chance to think about whether we really
want to toss the file.
Commenti su questo manuale