5. Linux文件目录管理和打包压缩与搜索命令
1.touch:用于创建空白文件或设置文件的时间

举例:使用ls 命令查看一个文件的修改时间,然后修改这个文件,最后再通过touch命令把修改后的文件时间设置成修改之前的时间(很多黑客就是这样做的):
[root@Centos test]# ll
total 8
-rw-r--r--. 1 root root 91 Aug 4 14:53 A.txt
-rw-r--r--. 1 root root 84 Aug 4 14:53 B.txt
[root@Centos test]# echo You can you up, no can no bebe>> A.txt
[root@Centos test]# ll
total 8
-rw-r--r--. 1 root root 122 Aug 4 16:36 A.txt
-rw-r--r--. 1 root root 84 Aug 4 14:53 B.txt
[root@Centos test]# touch -d 14:53 A.txt
[root@Centos test]# ll
total 8
-rw-r--r--. 1 root root 122 Aug 4 14:53 A.txt
-rw-r--r--. 1 root root 84 Aug 4 14:53 B.txt
注:用stat代替ll发现touch命令只能修改access time 和 modify time,而不能修改change time。
2.mkdir:用于创建空白的目录。
结合-p 参数来递归创建出具有嵌套叠层关系的文件目录。
[root@Centos test]# mkdir xinghen1216
[root@Centos test]# ll
total 8
-rw-r--r--. 1 root root 122 Aug 4 14:53 A.txt
-rw-r--r--. 1 root root 84 Aug 4 14:53 B.txt
drwxr-xr-x. 2 root root 6 Aug 4 16:46 xinghen1216
[root@Centos test]# mkdir -p a/b/c
[root@Centos test]# ll
total 8
drwxr-xr-x. 3 root root 15 Aug 4 16:47 a
-rw-r--r--. 1 root root 122 Aug 4 14:53 A.txt
-rw-r--r--. 1 root root 84 Aug 4 14:53 B.txt
drwxr-xr-x. 2 root root 6 Aug 4 16:46 xinghen1216
[root@Centos test]# cd a
[root@Centos a]# ll
total 0
drwxr-xr-x. 3 root root 15 Aug 4 16:47 b
[root@Centos a]# cd b
[root@Centos b]# ll
total 0
drwxr-xr-x. 2 root root 6 Aug 4 16:47 c
[root@Centos b]# cd c
[root@Centos c]# ll
total 0
3.cp:复制文件或目录。格式为“cp [选项] 源文件 目标文件”
1)如果目标文件是目录,则会把源文件复制到该目录中;
2)如果目标文件也是普通文件,则会询问是否要覆盖它;
3)如果目标文件不存在,则执行正常的复制操作。

[root@Centos test]# cp A.txt a.txt
[root@Centos test]# ll
total 12
drwxr-xr-x. 3 root root 15 Aug 4 16:47 a
-rw-r--r--. 1 root root 122 Aug 4 16:58 a.txt
-rw-r--r--. 1 root root 122 Aug 4 14:53 A.txt
-rw-r--r--. 1 root root 84 Aug 4 14:53 B.txt
drwxr-xr-x. 2 root root 6 Aug 4 16:46 xinghen1216
4.mv:剪切文件或将文件重命名,格式为“mv [选项] 源文件 [目标路径|目标文件名]”
如果在同一个目录中对一个文件进行剪切操作,其实也就是对其进行重命名:
[root@Centos test]# mv a.txt aa.txt
[root@Centos test]# ll
total 12
drwxr-xr-x. 3 root root 15 Aug 4 16:47 a
-rw-r--r--. 1 root root 122 Aug 4 16:58 aa.txt
-rw-r--r--. 1 root root 122 Aug 4 14:53 A.txt
-rw-r--r--. 1 root root 84 Aug 4 14:53 B.txt
drwxr-xr-x. 2 root root 6 Aug 4 16:46 xinghen1216
5.rm:删除文件或目录,格式为“rm [选项] 文件”。
-f 表示跳过询问确认直接删除
-r表示删除目录
[root@Centos test]# ll
total 12
drwxr-xr-x. 3 root root 15 Aug 4 16:47 a
-rw-r--r--. 1 root root 122 Aug 4 16:58 aa.txt
-rw-r--r--. 1 root root 122 Aug 4 14:53 A.txt
-rw-r--r--. 1 root root 84 Aug 4 14:53 B.txt
drwxr-xr-x. 2 root root 6 Aug 4 16:46 xinghen1216
[root@Centos test]# rm -rf a
[root@Centos test]# ll
total 12
-rw-r--r--. 1 root root 122 Aug 4 16:58 aa.txt
-rw-r--r--. 1 root root 122 Aug 4 14:53 A.txt
-rw-r--r--. 1 root root 84 Aug 4 14:53 B.txt
drwxr-xr-x. 2 root root 6 Aug 4 16:46 xinghen1216
6.dd:按照指定大小和个数的数据块来复制文件或转换文件
Linux系统中有一个名为/dev/zero 的设备文件这个文件不会占用系统存储空间,但却可以提供无穷无尽的数据,因此可以使用它作为dd命令的输入文件,来生成一个指定大小的文件。

例如我们可以用dd 命令从/dev/zero 设备文件中取出一个大小为560MB 的数据块,然后保存成名为560_file 的文件。
[root@Centos test]# dd if=/dev/zero of=560_file count=1 bs=560M
1+0 records in
1+0 records out
587202560 bytes (587 MB) copied, 0.82832 s, 709 MB/s
[root@Centos test]# ll
total 573444
-rw-r--r--. 1 root root 587202560 Aug 4 17:21 560_file
-rw-r--r--. 1 root root 122 Aug 4 16:58 aa.txt
直接使用dd 命令来压制出光盘镜像文件,将它编程一个可立即使用的iso 镜像:
[root@Centos test]# dd if=/dev/cdrom of=centos-server-7.4.ios
8830976+0 records in
8830976+0 records out
4521459712 bytes (4.5 GB) copied, 111.594 s, 40.5 MB/s
7.file:查看文件的类型,格式为“file 文件名”。
[root@Centos test]# file aa.txt
aa.txt: ASCII text
[root@Centos test]# file xinghen1216
xinghen1216: directory
[root@Centos test]# file /dev/sda
/dev/sda: block special
8.tar对文件进行打包压缩或解压

常用:使用“tar -czvf 压缩包名称.tar.gz 要打包的目录”命令把指定的文件进行打包压缩;相应的解压命令为“tar -xzvf 压缩包名称.tar.gz”
[root@Centos test]# tar -czvf etc.tar.gz /etc
/etc/sane.d/hp5400.conf
/etc/sane.d/hpsj5s.conf
/etc/sane.d/leo.conf
。。。
[root@Centos test]# ll
total 11384
-rw-r--r--. 1 root root 122 Aug 4 16:58 aa.txt
-rw-r--r--. 1 root root 11651868 Aug 4 17:52 etc.tar.gz
drwxr-xr-x. 2 root root 6 Aug 4 17:42 xinghen1216
[root@Centos test]# cd ..
[root@Centos ~]# mkdir test01
[root@Centos ~]# tar -xzvf /root/test/etc.tar.gz -C /root/test01/
etc/smartmontools/smartd.conf
etc/smartmontools/smartd_warning.d/etc/sudoers.d/
etc/wgetrc
。。。
9.在文本中执行关键词搜索,并显示匹配的结果

在 Linux 系统中,/etc/passwd 文件是保存着所有的用户信息,而一旦用户的登录终端被设置成/sbin/nologin,则不再允许登录系统,因此可以使用grep 命令来查找出当前系统中不允许登录系统的所有用户信息:
[root@Centos etc]# grep -n /sbin/nologin /etc/passwd
2:bin:x:1:1:bin:/bin:/sbin/nologin
3:daemon:x:2:2:daemon:/sbin:/sbin/nologin
4:adm:x:3:4:adm:/var/adm:/sbin/nologin
10.find:按照指定条件来查找文件,格式为“find [查找路径] 寻找条件操作”

“-exec {} \;”参数,其中的{}表示find 命令搜索出的每一个文件,并且命令的结尾必须是“\;”。
举例:1)获取到/etc目录中所有以host 开头的文件列表
[root@Centos etc]# find /etc -name "host*" -print
/etc/host.conf
/etc/hosts
/etc/hosts.allow
/etc/hosts.deny
/etc/selinux/targeted/active/modules/100/hostname
/etc/hostname
/etc/avahi/hosts
2)在整个系统中搜索权限中包括SUID 权限的所有文件
[root@Centos etc]# find / -perm -4000 -print
find: ‘/proc/84104/task/84104/fd/6’: No such file or directory
find: ‘/proc/84104/task/84104/fdinfo/6’: No such file or directory
find: ‘/proc/84104/fd/6’: No such file or directory
find: ‘/proc/84104/fdinfo/6’: No such file or directory
/usr/bin/fusermount
/usr/bin/passwd
/usr/bin/chfn
3)在整个文件系统中找出所有归属于centos 用户的文件并复制到/root/findresults 目录
[root@Centos etc]# find / -user centos -exec cp -a {} /root/findresults/ \;
5. Linux文件目录管理和打包压缩与搜索命令的更多相关文章
- Linux 打包压缩与搜索命令
1.tar 用于对文件进行打包压缩或解压,格式为tar[选项][文件],-f参数必须放到参数最后一位 tar -czvf etc.tar.gz /etc tar参数及作用 参数 作用 -c 创建压缩文 ...
- linux打包压缩与搜索命令
1.tar命令 tar命令用于对文件进行打包压缩或解压,格式为“tar [选项] [文件]”. tar命令的参数及其作用 参数 作用 -c 创建压缩文件 -x 解开压缩文件 -t 查看压缩包内有哪些 ...
- Linux就该这么学——新手必须掌握的命令之打包压缩与搜索命令组
tar命令 用途 : 对文件进行打包或者解压 格式 : tar [选项] [文件] 表 tar命令的参数及作用 参数 作用 -c 创建压缩文件 -x 解开压缩文件 -t 查看压缩包内有哪些文件 -z ...
- Linux文件目录管理
Linux文件目录管理 文件的路径 路径: . 表示当此层目录 .. 表示上一层目录 - 代表前一个工作目录 ~ 代表"目前用户身份"所在的文件夹 ~account 代表accou ...
- Linux学习之路(三)搜索命令
1.文件搜索命令locate 2.命令搜索命令whereis与which 3.字符串搜索命令grep 4.find命令与grep命令的区别 locate命令相对于find命令搜索非常快,find命令在 ...
- Linux系类(8) - 文件搜索命令locate
文件搜索命令locate 命令格式 locate [文件名] 在后台数据库中按文件名搜索,搜索速度更快,而find.which是遍历所有目录去查找:后台数据库在/var/lib/mlocate (保存 ...
- linux下打包压缩和解压命令
.tar 压缩:tar cvf FileName.tar FileName 解压:tar xvf FileName.tar .gz解压1:gunzip FileName.gz解压2:gzip -d F ...
- Linux 文件目录管理的指令
1.知识点:绝对路径:写法从/(根目录开始) /usr/share/doc 相对路径:不从/开始 如cd ../man 如果清楚文件夹内部情况,建议使用相对路径在文件夹之间跳转,而不用绝对路径,每次 ...
- linux文件目录管理命令
1.touch命令 touch命令用于创建空白文件或设置文件的时间,格式为“touch [选项] [文件]”. touch test命令可以创建出一个名为test的空白文本文件 touch命令的参数 ...
随机推荐
- 《深入理解Java虚拟机》 Java对象的生命周期
Java虚拟机运行时数据区 方法区:存储 类信息.常量.静态变量.即使编译器编译后的代码等数据,也有别名叫做非堆. 方法区其中有包含有 运行时常量池,用于存放编译期生成的各种字面量和符号引用.其中, ...
- volatile 关键字精讲
1.错误案例 通过一个案例引出volatile关键字,例如以下代码示例 : 此时没有加volatile关键字两个线程间的通讯就会有问题 public class ThreadsShare { priv ...
- 我的开源项目在五个月内超过了 600 star
其实我在 2016 年年底就开始写了这个项目:Forest,一个能够将 HTTP 的所有请求信息(包括 URL .Header 以及 Body 等信息)绑定到您自定义的 Interface 方法上,能 ...
- 添加/删除/读写c盘文件——c#
一.前言: 有时候我们为自己的程序添加配置文件,如tet.ini.xml等文件,又或者保存软件运行时的日志 当我们把软件打包后,默认安装在c盘,而配置文件也会跟随生成在安装目录下 此时你会发现,配置文 ...
- AtCoder Beginner Contest 188 F - +1-1x2 思维题
题目描述 给你两个数 \(x\),\(y\) 可以对 \(x\) 进行 \(+1,-1\) 或 \(\times 2\) 的操作 问最少操作多少次后变为 \(y\) \(x,y \leq 10^{18 ...
- 十八般武艺玩转GaussDB(DWS)性能调优:SQL改写
摘要:本文将系统介绍在GaussDB(DWS)系统中影响性能的坏味道SQL及SQL模式,帮助大家能够从原理层面尽快识别这些坏味道SQL,在调优过程中及时发现问题,进行整改. 数据库的应用中,充斥着坏味 ...
- 如何优雅的传递 stl 容器作为函数参数来实现元素插入和遍历?
问题背景 开始正文之前,做一些背景铺垫,方便读者了解我的工程需求.我的项目是一个客户端消息分发中心,在连接上消息后台后,后台会不定时的给我推送一些消息,我再将它们转发给本机的其它桌面产品去做显示.后台 ...
- 魔法方法推开Python进阶学习大门
热爱Python Python是Guido van Rossum设计出来的让使用者觉得如沐春风的一门编程语言.2020年11月12日,64岁的Python之父宣布由于退休生活太无聊,自己决定加入Mic ...
- Java开发手册之异常日志
1.捕获异常的时候,有一种特殊情况,就是方法体内部所抛出的并不是Exception而是Error,这个时候,上层方法捕获Exception就会失败.所以在某些场合需要捕获更高一级别的Throwable ...
- CTFshow萌新赛-萌新福利
下载链接文件 拿到show.bin文件 使用010Editor工具打开文件 做取反操作 取反后可以看到 把show.bin改为show.m4a 使用音频播放软件播放,即可得到flag