文章目录
一、CentOS的由来
CentOS全称为(Community Enterprise Operating System),中文意思是社区企业操作系统;它是基于Red Hat Enterprise Linux (RHEL)的源代码构建的,因此与RHEL在功能上几乎相同。
二、CentOS的优点和缺点
优点 | |
---|---|
免费与开源 | CentOS是基于Linux的,因此它是免费且开源的。用户可以随时获取其源代码,并根据需求进行定制,这对于程序开发人员尤其重要。 |
跨平台硬件支持 | CentOS支持广泛的硬件平台,这使得它能在多种不同的物理或虚拟环境中运行。 |
系统稳定 | CentOS的稳定性是其主要优势之一,它基于Red Hat Enterprise Linux (RHEL)的源代码构建,因此继承了RHEL的稳定性和可靠性。 |
企业级部署 | 许多公司选择使用CentOS来代替商业版的Red Hat Linux,因为它提供了企业级的服务和支持。 |
社区支持 | CentOS拥有一个活跃的社区,用户可以从社区中获得帮助和支持。 |
兼容性良好 | CentOS与RHEL的兼容性良好,这为企业级部署提供了便利。 |
新特性和改进 | CentOS 8引入了许多新特性和改进,如更快的更新、更好的安全性和应用支持,以及更好的图形界面和工具。 |
缺点 | |
更新速度 | CentOS的软件包更新速度相对较慢,可能不满足某些应用程序对最新软件版本的需求。 |
硬件和软件支持 | CentOS可能不支持最新的硬件型号和应用程序版本,这可能会限制在一些先进硬件上的应用。 |
发展方向 | 自从Red Hat宣布停止支持CentOS后,CentOS的未来发展方向变得不太明确,这可能会影响用户对其长期使用的信心。 |
三、基础操作命令
1、文件和目录操作
(1.)cd - 切换目录
cd命令用于改变当前目录路径,如windows一样,只不过是鼠标变成了命令
# 使用cd /可以进入系统的根目录
[root@localhost ~]# cd /
[root@localhost /]#
# cd后不加任何参数,将用户带回主目录(这里通常对应于/home/用户名的路径)
[root@localhost /]# cd
[root@localhost ~]#
# 相对路径(目标目录位于当前工作目录下,可以直接使用cd 目录名来进入)
[root@localhost ~]# cd /bin
[root@localhost bin]#
# 绝对路径(指定完整的目录路径来切换到目标目录,不论当前位置在哪里)
[root@localhost /]# cd /usr/bin/
[root@localhost bin]#
# 使用..表示上级目录,连续使用多个..可以回到更高级的目录
[root@localhost bin]# cd ../../
[root@localhost /]#
# 使用~符号可以快速切换到当前用户的主目录
[root@localhost /]# cd ~
[root@localhost ~]#
(2.)ls - 列出目录内容
列出目录内容,可以使用多种参数来定制输出
# 显示当前所在路径下的所有目录及文件
[root@httpsl /]# ls
bin dev home lib64 media opt root sbin sys usr
boot etc lib lost+found mnt proc run srv tmp var
[root@httpsl /]#
# 显示所有文件及目录,包括以点(.)开头的隐藏文件
[root@httpsl /]# ls -a
. .autorelabel boot etc lib lost+found mnt proc run srv tmp var
.. bin dev home lib64 media opt root sbin sys usr
[root@httpsl /]#
# 以长格式显示文件和目录信息,包括权限、所有者、大小、创建时间等
[root@httpsl network-scripts]# ls -l
total 232
-rw-r--r-- 1 root root 338 Mar 25 12:30 ifcfg-eth0
-rw-r--r--. 1 root root 254 Aug 19 2019 ifcfg-lo
lrwxrwxrwx. 1 root root 24 Sep 14 2020 ifdown -> ../../../usr/sbin/ifdown
-rwxr-xr-x. 1 root root 654 Aug 19 2019 ifdown-bnep
-rwxr-xr-x. 1 root root 6532 Aug 19 2019 ifdown-eth
[root@httpsl network-scripts]#
# 倒序显示文件和目录,即最新的文件或目录将显示在最前面
[root@httpsl network-scripts]# ls -r
network-functions-ipv6 ifup-sit ifup-ipv6 ifdown-TeamPort ifdown-ipv6
network-functions ifup-routes ifup-ippp ifdown-Team ifdown-ippp
init.ipv6-global ifup-ppp ifup-eth ifdown-sit ifdown-eth
ifup-wireless ifup-post ifup-bnep ifdown-routes ifdown-bnep
ifup-tunnel ifup-plusb ifup-aliases ifdown-ppp ifdown
ifup-TeamPort ifup-plip ifup ifdown-post ifcfg-lo
ifup-Team ifup-isdn ifdown-tunnel ifdown-isdn ifcfg-eth0
[root@httpsl network-scripts]#
# 按修改时间排序,最新的文件在最前面
[root@httpsl /]# ls -t
sys root run proc usr lib bin var media opt
tmp dev etc boot sbin lib64 lost+found home mnt srv
[root@httpsl /]#
# 以长格式列出所有文件,包括隐藏文件,并在文件名后添加类型标识符
[root@httpsl ~]# ls -alF
total 48
dr-xr-x---. 5 root root 4096 Mar 25 12:32 ./
dr-xr-xr-x. 18 root root 4096 Mar 25 12:30 ../
-rw------- 1 root root 768 Mar 25 21:31 .bash_history
-rw-r--r--. 1 root root 18 Dec 29 2013 .bash_logout
-rw-r--r--. 1 root root 176 Dec 29 2013 .bash_profile
-rw-r--r--. 1 root root 176 Dec 29 2013 .bashrc
drwx------ 3 root root 4096 Sep 14 2020 .cache/
-rw-r--r--. 1 root root 100 Dec 29 2013 .cshrc
drwxr-xr-x 2 root root 4096 Nov 30 2021 .pip/
-rw-r--r-- 1 root root 206 Mar 25 12:30 .pydistutils.cfg
drwx------ 2 root root 4096 Sep 14 2020 .ssh/
-rw-r--r--. 1 root root 129 Dec 29 2013 .tcshrc
[root@httpsl ~]#
(3.)pwd - 显示当前目录
pwd命令用于显示当前工作目录的完整路径
# 显示当前所在目录的绝对路径
[root@httpsl network-scripts]# pwd
/etc/sysconfig/network-scripts
# 显示出物理路径,即实际的路径,而不是符号链接指向的路径
[root@httpsl network-scripts]# pwd -P
/etc/sysconfig/network-scripts
# 显示逻辑路径;当有符号链接时,会直接显示链接文件的路径,而不是链接所指向的文件或目录的实际路径
[root@httpsl network-scripts]# pwd -L
/etc/sysconfig/network-scripts
(4.)mkdir - 创建目录
mkdir命令用于创建目录,其参数可以指定不同的操作行为
# 创建单一目录
[root@httpsl opt]# mkdir test
[root@httpsl opt]# ls
test
[root@httpsl opt]#
# 递归创建目录,在一个目录内创建另一个目录,套娃模式
[root@httpsl /]# mkdir -p a/b/c
[root@httpsl /]# ls
a boot etc lib lost+found mnt proc run srv tmp var
bin dev home lib64 media opt root sbin sys usr
[root@httpsl /]# cd /a/b/c/
[root@httpsl c]# pwd
/a/b/c
[root@httpsl c]#
# 创建目录返回创建结果,创建有反馈
[root@httpsl a]# mkdir -v c
mkdir: created directory ‘c’
[root@httpsl a]# ls
b c
[root@httpsl a]#
# 创建目录时自定义权限
[root@httpsl a]# mkdir -m 555 d
[root@httpsl a]# ls -l
total 12
drwxr-xr-x 3 root root 4096 Mar 25 21:51 b
drwxr-xr-x 2 root root 4096 Mar 25 21:56 c
dr-xr-xr-x 2 root root 4096 Mar 25 22:00 d
[root@httpsl a]#
(5.)rmdir - 删除空目录
rmdir命令用于删除空目录,其常用参数包括-p和-v
# 删除一个目录
[root@httpsl a]# rmdir d
[root@httpsl a]# ls
b c
[root@httpsl a]#
# 删除目录时有反馈
[root@httpsl a]# rmdir -v c
rmdir: removing directory, ‘c’
[root@httpsl a]# ls
b
[root@httpsl a]#
# 递归删除目录
[root@httpsl /]# ls
a boot etc lib lost+found mnt proc run srv tmp var
bin dev home lib64 media opt root sbin sys usr
[root@httpsl /]# rmdir -p a/b/c/
[root@httpsl /]# ls
bin dev home lib64 media opt root sbin sys usr
boot etc lib lost+found mnt proc run srv tmp var
[root@httpsl /]#
(6.)touch - 创建文件
touch命令是一个用于更新文件时间戳的实用工具,也可以用来创建新的空文件或设置特定的时间戳
# 创建一个文件
[root@httpsl test]# touch test
[root@httpsl test]# ls
test
[root@httpsl test]#
# 更新文件的访问时间(atime)
[root@httpsl test]# touch -a test
[root@httpsl test]# ls -lu
total 0
-rw-r--r-- 1 root root 0 Mar 25 22:10 test
[root@httpsl test]#
# 更新文件的修改时间(mtime)
[root@httpsl test]# touch -m test
[root@httpsl test]# ls -ll
total 0
-rw-r--r-- 1 root root 0 Mar 25 22:11 test
[root@httpsl test]#
# 将已有的文件更改到指定的时间戳(修改文件和访问时间同时修改)
[root@httpsl test]# touch -d "2023-01-01 12:00" test
[root@httpsl test]# stat test
File: ‘test’
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd01h/64769d Inode: 1441794 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2023-01-01 12:00:00.000000000 +0800
Modify: 2023-01-01 12:00:00.000000000 +0800
Change: 2024-03-25 22:15:24.244612743 +0800
Birth: -
[root@httpsl test]#
# 创建一个文件,并指定时间戳(修改文件和访问时间同时修改)
[root@httpsl test]# touch -d "2023-01-01 12:00" test1.txt
[root@httpsl test]# stat test
File: ‘test’
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd01h/64769d Inode: 1441794 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2023-01-01 12:00:00.000000000 +0800
Modify: 2023-01-01 12:00:00.000000000 +0800
Change: 2024-03-25 22:15:24.244612743 +0800
Birth: -
[root@httpsl test]#
(7.)cp - 复制文件或目录
Linux中的cp命令用于复制文件或目录,其参数可以指定不同的复制行为
# -a在复制目录时经常使用,它会保留链接、文件属性,并复制目录下的所有内容
[root@httpsl test]# cp -a test kong/
[root@httpsl test]# ls
kong test test1.txt
[root@httpsl test]# ll kong/test
-rw-r--r-- 1 root root 0 Jan 1 2023 kong/test
[root@httpsl test]#
# 目录与文件同时复制
[root@httpsl test]# cp -r he/ kong/
[root@httpsl test]# ls
he kong test test1.txt
[root@httpsl test]# ll kong/
he/ he.txt test
[root@httpsl test]# ll kong/he
he/ he.txt
[root@httpsl test]# ll kong/he/he.txt
-rw-r--r-- 1 root root 0 Mar 25 22:26 kong/he/he.txt
[root@httpsl test]#
# 如果目标目录中存在该文件,则提醒是否要覆盖该文件
[root@httpsl test]# cp -ri he/ kong/
cp: overwrite ‘kong/he/he.txt’?
# 仅复制源文件中更新时间较新的文件
[root@httpsl test]# cp -u he/he.txt kong/
[root@httpsl test]# ll kong/
total 4
drwxr-xr-x 2 root root 4096 Mar 25 22:26 he
-rw-r--r-- 1 root root 0 Mar 25 22:25 he.txt
-rw-r--r-- 1 root root 0 Jan 1 2023 test
[root@httpsl test]#
# 显示复制过程
[root@httpsl test]# cp -v he/he.txt kong/
cp: overwrite ‘kong/he.txt’? y
‘he/he.txt’ -> ‘kong/he.txt’
[root@httpsl test]# ll kong/
total 4
drwxr-xr-x 2 root root 4096 Mar 25 22:26 he
-rw-r--r-- 1 root root 0 Mar 25 22:30 he.txt
-rw-r--r-- 1 root root 0 Jan 1 2023 test
[root@httpsl test]#
# 保留源文件的权限、所有者和时间戳信息
[root@httpsl test]# cp -p he/he.txt kong/
cp: overwrite ‘kong/he.txt’? y
[root@httpsl test]# ll kong/
total 4
drwxr-xr-x 2 root root 4096 Mar 25 22:26 he
-rw-r--r-- 1 root root 0 Mar 25 22:25 he.txt
-rw-r--r-- 1 root root 0 Jan 1 2023 test
[root@httpsl test]#
# (这里没有显示出来硬链接的浅蓝色标识)
# 只生成链接文件
[root@httpsl test]# cp -l he/he.txt nan
[root@httpsl test]# ll nan
total 0
-rw-r--r-- 2 root root 0 Mar 25 22:25 he.txt
[root@httpsl test]#
(8.)mv - 移动文件或目录
mv命令在Linux系统中非常常用,主要用于移动或重命名文件和目录
# 在覆盖目标文件或目录前,在不确定是否需要覆盖时先为其创建一个备份
[root@httpsl test]# touch test
[root@httpsl test]# ll kong/
total 4
drwxr-xr-x 2 root root 4096 Mar 25 22:26 he
-rw-r--r-- 1 root root 0 Mar 25 22:32 he.txt
-rw-r--r-- 1 root root 0 Jan 1 2023 test
-rw-r--r-- 1 root root 0 Mar 25 22:33 test.txt
[root@httpsl test]# mv -b test kong/
mv: overwrite ‘kong/test’? y
[root@httpsl test]# ll kong/
total 4
drwxr-xr-x 2 root root 4096 Mar 25 22:26 he
-rw-r--r-- 1 root root 0 Mar 25 22:32 he.txt
-rw-r--r-- 1 root root 0 Mar 25 22:47 test
-rw-r--r-- 1 root root 0 Jan 1 2023 test~
-rw-r--r-- 1 root root 0 Mar 25 22:33 test.txt
[root@httpsl test]#
# 强制移动或重命名文件。如果目标位置已存在同名文件或目录,使用此参数会直接覆盖,而不会提示用户确认
[root@httpsl test]# ls
he kong nan test1.txt
[root@httpsl test]# ls kong/
he he.txt test test~ test.txt
[root@httpsl test]# touch test
[root@httpsl test]# ls
he kong nan test test1.txt
[root@httpsl test]# mv -f test kong/
[root@httpsl test]# ls kong/
he he.txt test test~ test.txt
[root@httpsl test]#
# 在目标文件已存在时,会提示用户是否覆盖
[root@httpsl test]# touch test
[root@httpsl test]# mv -i test kong/
mv: overwrite ‘kong/test’? y
[root@httpsl test]# ls kong/
he he.txt test test~ test.txt
[root@httpsl test]#
(9.)rm - 删除文件或目录
rm命令用于删除文件和目录
# -i会让rm在删除前逐一询问用户确认,这样可以避免意外删除文件
[root@httpsl test]# ls
he kong nan test1.txt
[root@httpsl test]# rm -i test1.txt
rm: remove regular empty file ‘test1.txt’? y
[root@httpsl test]# ls
he kong nan
[root@httpsl test]#
# 一般用于强制删除
[root@httpsl nan]# ls
he.txt
[root@httpsl nan]# rm -f he.txt
[root@httpsl nan]# ls
[root@httpsl nan]#
# 递归删除目录以及目录下的文件,会让用户确认一遍
[root@httpsl test]# ls he/
1.txt he.txt
[root@httpsl test]# rm -r he
rm: descend into directory ‘he’? y
rm: remove regular empty file ‘he/1.txt’? y
rm: remove regular empty file ‘he/he.txt’? y
rm: remove directory ‘he’? y
[root@httpsl test]# ls
kong nan
[root@httpsl test]#
# 详细显示删除的步骤
[root@httpsl test]# ls kong/he
he.txt
[root@httpsl test]# rm -v kong/he/he.txt
rm: remove regular empty file ‘kong/he/he.txt’? y
removed ‘kong/he/he.txt’
[root@httpsl test]#
(10.)cat - 查看文件内容
cat命令是一个非常实用的工具,它不仅可以用于查看文件内容,还可以用于创建文件、连接文件以及重定向输出等操作
# -n会从1开始对所有输出的行进行编号,常用于显示文件内容时,方便查看行数
[root@httpsl network-scripts]# cat -n ifcfg-eth0
1 # Created by cloud-init on instance boot automatically, do not edit.
2 # If you don't want cloud-init genrated automatically,you can disable it in /etc/cloud/cloud.cfg
3 # For more information, please refer to: https://help.aliyun.com/document_detail/57803.html
4 #
5 BOOTPROTO=dhcp
6 DEVICE=eth0
7 ONBOOT=yes
8 STARTMODE=auto
9 TYPE=Ethernet
10 USERCTL=no
[root@httpsl network-scripts]#
# 与-n一样,但是不会对空行进行编号
[root@httpsl network-scripts]# cat -b ifcfg-eth0
1 # Created by cloud-init on instance boot automatically, do not edit.
2 # If you don't want cloud-init genrated automatically,you can disable it in /etc/cloud/cloud.cfg
3 # For more information, please refer to: https://help.aliyun.com/document_detail/57803.html
4 #
5 BOOTPROTO=dhcp
6 DEVICE=eth0
7 ONBOOT=yes
8 STARTMODE=auto
9 TYPE=Ethernet
10 USERCTL=no
[root@httpsl network-scripts]#
# 当遇到连续两行以上的空白行时,只输出一行空白行,这样可以压缩多余的空白行
[root@httpsl network-scripts]# cat test.txt
1 # Created by cloud-init on instance boot automatically, do not edit.
2 # If you don't want cloud-init genrated automatically,you can disable it in /etc/cloud/cloud.cfg
3 # For more information, please refer to: https://help.aliyun.com/document_detail/57803.html
4 #
5 BOOTPROTO=dhcp
6 DEVICE=eth0
7 ONBOOT=yes
8 STARTMODE=auto
9 TYPE=Ethernet
10 USERCTL=no
[root@httpsl network-scripts]# cat -s test.txt
1 # Created by cloud-init on instance boot automatically, do not edit.
2 # If you don't want cloud-init genrated automatically,you can disable it in /etc/cloud/cloud.cfg
3 # For more information, please refer to: https://help.aliyun.com/document_detail/57803.html
4 #
5 BOOTPROTO=dhcp
6 DEVICE=eth0
7 ONBOOT=yes
8 STARTMODE=auto
9 TYPE=Ethernet
10 USERCTL=no
[root@httpsl network-scripts]#
# 使用^和M-符号显示文件中的不可打印字符,除了LFD和TAB之外
[root@httpsl network-scripts]# cat -v test.txt
1 # Created by cloud-init on instance boot automatically, do not edit.
2 # If you don't want cloud-init genrated automatically,you can disable it in /etc/cloud/cloud.cfg
3 # For more information, please refer to: https://help.aliyun.com/document_detail/57803.html
4 #
5 BOOTPROTO=dhcp
6 DEVICE=eth0
7 ONBOOT=yes
8 STARTMODE=auto
9 TYPE=Ethernet
10 USERCTL=no
[root@httpsl network-scripts]#
# 在每行结束处显示$符号,以显示行尾
[root@httpsl network-scripts]# cat -e ifcfg-eth0
# Created by cloud-init on instance boot automatically, do not edit.$
# If you don't want cloud-init genrated automatically,you can disable it in /etc/cloud/cloud.cfg$
# For more information, please refer to: https://help.aliyun.com/document_detail/57803.html$
#$
BOOTPROTO=dhcp$
DEVICE=eth0$
ONBOOT=yes$
STARTMODE=auto$
TYPE=Ethernet$
USERCTL=no$
[root@httpsl network-scripts]#
# 将TAB字符显示为^I,以便更清楚地看到文本中的制表符
[root@httpsl network-scripts]# cat -t ifcfg-eth0
# Created by cloud-init on instance boot automatically, do not edit.
# If you don't want cloud-init genrated automatically,you can disable it in /etc/cloud/cloud.cfg
# For more information, please refer to: https://help.aliyun.com/document_detail/57803.html
#
BOOTPROTO=dhcp
DEVICE=eth0
ONBOOT=yes
STARTMODE=auto
TYPE=Ethernet
USERCTL=no
[root@httpsl network-scripts]#
(11.)stat - 显示文件或目录的详细信息
stat命令是一个非常强大的工具,它能够提供比ls命令更详细的文件状态信息,包括文件的访问时间、修改时间、状态改变时间、设备号、Inode号等
# stat跟随符号链接,显示链接所指向文件的信息
[root@httpsl /]# stat -L /sbin/
File: ‘/sbin/’
Size: 12288 Blocks: 24 IO Block: 4096 directory
Device: fd01h/64769d Inode: 655368 Links: 2
Access: (0555/dr-xr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2024-03-25 12:31:32.547487172 +0800
Modify: 2024-03-25 12:30:54.155090531 +0800
Change: 2024-03-25 12:30:54.155090531 +0800
Birth: -
# 显示文件所在文件系统的信息,而不是文件本身的信息
[root@httpsl /]# stat -f /sbin/
File: "/sbin/"
ID: 703fa81c59373c13 Namelen: 255 Type: ext2/ext3
Block size: 4096 Fundamental block size: 4096
Blocks: Total: 10288203 Free: 9764230 Available: 9288303
Inodes: Total: 2621440 Free: 2560795
# stat以简洁的方式输出信息,只显示摘要信息
[root@httpsl /]# stat -t /sbin/
/sbin/ 12288 24 416d 0 0 fd01 655368 2 0 0 1711341092 1711341054 1711341054 0 4096
(12.)file - 确定文件类型
使用file命令时,你可以根据需要选择适当的参数来获取你想要的信息
# 在输出结果时不显示文件名,仅显示文件类型描述
[root@httpsl bin]# file -b bash
ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=85e3da5a087950e7aaeb7893c056218a8874d2e5, stripped
[root@httpsl bin]#
# 显示指令执行的详细过程
[root@httpsl network-scripts]# file -c ifcfg-eth0
cont offset type opcode mask value desc
# 显示file的版本信息
[root@httpsl network-scripts]# file -v
file-5.11
magic file from /etc/magic:/usr/share/misc/magic
# 后面跟名称文件,可以指定一个包含多个文件名的文本文件,file命令会依次识别这些文件
[root@httpsl test]# file -f 1.txt
/etc/passwd: ASCII text
/etc/shadow: ASCII text
/etc/group: ASCII text
/etc/fstab: ASCII text
[root@httpsl test]# cat 1.txt
/etc/passwd
/etc/shadow
/etc/group
/etc/fstab
[root@httpsl test]#
# 查看符号链接指向的文件类型
[root@httpsl /]# file -L /test/1.txt
/test/1.txt: ASCII text
[root@httpsl /]#
2、命令参数总结
命令 | 参数 | 注释 |
---|---|---|
cd | cd / | 使用cd /可以进入系统的根目录 |
cd | cd后不加任何参数,将用户带回主目录(这里通常对应于/home/用户名的路径) | |
cd /目录 | 相对路径(目标目录位于当前工作目录下,可以直接使用cd 目录名来进入) | |
cd /目录/目录 | 绝对路径(指定完整的目录路径来切换到目标目录,不论当前位置在哪里) | |
cd …/…/ | 使用…表示上级目录,连续使用多个…可以回到更高级的目录 | |
cd ~ | 使用~符号可以快速切换到当前用户的主目录 | |
ls | ls -a | 显示所有文件及目录,包括以点(.)开头的隐藏文件 |
ls -l | 以长格式显示文件和目录信息,包括权限、所有者、大小、创建时间等 | |
ls -r | 倒序显示文件和目录,即最新的文件或目录将显示在最前面 | |
ls -t | 按修改时间排序,最新的文件在最前面 | |
ls -alF | 以长格式列出所有文件,包括隐藏文件,并在文件名后添加类型标识符 | |
pwd | pwd -p | 显示当前所在目录的绝对路径 |
pwd -L | 显示逻辑路径;当有符号链接时,会直接显示链接文件的路径,而不是链接所指向的文件或目录的实际路径 | |
mkdir | mkdir -p | 递归创建目录,在一个目录内创建另一个目录,套娃模式 |
mkdir -v | 创建目录返回创建结果,创建有反馈 | |
mkdir -m | 创建目录时自定义权限 | |
rmdir | rmdir -v | 删除目录时有反馈 |
rmdir -p | 递归删除目录 | |
touch | touch -a | 更新文件的访问时间(atime) |
touch -m | 更新文件的修改时间(mtime) | |
touch -d | 将已有的文件更改到指定的时间戳(修改文件和访问时间同时修改) | |
touch -d | 创建一个文件,并指定时间戳(修改文件和访问时间同时修改) | |
cp | cp -a | -a在复制目录时经常使用,它会保留链接、文件属性,并复制目录下的所有内容 |
cp -r | 目录与文件同时复制 | |
cp -ri | 如果目标目录中存在该文件,则提醒是否要覆盖该文件 | |
cp -u | 仅复制源文件中更新时间较新的文件 | |
cp -v | 显示复制过程 | |
cp -p | 保留源文件的权限、所有者和时间戳信息 | |
cp -l | 只生成链接文件 | |
mv | mv -b | 在覆盖目标文件或目录前,在不确定是否需要覆盖时先为其创建一个备份 |
mv -f | 强制移动或重命名文件。如果目标位置已存在同名文件或目录,使用此参数会直接覆盖,而不会提示用户确认 | |
mv -i | 在目标文件已存在时,会提示用户是否覆盖 | |
rm | rm -i | -i会让rm在删除前逐一询问用户确认,这样可以避免意外删除文件 |
rm -f | 一般用于强制删除 | |
rm -r | 递归删除目录以及目录下的文件,会让用户确认一遍 | |
rm -v | 详细显示删除的步骤 | |
cat | cat -n | -n会从1开始对所有输出的行进行编号,常用于显示文件内容时,方便查看行数 |
cat -b | 与-n一样,但是不会对空行进行编号 | |
cat -s | 当遇到连续两行以上的空白行时,只输出一行空白行,这样可以压缩多余的空白行 | |
cat -v | 使用^和M-符号显示文件中的不可打印字符,除了LFD和TAB之外 | |
cat -e | 在每行结束处显示$符号,以显示行尾 | |
cat -t | 将TAB字符显示为^I,以便更清楚地看到文本中的制表符 | |
stat | stat -L | stat跟随符号链接,显示链接所指向文件的信息 |
stat -f | 显示文件所在文件系统的信息,而不是文件本身的信息 | |
stat -t | stat以简洁的方式输出信息,只显示摘要信息 | |
file | file -b | 在输出结果时不显示文件名,仅显示文件类型描述 |
file -c | 显示指令执行的详细过程 | |
file -v | 显示file的版本信息 | |
file -f | 后面跟名称文件,可以指定一个包含多个文件名的文本文件,file命令会依次识别这些文件 | |
file -L | 查看符号链接指向的文件类型 |