Chapter 14
Removing A File (rm)
14.1 Do This
Source 25: Linux/Mac OSX Exercise
14
$ cd temp $ ls
uncool.txt iamcool.txt neat.txt something thefourthfile.txt
$ rm uncool.txt $ ls
iamcool.txt neat.txt something thefourthfile.txt
$ rm iamcool.txt neat.txt thefourthfile.txt $ ls something
$ cp -r something newplace $ $ rm something/awesome.txt
$ rmdir something $ rm -rf newplace $ ls $
Source 26: Windows Exercise
14
> cd temp > ls Directory: C:\Users\zed\temp
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 12/22/2011 4:52 PM newplace
d---- 12/22/2011 4:52 PM something
-a--- 12/22/2011 4:49 PM 0 iamcool.txt
-a--- 12/22/2011 4:49 PM 0 neat.txt
-a--- 12/22/2011 4:49 PM 0 thefourthfile.txt
-a--- 12/22/2011 4:49 PM 0 uncool.txt
> rm uncool.txt > ls Directory: C:\Users\zed\temp
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 12/22/2011 4:52 PM newplace
d---- 12/22/2011 4:52 PM something
-a--- 12/22/2011 4:49 PM 0 iamcool.txt
-a--- 12/22/2011 4:49 PM 0 neat.txt
-a--- 12/22/2011 4:49 PM 0 thefourthfile.txt > rm iamcool.txt
> rm neat.txt > rm thefourthfile.txt > ls Directory: C:\Users\zed\temp
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 12/22/2011 4:52 PM newplace
d---- 12/22/2011 4:52 PM something > cp -r something newplace
> rm something/awesome.txt > rmdir something > rm -r newplace > ls >
14.2 You Learned This
Here we clean up the files from the last exercise. Remember when I had you try to
rmdir on a directory with something in it? Well that failed because you can't
remove a directory with files in it. To do that you have to remove the file,
or recursively delete all of its contents. That's what you did at the end of
this.
14.3 Do More
- Clean up everything in temp from all the exercises so far.
- Write in your notebook to be careful when running recursive remove on
files.