Linux目录、文件的创建与删除
目錄的創(chuàng)建:
mkdir - make directories
使用示例及說明:
[root@localhost?~]#?mkdir?/root/x/y/z mkdir:?cannot?create?directory?`/root/x/y/z':?No?such?file?or?directory如果直接創(chuàng)建層級目錄,是不能創(chuàng)建的。
[root@localhost?~]#?mkdir?-p?/root/x/y/z如果帶上“-p”就可以了,“-p”的意思是如果父目錄不存在則創(chuàng)建父目錄。
[root@localhost?~]#?tree?/root /root |--?Desktop |--?anaconda-ks.cfg |--?install.log |--?install.log.syslog `--?x`--?y`--?z 4?directories,?3?filestree命令可以查看目錄樹狀結(jié)構(gòu)。
[root@localhost?~]#?mkdir?-pv?/root/test/{x/y,z} mkdir:?created?directory?`/root/test' mkdir:?created?directory?`/root/test/x' mkdir:?created?directory?`/root/test/x/y' mkdir:?created?directory?`/root/test/z'說明:/root/test/{x/y,z}等于/root/test/x/y?/root/test/z}
-v:當(dāng)創(chuàng)建目錄后顯示信息。
[root@localhost?~]#?rmdir?-p?/root/x/y/z rmdir:?/root:?Directory?not?empty說明:rmdir用于刪除空目錄,如果目錄非空則不能刪除;
????? -p:用于刪除目錄和它的父目錄(如果父目錄是空的),此為選項(xiàng)。
????? 可以從本例中看出,刪除z目錄時,x和y目錄一并被刪除,但是因?yàn)?root非空無法將其刪除。
????? 可以通過tree命令查看:
從本例可以看出/root非空。
***********************分割線*************************
文件的創(chuàng)建于刪除:
[root@localhost?~]#?touch?/root/test/hello [root@localhost?~]#?ls?-l?/root/test/hello -rw-r--r--?1?root?root?0?Dec??7?03:42?/root/test/hellotouch本來的用途是用來修改文件的時間戳,卻同時也可以用來創(chuàng)建空文件,如上例所示:
用# touch /root/test/hello創(chuàng)建了hello空文件,用ls -l /root/test/hello可以查看hello文件信息;
同時也可以使用stat查看文件狀態(tài):
[root@localhost?~]#?stat?/root/test/helloFile:?`/root/test/hello'Size:?0?????????Blocks:?8??????????IO?Block:?4096???regular?empty?file Device:?fd00h/64768dInode:?29851728????Links:?1 Access:?(0644/-rw-r--r--)??Uid:?(????0/????root)???Gid:?(????0/????root) Access:?2014-12-07?03:42:22.000000000?+0800 Modify:?2014-12-07?03:42:22.000000000?+0800 Change:?2014-12-07?03:42:22.000000000?+0800可以看到hello的的訪問(access)、修改(modify)、change(改變)時間一樣;
[root@localhost?test]#?touch?-a?hello [root@localhost?test]#?stat?helloFile:?`hello'Size:?0?????????Blocks:?8??????????IO?Block:?4096???regular?empty?file Device:?fd00h/64768dInode:?29851728????Links:?1 Access:?(0644/-rw-r--r--)??Uid:?(????0/????root)???Gid:?(????0/????root) Access:?2014-12-07?03:51:22.000000000?+0800 Modify:?2013-12-07?12:50:30.000000000?+0800 Change:?2014-12-07?03:51:22.000000000?+0800使用-a選項(xiàng)可以修改文件的訪問時間,同時改變時間也一并修改。
(注意我已經(jīng)使用cd命令切換到了/test目錄,所以才能直接把參數(shù)輸入為“hello”)
[root@localhost?test]#?touch?-m?-t?201312071250.30?hello [root@localhost?test]#?stat?helloFile:?`hello'Size:?0?????????Blocks:?8??????????IO?Block:?4096???regular?empty?file Device:?fd00h/64768dInode:?29851728????Links:?1 Access:?(0644/-rw-r--r--)??Uid:?(????0/????root)???Gid:?(????0/????root) Access:?2012-12-07?12:50:30.000000000?+0800 Modify:?2013-12-07?12:50:30.000000000?+0800 Change:?2014-12-07?03:47:35.000000000?+0800說明:-m用來修改文件的修改時間
????? -t用來直接設(shè)置時間,如果沒有則使用當(dāng)前時間,格式:[[CC]YY]MMDDhhmm[.ss]
使用nano命令可以編輯文件,比較簡單,大家可以自行嘗試。
rm命令用來刪除文件。
刪除后找不到hello文件了:
[root@localhost?test]#?tree . |--?a_c |--?a_d |--?b_c |--?b_d |--?x |???`--?y `--?z 7?directories,?0?files[root@localhost test]# rm -rf /root/test
選項(xiàng)-r遞歸地刪除/test及其包含的所有文件和目錄,
????-f強(qiáng)制刪除不提示。
可以看到/test目錄已經(jīng)沒有了:
[root@localhost?~]#?tree . |--?Desktop |--?anaconda-ks.cfg |--?install.log `--?install.log.syslog 1?directory,?3?files謝謝!
轉(zhuǎn)載于:https://blog.51cto.com/kissofsun/1587263
總結(jié)
以上是生活随笔為你收集整理的Linux目录、文件的创建与删除的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: myisam表锁及锁粒度调节
- 下一篇: oracle的存储过程