一、文件类型
扩展名 .avi .txt .log .sh
Windows: 系统根据不同的扩展名 区分不同类型的文件.
Linux: 扩展名是给我们看的。方便人类区分不同类型的文件.
预备姿势:常见的扩展名
.txt 文本文件
.log 日志文件
.conf .cfg 配置文件
.sh .bash 脚本文件(命令大礼包)
常见的文件类型:
- file 普通文件
d diectory 目录
l softlink 软连接(快捷方式)
b block 设备(块)文件 光盘 硬盘
c character 字符设备(不断向外发出或接受字符)
- file 普通文件
1.二进制文件(命令)
2.文本文件(text)
3.数据文件(data) 压缩包
[root@oldboyedu59 oldboy]# ls -l /bin/ls /oldboy/alex.txt
-rwxr-xr-x. 1 root root 117680 Oct 31 03:16 /bin/ls
-rw-r--r-- 1 root root 0 Mar 29 09:03 /oldboy/alex.txt
如何区分文件类型(如何查看)
file
[root@oldboyedu59 oldboy]# file /bin/ls /oldboy/alex.txt
/bin/ls: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=ceaf496f3aec08afced234f4f36330d3d13a657b, stripped
/oldboy/alex.txt: ASCII text
d 目录 (文件夹)
l softlink 软连接/符号链接(快捷方式) 存放源文件的位置
创建软连接
touch /oldboy/oldboy.txt
[root@oldboyedu59 oldboy]# touch /oldboy/oldboy.txt
[root@oldboyedu59 oldboy]# ls -l /oldboy/
total 8
drwxr-xr-x. 3 root root 19 Mar 28 11:57 alex
-rw-r--r-- 1 root root 7 Apr 9 15:08 alex.txt
-rw-r--r-- 1 root root 65 Apr 1 20:52 oldboy.avi
-rw-r--r-- 1 root root 0 Apr 9 15:19 oldboy.txt
-rw-r--r--. 1 root root 0 Mar 28 12:38 oldboy.txt.bak
[root@oldboyedu59 oldboy]# ln -s /oldboy/oldboy.txt /oldboy/oldboy.txt.soft
[root@oldboyedu59 oldboy]# ls -l /oldboy/
total 8
drwxr-xr-x. 3 root root 19 Mar 28 11:57 alex
-rw-r--r-- 1 root root 7 Apr 9 15:08 alex.txt
-rw-r--r-- 1 root root 65 Apr 1 20:52 oldboy.avi
-rw-r--r-- 1 root root 0 Apr 9 15:19 oldboy.txt
-rw-r--r--. 1 root root 0 Mar 28 12:38 oldboy.txt.bak
lrwxrwxrwx 1 root root 18 Apr 9 15:20 oldboy.txt.soft -> /oldboy/oldboy.txt
[root@oldboyedu59 oldboy]# file /oldboy/oldboy.txt.soft
/oldboy/oldboy.txt.soft: symbolic link to `/oldboy/oldboy.txt'
[root@oldboyedu59 oldboy]# ls -l /bin /sbin /etc/init.d /etc/rc.local
lrwxrwxrwx. 1 root root 7 Mar 26 11:38 /bin -> usr/bin
lrwxrwxrwx. 1 root root 11 Mar 26 11:37 /etc/init.d -> rc.d/init.d
lrwxrwxrwx. 1 root root 13 Mar 26 11:39 /etc/rc.local -> rc.d/rc.local
lrwxrwxrwx. 1 root root 8 Mar 26 11:38 /sbin -> usr/sbin
b block 设备(块)文件 光盘 硬盘
[root@oldboyedu59 oldboy]# ls -l /dev/cdrom /dev/sr0 /dev/sda
lrwxrwxrwx 1 root root 3 Apr 3 14:39 /dev/cdrom -> sr0
brw-rw---- 1 root disk 8, 0 Apr 3 14:39 /dev/sda
brw-rw---- 1 root cdrom 11, 0 Apr 3 14:39 /dev/sr0
c character 字符设备(不断向外发出或接受字符)
/dev/urandom 随机字符生成器 (生成随机密码)
/dev/null 黑洞(不断接受信息 )
/dev/zero 白洞(不断发出信息 无法查看)
[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
[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
[root@oldboyedu59 ~]# #删除
[root@oldboyedu59 ~]# #tr -d '要删除的内容' </oldboy/oldboy.txt
[root@oldboyedu59 ~]# tr -d 'a-z' </oldboy/oldboy.txt
0 1 2 3 4 5 6 7 8 9 10
[root@oldboyedu59 ~]# #tr -cd
-d删除
-c取反
[root@oldboyedu59 ~]# tr -cd 'a-z' </oldboy/oldboy.txt
abcdefghijklmnopqrstuvwxyz[root@oldboyedu59 ~]#
[root@oldboyedu59 ~]# tr -cd 'a-zA-Z0-9' </dev/urandom |head -c 8
xoRe6cQs[root@oldboyedu59 ~]#
Linux文件类型:
- file 普通文件
d diectory 目录
l softlink 软连接(快捷方式)
b block 设备(块)文件 光盘 硬盘
c character 字符设备(不断向外发出或接受字符)
file
tr -c -d
ln -s
查询相关命令;
[root@oldboyedu59 ~]# \which sed awk grep
/usr/bin/sed
/usr/bin/awk
/usr/bin/grep
which:显示命令的全路径
whereis:显示命令及其相关文件全路径
yum故障集合:
Error: Nothing to do
No package locate available.
没有叫做 locate 的软件包
如何查询命令属于哪个软件包
软件包-多个命令
-
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
光盘安装
[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
查找find
[root@oldboyedu59 ~]# find /oldboy -type f -name "oldboy.txt"
/oldboy/alex/lidao/oldboy.txt
/oldboy/oldboy.txt
通过find命令找出ip命令的位置。
[root@oldboyedu59 ~]# find /oldboy -type f -name "*.txt"
/oldboy/alex/lidao/oldboy.txt
/oldboy/alex.txt
/oldboy/oldboy.txt
tree -L 1 -d
[root@oldboyedu59 ~]# 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 这个参数要放在其他参数之前。
跟下的d文件
[root@oldboyedu59 ~]# find / -maxdepth 1 -type d
/
/boot
/dev
/proc
/run
/sys
/etc
/root
/var
/tmp
/usr
/home
/media
/mnt
/opt
/srv
/old
/oldboy
/lidao
/oldwang
/newwang
/data
/tmp01
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
[root@oldboyedu59 ~]#
习题:找出/etc/目录下面第1层目录中以.conf结尾的文件(不区分大小写)
完成后发出命令
find /etc/ -maxdepth 1 -type f -iname "*.conf"
xargs 分组
[root@oldboyedu59 ~]# echo {1..10} >/oldboy/sf.txt
[root@oldboyedu59 ~]# cat /oldboy/sf.txt
1 2 3 4 5 6 7 8 9 10
[root@oldboyedu59 ~]# xargs -n2 </oldboy/sf.txt
1 2
3 4
5 6
7 8
9 10
tar:打包压缩命令
文本文件(配置) 备份
windows : 压缩(winrar 好压 2345压缩)
Linux: 打包压缩
tar
##创建压缩包
/etc 目录 压缩完成放在/tmp/etc.tar.gz (通过tar打包 gzip进行压缩)
z 通过gzip工具进行压缩
c create 创建包
v verbose 显示过程
f 指定压缩包(放在最后)
tar zcvf /tmp/etc.tar.gz /etc/
tar zcf /tmp/etc.tar.gz /etc/
##查看压缩包的内容
tar ztf /tmp/etc.tar.gz
t list 查看压缩包内容
##解压(默认解压到当前目录)
tar zxf /tmp/etc.tar.gz
[root@oldboyedu59 tmp]# tar xf /tmp/etc.tar.gz -C /opt/
[root@oldboyedu59 tmp]# ls -l /opt
total 12
drwxr-xr-x 79 root root 8192 Apr 9 16:35 etc