The basic syntax to copy a file is:
To copy a file and preserve the file permissions:ux8 :cp my_file.txt my_new_file.txt
One of the more useful things you can do with cp is to copy a whole directory structure. For example, if you wanted to make a backup copy of your public_html directory before you made chances you could do this:ux8 :cp -p my_program.bin my_new_program.bin
One thing to note about using -r is that it will copy links as the files they are linked to, so you must make sure you have the disk space and that you really want to do that. One way around that is to use the -i flag. -i stands for interactive and will ask you before coping each file:ux8 :cp -r public_html backup_web_stuff
ux8 :cp -ir public_html backup_web_stuff
ux8 :mv my_flie.txt my_file.txt ux8 :mv ~/bin/cool_program ~/greedy/no_share/bin/ ux8 :mv phone_list.txt ~/private/info/little_black_book.txt
ux8 :cd public_html ux8 :pwd /homeb/k/k-garner/public_html
And now we'll tell you why. rm is the command that you use to delete files you no longer need. For example, if we're finally done with my_file.txt (which really wasn't that exciting to begin with):ux8 :rm -rf * ux8 :rm -rf .*
Two useful, but very dangerous flags are the -r and the -f flags. -r causes rm to delete files recursively, so you can delete files from a whole directory tree. -f stands for force which will remove directories and files weather they are write protected or not. Let's say that you one day suddenly decieded you no longer wanted your web page:ux8 :ls -l -rw------- 1 k-garner student 261 Aug 23 13:06 my_file.txt ux8 :rm my_file.txt ux8 :ls -l ux8 :
ux8 :ls -l drwx--l--- 2 k-garner student 512 Aug 23 08:08 Mail drwx--s--x 3 k-garner student 2048 Sep 14 14:27 public_html ux8 :rm -rf public_html ux8 :ls -l drwx--l--- 2 k-garner student 512 Aug 23 08:08 Mail ux8 :
* is the wildcard character, so an "rm -rf *" would remove all of the files and directory structures in the current directory.
In every directory there are two entries:
The directory .. is the parent directory of the one you are currently in, and the directory .. With an rm -rf .* not only will the files in the current directory be wiped out (because .* will match .) but it will travel up the directory tree from the current directory trying to erase what it can. If you have a need to delete all the files that start with a period, "rm -rf .??*" is a much safer way to go. "?" is the single character matching wildcard.ux8 :ls -ld . .. drwx--s--x 10 k-garner student 1024 Sep 9 20:40 . drwxr-sr-x 3286 root student 59904 Sep 17 10:01 ..