
特殊符号; && ||
;#命令分割符 无论前面命令是否执行成功,都会继续执行后面命令
[root@theboy82 ~]# touch 88.txt;ll 88.txt -rw-r--r--. 1 root root 0 May 13 10:04 88.txt [root@theboy82 ~]# touh 22.tt;ll 22.txt -bash: touh: command not found ls: cannot access 22.txt: No such file or directory
&前面的命令执行成功 才可之后&&后面的命令
&前面的命令执行成功 才可之后&&后面的命令 [root@theboy82 ~]# mkdir linux&&ll linux mkdir: cannot create directory ‘linux’: File exists [root@theboy82 ~]# ll linux&&mkdir linux total 0 drwxr-xr-x. 3 root root 18 Apr 28 22:07 wh mkdir: cannot create directory ‘linux’: File exists
||#前面的命令执行失败 才能执行后面的命令
[root@theboy82 ~]# touc 2.txt||pwd -bash: touc: command not found /root [root@theboy82 ~]# ll 2.txt||pwd -rw-r--r--. 1 root root 30 May 13 10:15 2.txt
文件压缩
节约磁盘空间 压缩不常用的文件
压缩后的文件,发送备份服务器过程减少磁盘IO,一个文件建立一次IO请求,多个文件建立多个IO请求
压缩时间选择zabbix低点进行,因压缩过程比较消耗服务器CPU
Linux压缩命令
tar -参数
Z #使用gzip方式进行压缩 c #使用create创建压缩包 v #显示压缩过程 verbose f #指定文件 file x #表示解压 使用xf参数进行解压 extract t #查看压缩包里面文件名称 使用tf参数查看 c #指定解压位置(默认当前) ------------------------------------------------------------------------ -P #不提示从成员中删除/ --exclude#排除文件 --exclude-from#排除文件中的文件名
tar zcvf#压缩文件 [root@theboy82 ~]# tar zcvf /root/test1/hosts.tar.gz /root/hosts /root/88.txt tar: Removing leading `/' from member names /root/hosts /root/88.txt [root@theboy82 ~]# ll test1 total 4 -rw-r--r--. 1 root root 197 May 13 11:06 hosts.tar.gz 系统为保护文件安全,使用绝对路径会删除/,如不删除解压后的路径会覆盖源文件: [root@theboy82 ~]# tar tf test1/hosts.tar.gz root/hosts root/88.txt
tar xf#解压缩 [root@theboy82 ~]# tar xf test1/hosts.tar.gz -C test2 [root@theboy82 ~/test2/root]# ll total 4 -rw-r--r--. 1 root root 0 May 13 10:04 88.txt -rw-r--r--. 1 root root 158 May 13 10:44 hosts
exclude#排除压缩 [root@theboy82 ~]# tar zcvf 111.tar.gz ./* --exclude=passwd --exclude=anaconda-ks.cfg ./1.txt ./2.txt ./3.txt [root@theboy82 ~]# ll total 16 -rw-r--r--. 1 root root 298 May 13 14:02 111.tar.gz -rw-r--r--. 1 root root 120 May 13 11:24 1.txt -rw-r--r--. 1 root root 0 May 13 11:22 2.txt -rw-r--r--. 1 root root 0 May 13 11:22 3.txt -rw-------. 1 root root 1505 Apr 28 22:03 anaconda-ks.cfg -rw-r--r--. 1 root root 938 May 5 19:42 passwd
--exclude-from#排除压缩写入到文件的文件
[root@theboy82 ~]# cat 1.txt 2.txt 3.txt [root@theboy82 ~]# tar zcvf yasobk.tar.gz ./* --exclude-from=1.txt ./1.txt ./anaconda-ks.cfg ./passwd [root@theboy82 ~]# ll total 16 -rw-r--r--. 1 root root 12 May 13 14:08 1.txt -rw-r--r--. 1 root root 0 May 13 11:22 2.txt -rw-r--r--. 1 root root 0 May 13 11:22 3.txt -rw-------. 1 root root 1505 Apr 28 22:03 anaconda-ks.cfg -rw-r--r--. 1 root root 938 May 5 19:42 passwd -rw-r--r--. 1 root root 1399 May 13 14:09 yasobk.tar.gz
文件权限
[root@theboy82 ~]# ll -i total 12 33574990 -rw-r--r--. 1 root root 12 May 13 14:08 1.txt 33574991 -rw-r--r--. 1 root root 0 May 13 11:22 2.txt 33575203 -rw-r--r--. 1 root root 0 May 13 11:22 3.txt 33574979 -rw-------. 1 root root 1505 Apr 28 22:03 anaconda-ks.cfg 33575204 -rw-r--r--. 1 root root 938 May 5 19:42 passwd
| 33574990 | - | rw-r--r-- | . | 1 | root | root | 12 | May 13 14:08 | 1.txt |
|---|---|---|---|---|---|---|---|---|---|
| inode | 文件类型 | 9位权限 | 表示开启selinux时创建的 | 硬链接个数 | 用户 | 用户组 | 文件大小 | 创建时间 | 文件名 |
| 分为3组权限位 | 关闭就没有· | 文件默认1文件夹默认2 |
| 权限 | rw- | r-- | r-- | r | w | x | - |
|---|---|---|---|---|---|---|---|
| 释义 | users属主权限 | group属组权限 | other其他用户权限 | read读取 | write写入 | execute执行 | 无权限 |
| 表示数字 | 6 | 6 | 6 | 4 | 2 | 1 |
inode号:ll -i 查看
同一文件系统中相同inode号的文件互为硬链接
只能在相同分区创建,删除任意一个不影响其他
不能对目录进行创建硬链接 文件可以
ln 源文件 目标文件#创建硬链接 [root@theboy82 ~]# ln 1.txt tidl.txt [root@theboy82 ~]# ll -i total 16 33574990 -rw-r--r--. 2 root root 12 May 13 14:08 1.txt 33574990 -rw-r--r--. 2 root root 12 May 13 14:08 tidl.txt df -i#查看inode使用情况(每个文件最少占用1个inode和1个block软件储存块)
软连接:
删除软链接不影响源文件,删除源文件软链接文件不可用,红底白字闪烁
文件和目录都可做软链接,可以跨文件系统做软链接
软链接inode号不同
ln -s 源文件 链接文件(做软连接尽量使用绝对路路径) [root@theboy82 ~]# ln -s 1.txt rrlmjx.txt [root@theboy82 ~]# ll total 16 -rw-r--r--. 2 root root 12 May 13 14:08 1.txt -rw-r--r--. 1 root root 0 May 13 11:22 2.txt -rw-r--r--. 1 root root 0 May 13 11:22 3.txt -rw-------. 1 root root 1505 Apr 28 22:03 anaconda-ks.cfg -rw-r--r--. 1 root root 938 May 5 19:42 passwd lrwxrwxrwx. 1 root root 5 May 14 12:00 rrlmjx.txt -> 1.txt -rw-r--r--. 2 root root 12 May 13 14:08 tidl.txt
利用软链接跨文件系统解决磁盘不足问题
做代码上线 回滚等
文件时间
stat 查看文件详细属性
[root@theboy82 ~]# stat /etc/hosts File: ‘/etc/hosts’ Size: 158 Blocks: 8 IO Block: 4096 regular file Device: 803h/2051d Inode: 16777795 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Context: system_u:object_r:net_conf_t:s0 Access: 2022-05-14 10:44:21.975015432 +0800 Modify: 2013-06-07 22:31:32.000000000 +0800 Change: 2022-04-28 22:00:21.455270984 +0800 Birth: -
| access | modify | change |
|---|---|---|
| 访问时间 | 修改时间 | 改变时间 |
| 第一次查看会发生变化,后面查看不会变 | 编辑后三个时间都会变 | 改变文件内容属性发生变化 |
按时间进行查找文件
| -atime | 按访问时间查找 | 了解 |
|---|---|---|
| -mtime | 按修改时间查找 | 重要 |
| -ctime | 按属性修改时间查找 | 了解 |
| find ./ -mtime +7 | 查找7天前被修改的文件和目录 | |
| find ./ -mtime -7 | 查找7天内被修改的文件和目录 | |
| -mtime 0 | 表示最近24小时修改的文件 | |
| -mtime 1 | 表示一天前修改的文件 |