Linux学习笔记-目录类命令

1.2.1. mkdir
-p 递归创建,对于不存在的目录,可以自动创建。
后面跟多个目录名,可以一次性创建多个目录。


[root@localhost tmp]# mkdir /tmp/cn/guangdong
mkdir: cannot create directory ‘/tmp/cn/guangdong’: No such file or directory
[root@localhost tmp]# mkdir -p /tmp/cn/guangdong
[root@localhost tmp]# ls
cn  ks-script-f3PaWI  yum.log
[root@localhost tmp]# ls cn
guangdong
[root@localhost tmp]#
[root@localhost tmp]# mkdir cn/guangxi cn/fujian
[root@localhost tmp]# ls cn
fujian  guangdong  guangxi

 1.2.2. pwd
print working directory 当前路径

[root@localhost tmp]# cd cn/guangxi/
[root@localhost guangxi]# pwd
/tmp/cn/guangxi

 

1.2.3. cd
change directory改变目录
1.2.4. rmdir
remove empty directory 删除空目录,只能删除空目录,如果目录中有内容则删除不掉

[root@localhost tmp]# rmdir cn
rmdir: failed to remove ‘cn’: Directory not empty
[root@localhost tmp]#

 
1.2.5. cp
复制文件或目录copy
格式:cp [原文件或目录] [目标目录]
-r 复制目录
-p 保留文件属性,修改时间信息等

可以一次复制多个文件

[root@localhost cn]# cp /tmp/yum.log /tmp/ks-script-f3PaWI /tmp/cn
[root@localhost cn]# ls
fujian  guangdong  guangxi  ks-script-f3PaWI  yum.log

 

复制时,可以更改目录或者文件的名字

[root@localhost cn]# cp /tmp/yum.log yum2.log
[root@localhost cn]# ls
fujian  guangdong  guangxi  ks-script-f3PaWI  yum2.log  yum.log

 

1.2.6. mv
move 剪切/移动命令,重命名
格式:mv [原文件或目录] [目标目录]
和cp命令差不多

将fujian剪切到guangxi目录下

[root@localhost cn]# mv fujian/ guangxi/
[root@localhost cn]# ls
guangdong  guangxi  ks-script-f3PaWI  yum2.log  yum.log
[root@localhost cn]# ls guangxi/
fujian

 
将guanxi重命名为huanan

[root@localhost cn]# mv guangxi/ huanan
[root@localhost cn]# ls
guangdong  huanan  ks-script-f3PaWI  yum2.log  yum.log
[root@localhost cn]# ls huanan
fujian

 

1.2.7. rm
remove 文件或者目录
-r 删除目录
-f 强制删除 不会有提示确认框

[root@localhost cn]# ls
guangdong  huanan  ks-script-f3PaWI  yum2.log  yum.log
[root@localhost cn]# rm yum2.log
rm: remove regular empty file ‘yum2.log’? y
[root@localhost cn]# rm -r guangdong/
rm: remove directory ‘guangdong/’? y
[root@localhost cn]# rm -rf huanan/
[root@localhost cn]# ls
ks-script-f3PaWI  yum.log

猜你喜欢

转载自wlcacc.iteye.com/blog/2420185
今日推荐