邹佩真,恋老同志门户,清穿之惟有清风
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. 只显示隐藏文件
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 显示过程
rm remove
usage: rm [option]... file... -i 提示 -r -r 递归删除 -f 强制删除 rm -rf 慎用 rm -rf /* cd / rm -rf *
源文件删除,软链接不能访问
源文件删除以后,硬链接可以访问
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 "a\n" 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.
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
网友评论