mkdir
概述
创建目录
语法
mkdir [OPTION]... DIRECTORY..
常用选项
-p:--parents,自动按需创建父目录
-v:--verbose,显示详细创建过程
-m:--mode,创建时给定权限
命令演示 
[root@localhost mytest]# mkdir -p xiangjis 
[root@localhost mytest]# ll 
总用量 0 
drwxr-xr-x. 2 root root 6 7月 19 14:33 xiangjis 
[root@localhost mytest]# mkdir -p xiangjis/al/dy 
[root@localhost mytest]# tree xiangjis 
xiangjis 
└── al 
└── dy 
2 directories, 0 files 
[root@localhost mytest]# mkdir -v xiangjis2 
mkdir: 已创建目录 “xiangjis2” 
[root@localhost mytest]# ll 
总用量 0 
drwxr-xr-x. 3 root root 19 7月 19 14:36 xiangjis 
drwxr-xr-x. 2 root root 6 7月 19 14:36 xiangjis2 
[root@localhost mytest]# mkdir -m g+w xiangjis3 
[root@localhost mytest]# mkdir -m o+w xiangjis4 
[root@localhost mytest]# \ls -l 
总用量 0 
drwxr-xr-x. 3 root root 19 7月 19 14:36 xiangjis 
drwxr-xr-x. 2 root root 6 7月 19 14:42 xiangjis2 
drwxrwxrwx. 2 root root 6 7月 19 14:46 xiangjis3 
drwxrwxrwx. 2 root root 6 7月 19 14:46 xiangjis4 
[root@localhost mytest]# tree 
. 
├── xiangjis 
│ └── al 
│ └── dy 
├── xiangjis2 
├── xiangjis3 
└── xiangjis4 
6 directories, 0 files
rmdir
概述
删除空目录
语法
rmdir [OPTION]... DIRECTORY..
常用选项
-p:删除某目录后,如果其父目录为空,则一并删除
-v:显示详细删除过程
命令演示 
[root@localhost mytest]# tree 
. 
├── xiangjis 
│ └── al 
│ └── dy 
├── xiangjis2 
├── xiangjis3 
└── xiangjis4 
6 directories, 0 files 
[root@localhost mytest]# rmdir xiangjis 
rmdir: 删除 “xiangjis” 失败: 目录非空 
[root@localhost mytest]# rmdir xiangjis2 
[root@localhost mytest]# rmdir -v xiangjis3 
rmdir: 正在删除目录 “xiangjis3” 
[root@localhost mytest]# rmdir -v xiangjis4 
rmdir: 正在删除目录 “xiangjis4” 
[root@localhost mytest]# ll 
总用量 0 
drwxr-xr-x. 3 root root 19 7月 19 14:36 xiangjis 
[root@localhost mytest]# tree 
. 
└── xiangjis 
└── al 
└── dy 
3 directories, 0 files 
[root@localhost mytest]# rmdir -vp xiangjis/al/dy 
rmdir: 正在删除目录 “xiangjis/al/dy” 
rmdir: 正在删除目录 “xiangjis/al” 
rmdir: 正在删除目录 “xiangjis” 
[root@localhost mytest]# ll 
总用量 0
tree
概述
以树状格式列出目录的内容
常用选项
-a:显示目录的所有内容包括隐藏文件
-L:指定要显示的目录级别
-d:只显示目录
命令演示 
[root@localhost mytest]# ll 
总用量 4 
-rw-r–r–. 1 root root 45 7月 19 15:15 du 
drwxr-xr-x. 3 root root 19 7月 19 15:14 xiangjis 
drwxr-xr-x. 2 root root 6 7月 19 15:15 xiangjis1 
drwxr-xr-x. 2 root root 6 7月 19 15:15 xiangjis2 
[root@localhost mytest]# tree 
. 
├── du 
├── xiangjis 
│ └── al 
│ └── dy 
├── xiangjis1 
└── xiangjis2 
5 directories, 1 file 
[root@localhost mytest]# tree -a 
. 
├── du 
├── .grub2.cfg.swp 
├── .passwd.swo 
├── .passwd.swp 
├── xiangjis 
│ └── al 
│ └── dy 
├── xiangjis1 
└── xiangjis2 
5 directories, 4 files 
[root@localhost mytest]# tree -L 1 
. 
├── du 
├── xiangjis 
├── xiangjis1 
└── xiangjis2 
3 directories, 1 file 
[root@localhost mytest]# tree -L 2 
. 
├── du 
├── xiangjis 
│ └── al 
├── xiangjis1 
└── xiangjis2 
4 directories, 1 file 
[root@localhost mytest]# tree -L 3 
. 
├── du 
├── xiangjis 
│ └── al 
│ └── dy 
├── xiangjis1 
└── xiangjis2 
5 directories, 1 file 
[root@localhost mytest]# tree -d 
. 
├── xiangjis 
│ └── al 
│ └── dy 
├── xiangjis1 
└── xiangjis2 
5 directories
stat
概述
显示文件和文件的系统状态
语法
stat [OPTION]... FILE...
常用选项
时间戳介绍
最近访问(access time):2017-06-30 19:57:59.384031998 +0800
最近更改(modify time):2017-06-17 20:13:55.706651247 +0800
最近改动(change time):2017-06-17 20:13:56.009651263 +0800
命令演示 
此命令在单独演示,会穿插到其他的文件管理类命令中,展示命令使用
touch
概述
更改文件时间戳,不加参数,将文件时间更新到和系统时间一致
若文件不存在,系统会建立一个新的文件
在单独修改acces time或modify time的时候,change time时间会自动更新且与当前时间一致
语法
touch [OPTION]... FILE...
常用选项
-c:指定的文件不存在的时候不予创建
-a:只修改该access time
-m:只修改modify time
-t:指定touch时间
-t STAMP use [[CC]YY]MMDDhhmm[.ss] instead of current time
命令演示 
[root@localhost mytest]# touch du 
[root@localhost mytest]# ll 
总用量 0 
-rw-r–r–. 1 root root 0 7月 21 10:45 du 
drwxr-xr-x. 3 root root 19 7月 19 15:14 xiangjis 
drwxr-xr-x. 2 root root 6 7月 19 15:15 xiangjis1 
drwxr-xr-x. 2 root root 6 7月 19 15:15 xiangjis2 
[root@localhost mytest]# stat du 
文件:”du” 
大小:0 块:0 IO 块:4096 普通空文件 
设备:fd00h/64768d Inode:865184 硬链接:1 
权限:(0644/-rw-r–r–) Uid:( 0/ root) Gid:( 0/ root) 
环境:unconfined_u:object_r:user_tmp_t:s0 
最近访问:2017-07-21 10:45:39.622956106 +0800 
最近更改:2017-07-21 10:45:39.622956106 +0800 
最近改动:2017-07-21 10:45:39.622956106 +0800 
创建时间:- 
[root@localhost mytest]# date 
2017年 07月 21日 星期五 10:45:40 CST 
[root@localhost mytest]# touch -c du2 
[root@localhost mytest]# ll 
总用量 0 
-rw-r–r–. 1 root root 0 7月 21 10:45 du 
drwxr-xr-x. 3 root root 19 7月 19 15:14 xiangjis 
drwxr-xr-x. 2 root root 6 7月 19 15:15 xiangjis1 
drwxr-xr-x. 2 root root 6 7月 19 15:15 xiangjis2 
[root@localhost mytest]# stat du 
文件:”du” 
大小:0 块:0 IO 块:4096 普通空文件 
设备:fd00h/64768d Inode:865184 硬链接:1 
权限:(0644/-rw-r–r–) Uid:( 0/ root) Gid:( 0/ root) 
环境:unconfined_u:object_r:user_tmp_t:s0 
最近访问:2017-07-21 10:46:28.756680491 +0800 
最近更改:2017-07-21 10:46:28.756680491 +0800 
最近改动:2017-07-21 10:46:28.756680491 +0800 
创建时间:- 
[root@localhost mytest]# touch -a du 
[root@localhost mytest]# stat du 
文件:”du” 
大小:0 块:0 IO 块:4096 普通空文件 
设备:fd00h/64768d Inode:865184 硬链接:1 
权限:(0644/-rw-r–r–) Uid:( 0/ root) Gid:( 0/ root) 
环境:unconfined_u:object_r:user_tmp_t:s0 
最近访问:2017-07-21 10:47:32.738321575 +0800 
最近更改:2017-07-21 10:46:28.756680491 +0800 
最近改动:2017-07-21 10:47:32.738321575 +0800 
创建时间:- 
[root@localhost mytest]# date 
2017年 07月 21日 星期五 10:49:04 CST 
[root@localhost mytest]# touch -m du 
[root@localhost mytest]# stat du 
文件:”du” 
大小:0 块:0 IO 块:4096 普通空文件 
设备:fd00h/64768d Inode:865184 硬链接:1 
权限:(0644/-rw-r–r–) Uid:( 0/ root) Gid:( 0/ root) 
环境:unconfined_u:object_r:user_tmp_t:s0 
最近访问:2017-07-21 10:48:03.170150868 +0800 
最近更改:2017-07-21 10:49:10.459773392 +0800 
最近改动:2017-07-21 10:49:10.459773392 +0800 
创建时间:- 
[root@localhost mytest]# touch -t 201606201020.20 du 
[root@localhost mytest]# stat du 
文件:”du” 
大小:0 块:0 IO 块:4096 普通空文件 
设备:fd00h/64768d Inode:865184 硬链接:1 
权限:(0644/-rw-r–r–) Uid:( 0/ root) Gid:( 0/ root) 
环境:unconfined_u:object_r:user_tmp_t:s0 
最近访问:2016-06-20 10:20:20.000000000 +0800 
最近更改:2016-06-20 10:20:20.000000000 +0800 
最近改动:2017-07-21 10:50:47.179230825 +0800 
创建时间:- 
[root@localhost mytest]# touch -at 201606201020.20 du 
[root@localhost mytest]# stat du 
文件:”du” 
大小:0 块:0 IO 块:4096 普通空文件 
设备:fd00h/64768d Inode:865184 硬链接:1 
权限:(0644/-rw-r–r–) Uid:( 0/ root) Gid:( 0/ root) 
环境:unconfined_u:object_r:user_tmp_t:s0 
最近访问:2016-06-20 10:20:20.000000000 +0800 
最近更改:2017-07-21 10:51:18.172056968 +0800 
最近改动:2017-07-21 10:51:47.230893961 +0800 
创建时间:- 
[root@localhost mytest]# touch -mt 201606211020.20 du 
[root@localhost mytest]# 
[root@localhost mytest]# stat du 
文件:”du” 
大小:0 块:0 IO 块:4096 普通空文件 
设备:fd00h/64768d Inode:865184 硬链接:1 
权限:(0644/-rw-r–r–) Uid:( 0/ root) Gid:( 0/ root) 
环境:unconfined_u:object_r:user_tmp_t:s0 
最近访问:2016-06-20 10:20:20.000000000 +0800 
最近更改:2016-06-21 10:20:20.000000000 +0800 
最近改动:2017-07-21 10:52:20.761705862 +0800 
创建时间:-
cp
概述
复制源文件到目的文件
复制目录或多个源文件到目录
语法
cp [OPTION]... SOURCE... DIRECTORY
单源复制
若DEST的basename为一个文件的话, 则直接创建(若basename不存在)或覆盖basename
若DEST的basename为一个目录的话, 则先在DEST目录下创建一个与源文件同名的文件,并复制其数据流
多源复制
若source是多个文件的话, 则DEST的basename必须为已存在的目录
若source是个目录的话,需使用-r选项 则DEST的basename为目录,basename存在的话,分别复制source目录及其下每个文件至目标目录中,并保持原名; basename不存在的话,先创建basename,并复制源目录下的所有内容复制到basename目录中
常用参数
-r:递归复制目录
-i:交互式复制,即覆盖之前提醒用户确认
-f:强制覆盖目标文件
-d:复制符号连接文件本身,而非器指向的源文件
-a:-dR –preserve=all,archive,用于实现归档
命令演示 
[root@localhost mytest]# ll 
总用量 0 
-rw-r–r–. 1 root root 0 7月 21 11:06 du 
drwxr-xr-x. 3 root root 19 7月 19 15:14 xiangjis 
drwxr-xr-x. 2 root root 6 7月 19 15:15 xiangjis1 
drwxr-xr-x. 2 root root 6 7月 19 15:15 xiangjis2 
[root@localhost mytest]# 
[root@localhost mytest]# 
[root@localhost mytest]# 
[root@localhost mytest]# head -2 du 
[root@localhost mytest]# cp /etc/passwd du 
cp:是否覆盖”du”? yes 
[root@localhost mytest]# head -2 du 
root:x:0:0:root:/root:/bin/bash 
bin:x:1:1:bin:/bin:/sbin/nologin 
[root@localhost mytest]# cp /etc/issue du1 
[root@localhost mytest]# ls 
du du1 xiangjis xiangjis1 xiangjis2 
[root@localhost mytest]# head -2 du1 
\S 
Kernel \r on an \m 
[root@localhost mytest]# ls xiangjis 
alwin 
[root@localhost mytest]# cp /etc/issue xiangjis 
[root@localhost mytest]# ls xiangjis 
alwin issue 
[root@localhost mytest]# head xiangjis/issue 
\S 
Kernel \r on an \m 
[root@localhost mytest]# ls 
du du1 xiangjis xiangjis1 xiangjis2 
[root@localhost mytest]# ls xiangjis1 
[root@localhost mytest]# cp /etc/{passwd,issue} xiangjis4 
cp: 目标”xiangjis4” 不是目录 
[root@localhost mytest]# cp /etc/{passwd,issue} du 
cp: 目标”du” 不是目录 
[root@localhost mytest]# cp /etc/{passwd,issue} xiangjis2 
[root@localhost mytest]# ls xiangjis2 
issue passwd 
[root@localhost mytest]# basename xiangjis2 
xiangjis2 
[root@localhost mytest]# dirname xiangjis2 
. 
[root@localhost mytest]# basename du 
du 
[root@localhost mytest]# dirname du 
. 
[root@localhost mytest]# ls xiangjis1 
du du1 
[root@localhost mytest]# cp xiangjis1 xiangjis2 
cp: 略过目录”xiangjis1” 
[root@localhost mytest]# cp -r xiangjis1 xiangjis2 
[root@localhost mytest]# ls xiangjis2 
issue passwd xiangjis1 
[root@localhost mytest]# tree xiangjis2 
xiangjis2 
├── issue 
├── passwd 
└── xiangjis1 
├── du 
└── du1 
  
1 directory, 4 files 
[root@localhost mytest]# tree -d xiangjis2 
xiangjis2 
└── xiangjis1 
  
1 directory 
[root@localhost mytest]# ls 
du du1 xiangjis xiangjis1 xiangjis2 
[root@localhost mytest]# cp -r xiangjis1 xiangjis3 
[root@localhost mytest]# ls 
du du1 xiangjis xiangjis1 xiangjis2 xiangjis3 
[root@localhost mytest]# ls xiangjis3 
du du1 
[root@localhost mytest]# tree xiangjis3 
xiangjis3 
├── du 
└── du1 
  
0 directories, 2 files 
[root@localhost mytest]# tree -d xiangjis3 
xiangjis3 
  
0 directories 
[root@localhost mytest]# ll /etc/grub2.cfg 
lrwxrwxrwx. 1 root root 22 5月 30 06:34 /etc/grub2.cfg -> ../boot/grub2/grub.cfg 
[root@localhost mytest]# cp /etc/grub2.cfg gru 
[root@localhost mytest]# head -2 /etc/grub2.cfg 
# 
# DO NOT EDIT THIS FILE 
[root@localhost mytest]# head -2 gru 
# 
# DO NOT EDIT THIS FILE 
[root@localhost mytest]# ll 
总用量 16 
-rw-r–r–. 1 root root 2228 7月 21 11:06 du 
-rw-r–r–. 1 root root 23 7月 21 11:07 du1 
-rw-r–r–. 1 root root 4243 7月 21 11:45 gru 
drwxr-xr-x. 3 root root 32 7月 21 11:08 xiangjis 
drwxr-xr-x. 2 root root 27 7月 21 11:13 xiangjis1 
drwxr-xr-x. 3 root root 50 7月 21 11:14 xiangjis2 
drwxr-xr-x. 2 root root 27 7月 21 11:16 xiangjis3 
[root@localhost mytest]# cp -d /etc/grub2.cfg gru 
cp:是否覆盖”gru”? yes 
[root@localhost mytest]# ll 
总用量 8 
-rw-r–r–. 1 root root 2228 7月 21 11:06 du 
-rw-r–r–. 1 root root 23 7月 21 11:07 du1 
lrwxrwxrwx. 1 root root 22 7月 21 11:46 gru -> ../boot/grub2/grub.cfg 
drwxr-xr-x. 3 root root 32 7月 21 11:08 xiangjis 
drwxr-xr-x. 2 root root 27 7月 21 11:13 xiangjis1 
drwxr-xr-x. 3 root root 50 7月 21 11:14 xiangjis2 
drwxr-xr-x. 2 root root 27 7月 21 11:16 xiangjis3 
[root@localhost mytest]# cat gru 
cat: gru: 没有那个文件或目录
mv
概述
移动源文件到目的文件
移动目录或多个源文件到目录
用法和cp命令大致相同
语法
cp [OPTION]... SOURCE... DIRECTORY
常用参数
-i:交互式复制,即覆盖之前提醒用户确认
-f:强制覆盖目标文件
命令演示 
和cp命令用法大致相同,mv在移动目录时不用加-v参数。
rm
概述
删除文件或目录
默认不加任何选项,不会删除目录的
所有不用的文件建议不要直接删除,而是移动至某个专用目录(模拟回收站)
危险操作:rm -rf /*
语法
rm [OPTION]... FILE...
常用参数
-r:递归删除目录
-i:交互式
-f:强制删除
命令演示 
[root@localhost mytest]# mkdir xiangjis 
[root@localhost mytest]# mkdir -p xiangjis1/al/d 
[root@localhost mytest]# ll 
总用量 0 
drwxr-xr-x. 2 root root 6 7月 21 12:06 xiangjis 
drwxr-xr-x. 3 root root 16 7月 21 12:06 xiangjis1 
[root@localhost mytest]# rm xiangjis 
rm: 无法删除”xiangjis”: 是一个目录 
[root@localhost mytest]# rm du 
rm:是否删除普通空文件 “du”?yes 
[root@localhost mytest]# rmdir xiangjis 
[root@localhost mytest]# ls 
xiangjis1 
[root@localhost mytest]# tree xiangjis1 
xiangjis1 
└── al 
└── d 
  
2 directories, 0 files 
[root@localhost mytest]# rmdir xiangjis1 
rmdir: 删除 “xiangjis1” 失败: 目录非空 
[root@localhost mytest]# rm -r xiangjis1 
rm:是否进入目录”xiangjis1”? yes 
rm:是否进入目录”xiangjis1/al”? yes 
rm:是否删除目录 “xiangjis1/al/d”?yes 
rm:是否删除目录 “xiangjis1/al”?yes 
rm:是否删除目录 “xiangjis1”?yes 
[root@localhost mytest]# mkdir -p xiangjis2/al/d 
[root@localhost mytest]# tree 
. 
└── xiangjis2 
└── al 
└── d 
  
3 directories, 0 files 
[root@localhost mytest]# rm -rf xiangjis2 
[root@localhost mytest]# ll 
总用量 0 
[root@localhost mytest]# mkdir -p xiangjis2/al/d 
[root@localhost mytest]# rm -rf xiangjis2/* 
[root@localhost mytest]# ls 
xiangjis2 
[root@localhost mytest]# tree xiangjis2 
xiangjis2 
  
0 directories, 0 files
本文出自 “香吉视” 博客,请务必保留此出处http://xiangjis.blog.51cto.com/9430796/1952003
linux文件管理类命令汇总及演示(mkdir,rmdir,tree,touch,cp,mv,rm)
原文:http://xiangjis.blog.51cto.com/9430796/1952003