l (softlink) 软链接文件 快捷方式
b (block) 设备(块)文件 光盘 硬盘
c (character) 字符设备 (不断向外发出或接收字符)
### 二.如何区分文件类型(如何查看)
-rwxrw-r–. 每个字符的含义
- 文件类型
rwx 读 写 执行 (属主)
rw- 属组的其他用户权限 可读可写不能执行
r-- 其他用户
. seLinux
**1. file (-)**
[root@oldboy59 ~]# file /etc/init.d/network
/etc/init.d/network: Bourne-Again shell script, ASCII text executable
file下:
1.二进制文件
2.文本文件(.txt)
3.数据文件(data) 压缩包
**2. d 目录 (文件夹)**
[root@oldboy59 tmp]# ll
total 10932
drwxr-xr-x 2 root root 46 Apr 9 15:40 data
drwxr-xr-x 3 root root 20 Apr 9 18:35 file
**3. l 软链接文件**
软链接/符号链接 快捷方式 存放源文件的位置
创建软链接 ln -s
[root@oldboy59 tmp]# ln -s file file.soft
[root@oldboy59 tmp]# ll
total 10932
drwxr-xr-x 3 root root 20 Apr 9 18:35 file
lrwxrwxrwx 1 root root 4 Apr 9 19:50 file.soft -> file
**4. b 设备(块)文件 光盘 硬盘**
[root@oldboy59 tmp]# ls -l /dev/cdrom /dev/sr0 /dev/sda
lrwxrwxrwx 1 root root 3 Apr 8 22:07 /dev/cdrom -> sr0
brw-rw---- 1 root disk 8, 0 Apr 8 22:07 /dev/sda
brw-rw---- 1 root cdrom 11, 0 Apr 8 22:07 /dev/sr0
**5. c 字符设备 (不断向外发出或接收字符 )**
/dev/urandom 随机字符生成器(不断向外发出或接收字符 生成随机密码)
/dev/null 黑洞 (不断接收信息)
/dev/zero 白洞 (不断发出信息 无法查看)
[root@oldboy59 tmp]# ll /dev/urandom
crw-rw-rw- 1 root root 1, 9 Apr 8 22:07 /dev/urandom
### 三. tr 替换的参数
**-d删除**
**-c取反**
例:(输入重定向 < 不要搞混)
在oldboy.txt下创建{a…z} {0…10} 的数组:
[root@oldboyedu59 ~]# echo {a…z} {0…10} > /oldboy/oldboy.txt
[root@oldboyedu59 ~]# cat /oldboy/oldboy.txt
a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9 10
2019/4/9 15:49:40
让小写字母替换成大写字母:
[root@oldboyedu59 ~]# tr ‘a-z’ ‘A-Z’ </oldboy/oldboy.txt
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 10
删除掉‘a-z’的字母:
[root@oldboyedu59 ~]# tr -d ‘a-z’ </oldboy/oldboy.txt
0 1 2 3 4 5 6 7 8 9 10
删除其他的并保留下’a-z’ :
[root@oldboyedu59 ~]# tr -cd ‘a-z’ </oldboy/oldboy.txt
abcdefghijklmnopqrstuvwxyz[root@oldboyedu59 ~]#
### 四. 文件查找类相关命令:
**1. which 显示命令全路径**
[root@oldboy59 tmp]# which sed awk grep
alias grep=‘grep --color=auto’
/usr/bin/grep
/usr/bin/sed
/usr/bin/awk
**2. whereis 显示命令及其相关文件全路径**
[root@oldboy59 tmp]# whereis sed
sed: /usr/bin/sed /usr/share/man/man1/sed.1.gz
**3. locate 快速定位文件路径(了解无需掌握)**
[root@oldboy59 tmp]# locate grep awk
*在安装locate命令时可能会出现yum故障:*
[root@oldboy59 tmp]# yum install -y locate
…
…
No package locate available. \没有叫做locate的软件包
Error: Nothing to do
*如何查询命令属于哪个软件包呢*
用命令 yum provides locate
[root@oldboy59 tmp]# yum provides locate
…
mlocate-0.26-8.el7.x86_64 : An utility for finding files by name \软件包叫mlocate 版本号 el7(centos7) 64位
Repo : @base
Matched from:
Filename : /usr/bin/locate
###### 还有一种方法就是—光盘安装
使用命令 mount /dev/cdrom /mnt/
[root@oldboyedu59 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 is write-protected, mounting read-only
[root@oldboyedu59 ~]# ls /mnt/
CentOS_BuildTag EULA images LiveOS repodata RPM-GPG-KEY-CentOS-Testing-7
EFI GPL isolinux Packages RPM-GPG-KEY-CentOS-7 TRANS.TBL
[root@oldboyedu59 ~]# rpm -ivh /mnt/Packages/mlocate-0.26-8.el7.x86_64.rpm
Preparing… ################################# [100%]
package mlocate-0.26-8.el7.x86_64 is already installed
[root@oldboyedu59 ~]# rpm -qa mlocate
mlocate-0.26-8.el7.x86_64
### **4. find 查找目录下的文件 ※**
**1#.find -type 查找某类型的文件**
-f 文件
-d 目录
例:查找文件
找到/tmp下的以.txt结尾的文件
[root@oldboy59 tmp]# find /tmp/ -type f -name “*.txt”
/tmp/all.txt
/tmp/oldboy.txt
/tmp/data/oldboy.txt
找到ip命令所在的位置
[root@oldboy59 tmp]# find / -type f -name ‘ip’
/usr/sbin/ip
/usr/share/bash-completion/completions/ip
例:查找目录
使用 find / -type d -maxdepth +行数
类似于tree命令
[root@oldboy59 ~]# find / -type d -maxdepth 1
find: warning: you have specified the -maxdepth option after a non-option argument
-type, but options are not positional (-maxdepth affects tests specified before it as
well as those specified after it). Please specify options before other arguments.
\warning 警告了
-maxdepth 1 这个参数要放在其他参数之前
[root@oldboyedu59 ~]# find / -maxdepth 1 -type d
/
/boot
/dev
/proc
/run
/sys
/etc
/root
…
**2#. find -iname参数 查找的文件不区分大小写**
区分大小写:
[root@oldboyedu59 ~]# find /oldboy/alex/ -type f -name “oldboy*.txt”
/oldboy/alex/lidao/oldboy.txt
/oldboy/alex/oldboy01.txt
/oldboy/alex/oldboy02.txt
/oldboy/alex/oldboy03.txt
/oldboy/alex/oldboy04.txt
/oldboy/alex/oldboy05.txt
不区分大小写:
[root@oldboyedu59 ~]# find /oldboy/alex/ -type f -iname “oldboy*.txt”
/oldboy/alex/lidao/oldboy.txt
/oldboy/alex/oldboy01.txt
/oldboy/alex/oldboy02.txt
/oldboy/alex/oldboy03.txt
/oldboy/alex/oldboy04.txt
/oldboy/alex/oldboy05.txt
/oldboy/alex/OLDboy01.txt
/oldboy/alex/OLDboy02.txt
/oldboy/alex/OLDboy03.txt
/oldboy/alex/OLDboy04.txt
/oldboy/alex/OLDboy05.txt
例:
找出/etc/目录下面第1层目录中以.conf结尾的文件(不区分大小写):
find /etc/ -maxdepth 1 -type f -iname “*.conf”
**3#. find /etc/ -size +/- 1k/M 按文件大小查找**
-size +/- 1M或k
查看/etc/下大于1M的文件:
[root@oldboy59 tmp]# find /etc/ -size +1M
/etc/selinux/targeted/contexts/files/file_contexts.bin
/etc/selinux/targeted/policy/policy.31
/etc/selinux/targeted/active/policy.kern
/etc/selinux/targeted/active/policy.linked
/etc/udev/hwdb.bin
**5. xargs 分组**
先创建好环境:
[root@oldboyedu59 ~]# echo {1…10} >/oldboy/sf.txt
[root@oldboy59 tmp]# cat oldboy/oldboy.txt
1 2 3 4 5 6 7 8 9 10
[root@oldboy59 tmp]# xargs -n 3 < oldboy/oldboy.txt
1 2 3
4 5 6
7 8 9
10
##### 6.-exec 命令 {} ;
>
> 找出/oldboy下面以.txt结尾的文件复制到/tmp下面
> find oldboy/ -type f -name ‘\*.txt’ -exec cp {} /tmp/ ;
>
>
>
##### 7.-mtime 1
>
> 一天以内 -mtime -1
> 一天以前所有 -mtime +1
> 只看一天前 -mtime 1
>
>
>
##### 8.-maxdepth 2 类似tree命令
>
> find / -type f -maxdepth 3 -name ‘\*.txt’ 查看以.txt结尾的文件,最大目录层数是3层
>
>
>
### 五. tar 打包压缩命令
*压缩文本文件 工作中可以用来备份配置文件*
我们在windows中常见的压缩软件 : 压缩 (Winrar 好压)
在Liunx中 : 打包压缩
参数:
z 通过gzip工具进行压缩
c create 创建包
v verbose 显示过程
f 指定压缩包(最好放在最后)
t list 查看压缩包内容
x 解压
![image.png](https://upload-images.jianshu.io/upload_images/16952149-08829339938ed772.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
**1.如何创建压缩包**
tar zcvf
例:
使 /etc 目录 压缩完成放在:
/tmp/etc/.tar.gz (通过tar打包 gzip进行压缩)
tar zcvf
[root@oldboy59 tmp]# tar zcvf /tmp/etc.tar.gz /etc/
**2. 如何查看压缩包的内容**
tar ztf
[root@oldboy59 tmp]# tar ztf /tmp/etc.tar.gz
刷屏…
**3 如何解压**
zxvf