3符号链接(symbolic link)文件,软链接(soft link)
快捷方式:ln -s
rm
4.字符(character)/块(block)设备文件
以c开头的就是字符设备,猫等串口设备
以b开头的就是块设备 硬盘、光驱等都属于块设备
mknod
5.套接口(socket)文件
以s开头
.sock文件也是一类特殊的文件,这类文件通常用在网络之间,进行数据连接,如:我们可以启动一个程序来监听客户端的请求,客户端可以通过套接字来进行数据通信。
用于进程之间通信的文件。
8.3 文件及命令查找命令
1. file 显示文件类型
2. which 查命令所在的路径
重点:
PATH 变量作用
命令行执行命令会从PATH对应的路径中查找命令,
PATH 对应的路径中没有这个命令就会报command not found
[root@oldboyedu~]# ff
-bash: ff: commandnot found
[root@oldboyedu~]# cd /usr/local/sbin
[root@oldboyedu/usr/local/sbin]# vim ff
[root@oldboyedu/usr/local/sbin]# cat ff
echo $1
[root@oldboyedu/usr/local/sbin]# chmod +x ff
[root@oldboyedu ~]# ff oldboy
oldboy
[root@oldboyedu~]# ff oldgirl
oldgirl
[root@oldboyedu ~]# which ff
/usr/local/sbin/ff
3. whereis:显示命令、源码、说明文档等的路径
locate:[root@oldboyedu~]# whereis -b cp
cp: /usr/bin/cp
4. locate:快速定位文件路径
locate查找文件路径,是从数据库A(/var/lib/mlocate/mlocate.db)里查询
更新A数据库用updatedb命令
C7默认没安装,不要学了
6. find:查找目录下的文件*****
查找原理:磁盘遍历,速度慢。
[root@oldboyedu~]# find ~ -name "oldboy.txt"
路径 名字参数 具体文件
/root/oldboy.txt
练习:从根下查找ifcfg-eth0网卡文件
[root@oldboyedu~]# find / -name "ifcfg-eth0"
/etc/sysconfig/network-scripts/ifcfg-eth0
模糊查找 *表示所有
[root@oldboyedu~]# find / -name "*y*"
按文件类型查找-type
[root@oldboyedu~]# find / -type f -name "oldboy*"
-type c
File is of type c:
b block (buffered) special
c character (unbuffered) special
d directory
p named pipe (FIFO)
f regular file
l symbolic link; this is never true if the-L option or the -follow
find / -type d-name "oldboy*"
这里的类型和名字是取交集,两条件都满足。默认是交集,相当于有个-a
如果取并集即或者用-o分割查找的项
find / -type d -o-name "oldboy*"
了解:
-a and 并且
-o or 或者
! 取反
已知;代表oldboy
\; 又仅代表自身,即分号。
7. xargs分组
[root@oldboyedu/data]# echo {1..10} >test.txt
[root@oldboyedu/data]# cat test.txt
1 2 3 4 5 6 7 8 910
[root@oldboyedu/data]# xargs -n 3
1 2 3
4 5 6
7 8 9
10
-d 指定分隔符,不指定默认是空格
[root@oldboyedu/data]# xargs -d"." -n2
a b
c d
[root@oldboyedu/data]# xargs -n2
a.b.c.d
[root@oldboyedu/data]# cat test.txt
a.b.c.d
[root@oldboyedu/data]# echo "Oldboy" >test.txt
[root@oldboyedu/data]# echo "Oldgirl" >>test.txt
[root@oldboyedu/data]# echo "Oldboedu" >>test.txt
[root@oldboyedu/data]# echo "Oldboyedu" >>test.txt
[root@oldboyedu/data]# cat test.txt
Oldboy
Oldgirl
Oldboedu
Oldboyedu
[root@oldboyedu/data]# cat test.txt|grep "boy"
Oldboy
Oldboyedu
[root@oldboyedu/data]# grep "boy" test.txt
Oldboy
Oldboyedu
[root@oldboyedu/data]# find /data -type f|xargs rm -f
[root@oldboyedu/data]# ll
total 0
drwxr-xr-x. 2 rootroot 6 Mar 14 10:40 a
drwxr-xr-x. 2 rootroot 6 Mar 14 10:40 b
drwxr-xr-x. 2 rootroot 6 Mar 14 10:40 c
drwxr-xr-x. 2 rootroot 6 Mar 14 10:40 d
[root@oldboyedu/data]# touch oldboy{1..5}.txt
[root@oldboyedu/data]# ls
a b c d oldboy1.txt oldboy2.txt oldboy3.txt oldboy4.txt oldboy5.txt
[root@oldboyedu/data]# find /data -type f -exec rm -f {} \;
[root@oldboyedu/data]# ls
a b c d
find /data -type f-exec rm -f {} \;
相当于
rm -f oldboy1.txt
rm -f oldboy2.txt
rm -f oldboy3.txt
效率低。
find /data -typef|xargs rm -f
只是一条命令
rm -f oldboy1.txtoldboy2.txt oldboy3.txt
效率高
find /data -typef|rm -f
相当于:
find /data -type f
rm -f
[root@oldboyedu/data]# date -s "2020/10/1 00:00:00"
Thu Oct 1 00:00:00 CST 2020
[root@oldboyedu/data]# date
Thu Oct 1 00:00:03 CST 2020
[root@oldboyedu/data]# clock -w
[root@oldboyedu/data]# date +%F
2020-10-01
[root@oldboyedu/data]# date +%Y #year年
2020
[root@oldboyedu/data]# date +%y #year年
20
[root@oldboyedu/data]# date +%m #month月
10
[root@oldboyedu /data]#date +%d #day日
01
[root@oldboyedu/data]# date +%H #hour时
00
[root@oldboyedu/data]# date +%M #minute分
02
[root@oldboyedu/data]# date +%S #second秒
46
[root@oldboyedu/data]# date +%Y-%m-%d
2020-10-01
[root@oldboyedu/data]# date +%F
2020-10-01
[root@oldboyedu/data]# date +%H:%M:%S
00:04:29
[root@oldboyedu/data]# date
Thu Oct 1 00:04:38 CST 2020
[root@oldboyedu/data]# date +%F -d "-1day"
2020-09-30
[root@oldboyedu/data]# date +%F -d "+1day"
2020-10-02
[root@oldboyedu/data]# date +%F -d "+1month"
2020-11-01
[root@oldboyedu/data]# date +%F -d "+1Y"
date: invalid date‘+1Y’
[root@oldboyedu/data]# date +%F -d "+1year"
2021-10-01
- 过去
+ 未来
[root@oldboyedu/data]# date +"%Y-%m-%d %H:%M:%S"
2020-10-0100:09:36
[root@oldboyedu/data]# date +"%F %T"
2020-10-0100:09:39
8.4 tar *****
tar 参数 筐(压缩包) 苹果(被打包的文件)
打包集合参数zcvf:v可以不加
压缩包名字:data.tar.gz #tar表示打包,gz表示gzip格式压缩。
例子:
[root@oldboyedu~]# mkdir /data
[root@oldboyedu~]# cd /data
[root@oldboyedu/data]# touch {1..5}.txt
[root@oldboyedu/data]# ls
1.txt 2.txt 3.txt 4.txt 5.txt
[root@oldboyedu/data]# cd ..
[root@oldboyedu/]# tar zcvf /opt/data.tar.gz ./data
./data/
./data/1.txt
./data/2.txt
./data/3.txt
./data/4.txt
./data/5.txt
查看压缩包里的内容:-t
[root@oldboyedu/]# tar tf /opt/data.tar.gz
./data/
./data/1.txt
./data/2.txt
./data/3.txt
./data/4.txt
./data/5.txt
解压:
[root@oldboyedu/opt]# tar zxvf data.tar.gz
./data/
./data/1.txt
./data/2.txt
./data/3.txt
./data/4.txt
./data/5.txt
[root@oldboyedu/opt]# ls
data data.tar.gz
[root@oldboyedu/opt]# ls data
1.txt 2.txt 3.txt 4.txt 5.txt
[root@oldboyedu/opt]# tar xf data.tar.gz
[root@oldboyedu/opt]# tar xf data.tar.gz -C /tmp/
[root@oldboyedu/opt]# ls /tmp/data
1.txt 2.txt 3.txt 4.txt 5.txt
[if !vml]
[endif]
[if !vml]
[endif]