社区微信群开通啦,扫一扫抢先加入社区官方微信群
社区微信群
目录
ln
命令建立的文件[root@localhost log]#basename /etc/sysconfig/network-scripts/ifcfg-ens33
ifcfg-ens33
[root@localhost log]#basename /etc/sysconfig/network-scripts
network-scripts
[root@localhost log]#dirname /etc/sysconfig/network-scripts
/etc/sysconfig
[root@localhost log]#dirname /etc/sysconfig/network-scripts/ifcfg-ens33
/etc/sysconfig/network-scripts
cd 切换目录 change directory
[root@localhost log]#cd
[root@localhost ~]#
[root@localhost ~]#cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]#cd -
/root
[root@localhost ~]#cd -
/etc/sysconfig/network-scripts
pwd print working directory
[root@localhost network-scripts]#pwd
/etc/sysconfig/network-scripts
# 查看链接的真正目录
[root@localhost /]#cd lib
[root@localhost lib]#pwd -P
/usr/lib
ls list
命令格式:Usage: ls [OPTION]... [FILE]...
ls -a 显示所有文件
[root@root ~]# ls -a
. .cshrc file15 file3 .passwd.swo
.. file1 file16 file4 .tcshrc
anaconda-ks.cfg file10 file17 file5 teaching_plan.zip
ls -l 以长格式显示文件列表
[root@root ~]# ls -l
total 8
-rw-------. 1 root root 1414 Aug 22 2019 anaconda-ks.cfg
-rw-r--r--. 1 root root 0 Mar 1 18:28 file1
-rw-r--r--. 1 root root 0 Aug 22 17:21 10
权限 硬盘的引用次数 属主 属组 大小 访问时间 文件名称
ls -R 递归显示目录
[root@root ~]# ls -R
.:
anaconda-ks.cfg file12 file16 file2 file5 file9
file1 file13 file17 file20 file6 teaching_plan.zip
ls -d 显示目录本身
[root@root ~]# ls -d
.
ls -1(数字1) 文件分行显示
[root@root ~]# ls -1
anaconda-ks.cfg
file1
file10
file11
file12
ls -S 安装文件大小排序
[root@root ~]# ls -S
teaching_plan.zip file11 file15 file19 file4 file8
ls -r 倒序显示
[root@root ~]# ls -r
teaching_plan.zip file6 file20 file17 file13 file1
ls -t 按照时间来排序
[root@root ~]# ls -t
file18 file11 file15 file3 file7 teaching_plan.zip
ls -lh 显示人类易读的方式
[root@root ~]# ls -1h
anaconda-ks.cfg
file1
file10
file11
file12
file13
ls -d */ 显示当前目录下的文件夹
l. 只显示隐藏文件
#修改文件创建时间
[root@root ~]# touch -c -m -t 201301211925 b19
[root@root ~]# ll b19
-rw-r--r--. 1 root root 0 Jan 21 2013 b19
#ls -l 等同于 ll
[root@root ~]# ls -l b19
-rw-r--r--. 1 root root 0 Jan 21 2013 b19
[root@root ~]# ll b19
-rw-r--r--. 1 root root 0 Jan 21 2013 b19
File: ‘anaconda-ks.cfg’
Size: 1747 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 33574992 Links: 1
Access: (0600/-rw-------) Uid: ( 0/ root) Gid: ( 0/ root)
Context: system_u:object_r:admin_home_t:s0
Access: 2019-08-22 12:09:03.288000381 +0900 # 访问时间
Modify: 2019-08-22 11:47:12.262947345 +0900 # 修改时间
Change: 2019-08-22 11:47:12.262947345 +0900 # 改动时间
atime 访问时间 查看文件内容就会改变
mtime 修改时间 改变内容发生变化
ctime 改动时间 元数据发生变化
创建空文件和刷新时间,如果文件存在,则刷新时间,如果文件不存在,则创建文件
-a 只修改atime和ctime
-m 只修改mtime和ctime
mkdir 创建目录
安装:yum install -y tree
tree 显示目录树
[root@root ~]# tree
.
├── anaconda-ks.cfg
├── file1
├── file10
├── file11
├── file12
├── file13
├── file14
├── file15
├── file16
├── file17
├── file18
├── file19
├── file2
├── file20
├── file3
├── file4
├── file5
├── file6
├── file7
├── file8
├── file9
└── teaching_plan.zip
0 directories, 22 files
-d 只显示文件夹
[root@root ~]# tree -d
.
0 directories
-L # 只显示#层
[root@root ~]# tree -L 1
.
├── anaconda-ks.cfg
├── file1
├── file10
├── file11
├── file12
├── file13
├── file14
├── file15
├── file16
├── file17
├── file18
├── file19
├── file2
├── file20
├── file3
├── file4
├── file5
├── file6
├── file7
├── file8
├── file9
└── teaching_plan.zip
0 directories, 22 files
rmdir 只能删除非空目录
-p 递归删除空父目录
-v 显示删除过程
rm -rf 删除非空目录
cp copy 默认情况下是别名,原来本身命令是不提示覆盖的
Usage: cp [OPTION]... [-T] SOURCE DEST
or: cp [OPTION]... SOURCE... DIRECTORY
or: cp [OPTION]... -t DIRECTORY SOURCE...
-i 显示提示信息
-n 不覆盖
-r -R 递归复制
-d 只复制链接文件,不复制源文件
-a 归档
-v 显示过程
-b 备份原来的文件
--backup=number 备份文件加上数字
-p 保留原来的属性
mv move
Usage: mv [OPTION]... [-T] SOURCE DEST
or: mv [OPTION]... SOURCE... DIRECTORY
or: mv [OPTION]... -t DIRECTORY SOURCE...
-i 提示
-f 强制
-b 备份
--backup=number 备份后面加数字
-v 显示过程
#文件重命名示例
[root@root ~]# ls
b111111
[root@root ~]# mv b111111 bbb233
[root@root ~]# ls
bbb233
rm remove
Usage: rm [OPTION]... FILE...
-i 提示
-r -R 递归删除
-f 强制删除
rm -rf 慎用
rm -rf /*
cd /
rm -rf *
删除文件
[root@localhost bighome]# rm install.log
删除文件夹
[root@localhost ~]# rm -r b
-f 省略确认步骤
[root@localhost ~]# rm -rf b
删除文件里面的内容
[root@localhost ~]# > filename
[root@localhost ~]# > filename
[root@localhost ~]# echo “” > filename
[root@localhost ~]# echo > filename
[root@localhost ~]# cat /dev/null > filename
源文件删除,软链接不能访问
源文件删除以后,硬链接可以访问
file
> 覆盖
禁止、允许覆盖
>> 追加
>> 将标准输出追加到文件中
2>> 将错误输出追加到文件中
&>> 将所有输出追加到文件中
[root@localhost ~]#ls f 45yuio > log.log 2> error.log
[root@localhost ~]#cat log.log
f
[root@localhost ~]#cat error.log
ls: cannot access 45yuio: No such file or directory
tr 字符替换
-t 截断
-d 删除
-s 压缩,去重
-c 取反
[root@localhost ~]#tr 'a-z' 'A-Z' < /etc/issue
S
KERNEL R ON AN M
[root@localhost ~]#tr 'a-z' 'A-Z'
qwertyy
QWERTYY
12345678
12345678
ASDFGHJ
ASDFGHJ
qwertyuio
QWERTYUIO
^C
[root@localhost ~]#tr ab 12
ab
12
abb
122
asdfghjkl
1sdfghjkl
^C
[root@localhost ~]#tr abc 12
ab
12
abc
122
abc
122
^C
[root@localhost ~]#tr ab 123
ab
12
abb
122
avc
1vc
qbc
q2c
abc
12c
[root@localhost ~]#tr -t abc 12
abc
12c
ab
12
[root@localhost ~]#tr -d abc
qwertyui
qwertyui
an^H^H
n
abc
artyibrtyuiocrtyuiop
rtyirtyuiortyuiop
^C
[root@localhost ~]#tr -d abc < /etc/issue
S
Kernel r on n m
[root@localhost ~]#cat /etc/issue
S
Kernel r on an m
[root@localhost ~]#tr -s a
abc
abc
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabc
abc
^C
[root@localhost ~]#tr -sc a
aasdaaaaaaa
aasdaaaaaaa
^[[A^H^H^C
[root@localhost ~]#tr -sc a
aaaaaaaaabbbbbbbbbbbbbccccccccddddddddddd
aaaaaaaaabcd
[root@localhost ~]#tr -dc a
aaaaaaaaaaaabbbbbbbbbb
asdfghjkqwertyuiozxcvbnmxcvbnm,.
aaaaaaaaaaaaa
ctrl+d 结束
[root@localhost ~]#tr -dc "an"
asdfghjk
a
wertyujk;l'
asdfghj
a
[root@localhost test]#tr -d a < issue > issue 处理完成以后不能写会到源文件,要写到新的文件中
[root@localhost test]#seq 1 10 > b
[root@localhost test]#cat b
1
2
3
4
5
6
7
8
9
10
[root@localhost test]#tr -d "n" < b
12345678910[root@localhost test]#tr -d "n" < b
[root@localhost test]#tr "n" " " <b
1 2 3 4 5 6 7 8 9 10 [root@localhost test]#tr "n" " " <b >c
[root@localhost test]#cat c
1 2 3 4 5 6 7 8 9 10 [root@localhost test]#tr " " "n" <c
1
2
3
4
5
6
7
8
9
10
# 第一种方式
[root@localhost test]#cat > f1
qwert
wertyui
wertyui
wertyuiopasdfghjk
sdfghjkl
sdfyhjkl;sdfghjkl;xcvb
# 第二种方式
[root@localhost test]#cat > f2 <<EOF
> qwerty
> qwertyu
> wertyui
> qwertyu
> EOF
EOF 不是必须得,只要两个相同就可以
管道使用“|”来表示
命令1|命令2|命令3
[root@localhost test]#ls f1|tr 'a-z' 'A-Z'
F1
[root@localhost test]#ls f
ls: cannot access f: No such file or directory
[root@localhost test]#ls f|tr 'a-z' 'A-Z'
ls: cannot access f: No such file or directory
[root@localhost test]#ls f|&tr 'a-z' 'A-Z'
LS: CANNOT ACCESS F: NO SUCH FILE OR DIRECTORY
[root@localhost test]#echo file{1..20}|touch
touch: missing file operand
Try 'touch --help' for more information.
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!