python rm 条件_删除文件 (rm)
# 附錄A-練習14:刪除文件 (rm)
這節練習中,你將學會如何使用`rm`命令刪除一個文件。
### 做到這些
### Linux
~~~
$ 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
$
~~~
### Windows
~~~
> 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
>
~~~
### 你應該學到的
這里我們清理了之前練習中的所有文件。還記得我讓你嘗試使用`rmdir`刪除一個不為空的目錄嗎?那個操作失敗了因為你無法刪除包含文件在內的目錄。要做到這一點,你需要刪除文件,或者遞歸刪除所有的內容。這是你要在本節練習結尾要做的事情。
### 更多練習
> - 清理從開始練習到現在所有`temp`目錄下的文件。
> - 在你的筆記本上寫下遞歸刪除文件時一定要小心。
總結
以上是生活随笔為你收集整理的python rm 条件_删除文件 (rm)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 联想g510升级方案_联想集团副总裁阿木
- 下一篇: php定时发送生日模块消息_Swoft