Linux达人养成(二)目录处理命令

来源:互联网 发布:mac里面的照片怎么导出 编辑:程序博客网 时间:2024/06/06 20:54

1、创建目录mkdir;
递归创建目录 mkdir -p hunan/changde

[root@localhost ~]# lsanaconda-ks.cfg  install.log  install.log.syslog  japan[root@localhost ~]# mkdir hunan[root@localhost ~]# lsanaconda-ks.cfg  hunan  install.log  install.log.syslog  japan[root@localhost ~]# mkdir -p zhejiang/hangzhou[root@localhost ~]# lsanaconda-ks.cfg  hunan  install.log  install.log.syslog  japan  zhejiang[root@localhost ~]# cd zhejiang[root@localhost zhejiang]# lshangzhou

2、删除文件或目录rm -rf

[root@localhost ~]# lsanaconda-ks.cfg  hunan  install.log  install.log.syslog  japan  zhejiang[root@localhost ~]# rm -rf japan[root@localhost ~]# lsanaconda-ks.cfg  hunan  install.log  install.log.syslog  zhejiang

3、cp复制文件;
-r 复制目录
-p 连带属性复制
-d 若源文件是链接文件,则复制链接属性
-a 相当于-pdr

将zhejiang/hangzhou/xihu.txt 文件复制到 hunan/changde/目录下

[root@localhost ~]# cp install.log /tmp/aa  #复制文件改名复制[root@localhost ~]# ls /tmpaa[root@localhost ~]# lsaa  anaconda-ks.cfg  hunan  install.log  install.log.syslog  zhejiang[root@localhost ~]# cp zhejiang/hangzhou/xihu.txt hunan/changde/ #复制文件[root@localhost ~]# ls hunan/changde/xihu.txt[root@localhost ~]# cp zhejiang/hangzhou hunan/cp: 略过目录"zhejiang/hangzhou"[root@localhost ~]# ls hunanchangde[root@localhost ~]# cp -r zhejiang/hangzhou hunan/  #复制目录[root@localhost ~]# ls hunanchangde  hangzhou

4、mv剪切文件或目录 操作目录不用加 -r

将zhejang/hangzhou/wushan.txt 剪切到hunan/changde/目录下

[root@localhost ~]# touch zhejiang/hangzhou/wushan.txt#创建wushan.txt文件[root@localhost ~]# ls zhejiang/hangzhou/wushan.txt  xihu.txt[root@localhost ~]# vim zhejiang/hangzhou/wushan.txt[root@localhost ~]# cat zhejiang/hangzhou/wushan.txt This is wushan.welcome to there.[root@localhost ~]# mv zhejiang/hangzhou/wushan.txt hunan/changde/[root@localhost ~]# ls hunan/changde/taoyuan.txt  wushan.txt  xihu.txt[root@localhost ~]# cat hunan/changde/wushan.txtThis is wushan.welcome to there.[root@localhost ~]# ls zhejiang/hangzhou/xihu.txt

重命名目录或文件

[root@localhost ~]# mv zhejiang/hangzhou zhejiang/ningbo[root@localhost ~]# ls zhejiangningbo
0 0
原创粉丝点击