centos

sys.3.2 linux目录与文件管理命令

mkdir , rmdir ; cp , mv , rm ;

mkdir – make directories
mkdir [OPTION]… DIRECTORY…
OPTION:
-p : 自动按需创建父目录;
-v : verbose , 显示详细过程;组合使用 -pv ;
-m MODE : 直接给定权限;

rmdir – remove empty directories
rmdir [OPTION]… DIRECTORY…

OPTION:
-p : 删除某个目录后,如果其父目录为空,则一并删除;
-v : 显示过程;

cp – copy files and directories
cp [OPTION]… [-T] SOURCE DEST
cp [OPTION]… SOURCE… DIRECTORY
cp [OPTION]… -t DIRECTORY SOURCE…

OPTION:
-i : 交互式复制,覆盖之前提醒用户确认;cp 是 cp -i 的别名;
-f : 强制覆盖目标文件;
-r , -R : 递归复制目录;
-d : 复制符号链接文件本身,而非其指向的源文件;
-a : = -dR –preserv=all ; archive , 用于实现归档;
–preserv=
>>>>> mode : 权限
>>>>> ownership : 属主属组
>>>>> timestamps: 时间戳
>>>>> context : 安全上下文
>>>>> xattr : 扩展属性
>>>>> links : 符号链接
>>>>> all : 包含上述所有属性

[root@localhost ~]# ll /etc |grep system-release
lrwxrwxrwx.  1 root root     14 Dec 27 05:37 system-release -> centos-release
-rw-r--r--.  1 root root     23 Aug 30  2017 system-release-cpe
[root@localhost ~]#

cp 命令不带任何选项参数,复制符号链接文件时,复制的是符号链接文件指向的源文件;

[root@localhost ~]# cp /etc/system-release /tmp/
[root@localhost ~]# ll /tmp
total 8
drwxr-xr-x. 3 root root   30 Dec 27 06:36 kkou_2017
drwxr-xr-x. 3 root root   30 Dec 27 06:32 kkou_20171226
drwxr-xr-x. 7 root root   62 Mar 18 15:16 mysysroot
-rw-r--r--. 1 root root   38 Mar 18 21:53 system-release
drwx------. 2 root root 4096 Mar 18 21:52 vmware-root
drwxr-xr-x. 4 root root   26 Mar 18 15:05 x
[root@localhost ~]# more /tmp/system-release 
CentOS Linux release 7.4.1708 (Core) 
[root@localhost ~]# 
[root@localhost ~]# cp /etc/system-release /tmp/abcd
[root@localhost ~]# more /tmp/abcd
CentOS Linux release 7.4.1708 (Core) 
[root@localhost ~]#

cp 命令带选项 -d ,复制符号链接文件时,复制的是符号链接文件本身,而非其指向的源文件;

[root@localhost ~]# 
[root@localhost ~]# cp -d /etc/system-release /tmp/aaa 
[root@localhost ~]# ll /tmp
total 12
lrwxrwxrwx. 1 root root   14 Mar 18 21:54 aaa -> centos-release
-rw-r--r--. 1 root root   38 Mar 18 21:54 abcd
drwxr-xr-x. 3 root root   30 Dec 27 06:36 kkou_2017
drwxr-xr-x. 3 root root   30 Dec 27 06:32 kkou_20171226
drwxr-xr-x. 7 root root   62 Mar 18 15:16 mysysroot
-rw-r--r--. 1 root root   38 Mar 18 21:53 system-release
drwx------. 2 root root 4096 Mar 18 21:52 vmware-root
drwxr-xr-x. 4 root root   26 Mar 18 15:05 x
[root@localhost ~]# more /tmp/aaa
/tmp/aaa: No such file or directory
[root@localhost ~]#

mv – move (rename) files
mv [OPTION]… [-T] SOURCE DEST
mv [OPTION]… SOURCE… DIRECTORY
mv [OPTION]… -t DIRECTORY SOURCE…

rm – remove files or directories
rm [OPTION]… FILE…

OPTION:
-r, -R, –recursive : remove directories and their contents recursively
-f, –force : ignore nonexistent files and arguments, never prompt

∪∂∀∃∅∇åΣêēÙ

centos 7 系统:

[root@localhost ~]# rm -rf /
rm: it is dangerous to operate recursively on ‘/’
rm: use --no-preserve-root to override this failsafe
[root@localhost ~]#

 

Leave a Reply

Your email address will not be published. Required fields are marked *