一、复制、移动
1、在/test目录下创建一个子目录dir,将/etc/passwd复制到该目录
[root@localhost test]# mkdir dir
[root@localhost test]# cp /etc/passwd /test/dir
2、将/etc/ssh/sshd_config文件复制到/test目录
[root@localhost test]# cp /etc/ssh/sshd_config /test
3、将/etc/yum.repos.d/目录复制到/test目录
[root@localhost test]# cp -a /etc/yum.repos.d/ /test
4、将/etc/hosts文件复制到/test目录
[root@localhost test]# cp /etc/hosts /test
5、将/etc/hostname文件复制到/test目录
[root@localhost test]# cp /etc/hostname /test
6、将/test/sshd_config文件移动到/test/dir目录下并改名为sshd.conf
[root@localhost test]# mv /test/sshd_config /test/dir/sshd.conf
二、文件查找
1、在$HOME目录及其子目录中,查找2天前被更改过的文件
[root@localhost ~]# find -mtime -2 -type f -print
./anaconda-ks.cfg
./.cache/dconf/user
./.cache/tracker/db-version.txt
./.cache/tracker/meta.db
./.cache/tracker/db-locale.txt
2、在/etc/目录下寻找以host开头的文件
[root@localhost ~]# find /etc -name "host*" -type f -print
/etc/host.conf
/etc/hosts
/etc/avahi/hosts
/etc/hostname
/etc/nvme/hostnqn
/etc/nvme/hostid
3、在/test/下面查找目录文件
[root@localhost ~]# find /test -type d -print
/test
/test/dir
/test/yum.repos.d
4、在/test目录及子目录中,查找超过2KB的文件
[root@localhost ~]# find /test -size +2k -ls
1551175 8 -rw-r--r-- 1 root root 4309 Oct 22 22:20 /test/sshd.conf
1551169 4 -rw-r--r-- 1 root root 2617 Oct 22 22:30 /test/passwd
34288565 4 -rw-r--r-- 1 root root 2548 Oct 23 14:45 /test/dir/passwd
1551174 8 -rw------- 1 root root 4269 Jul 12 2021 /test/dir/sshd.conf
1551180 8 -rw------- 1 root root 4269 Oct 23 15:04 /test/sshd_config
三、打包压缩
1、将/test目录下的所有文件和文件夹全部压缩成myfile.zip文件
[root@localhost ~]# zip myfile.zip /test/*
adding: test/bashrc (deflated 32%)
adding: test/dir/ (stored 0%)
adding: test/file (deflated 20%)
adding: test/group (deflated 15%)
adding: test/hostname (deflated 5%)
adding: test/hosts (deflated 65%)
adding: test/motd.hard (deflated 3%)
adding: test/motd.soft (deflated 3%)
adding: test/passwd (deflated 61%)
adding: test/profile (deflated 43%)
adding: test/sshd.conf (deflated 54%)
adding: test/sshd_config (deflated 55%)
adding: test/yum.repos.d/ (stored 0%)
[root@localhost ~]# unzip -v myfile.zip
Archive: myfile.zip
Length Method Size Cmpr Date Time CRC-32 Name
-------- ------ ------- ---- ---------- ----- -------- ----
164 Defl:N 111 32% 10-22-2022 22:32 563ce98b test/bashrc
0 Stored 0 0% 10-23-2022 15:02 00000000 test/dir/
137 Defl:N 109 20% 10-22-2022 21:33 d27e1bfc test/file
20 Defl:N 17 15% 10-22-2022 22:31 1e76fbd5 test/group
22 Defl:N 21 5% 10-23-2022 14:58 48c50885 test/hostname
158 Defl:N 56 65% 10-23-2022 14:56 6ab3fd78 test/hosts
99 Defl:N 96 3% 10-22-2022 21:28 8878450c test/motd.hard
99 Defl:N 96 3% 10-22-2022 21:28 8878450c test/motd.soft
2617 Defl:N 1017 61% 10-22-2022 22:30 3aeb434f test/passwd
68 Defl:N 39 43% 10-22-2022 22:37 9fc7642d test/profile
4309 Defl:N 1967 54% 10-22-2022 22:20 9248bbe5 test/sshd.conf
4269 Defl:N 1940 55% 10-23-2022 15:04 40610ac7 test/sshd_config
0 Stored 0 0% 10-22-2022 21:30 00000000 test/yum.repos.d/
-------- ------- --- -------
11962 5469 54% 13 files
2、把myfile.zip文件解压到 /opt
[root@localhost ~]# unzip myfile.zip -d /opt
Archive: myfile.zip
inflating: /opt/test/bashrc
creating: /opt/test/dir/
inflating: /opt/test/file
inflating: /opt/test/group
inflating: /opt/test/hostname
inflating: /opt/test/hosts
inflating: /opt/test/motd.hard
inflating: /opt/test/motd.soft
inflating: /opt/test/passwd
inflating: /opt/test/profile
inflating: /opt/test/sshd.conf
inflating: /opt/test/sshd_config
creating: /opt/test/yum.repos.d/
3、将/opt目录下的文件全部打包并用gzip压缩成/test/newfile.tar.gz
[root@localhost opt]# tar -czf /test/newfile.tar.gz ./
4、查看/test/newfile.tar.gz文件中有哪些文件
[root@localhost ~]# tar tvf /test/newfile.tar.gz
drwxr-xr-x root/root 0 2022-10-23 15:32 ./
drwxr-xr-x root/root 0 2022-10-23 15:32 ./test/
-rw-r--r-- root/root 164 2022-10-22 22:32 ./test/bashrc
drwxr-xr-x root/root 0 2022-10-23 15:02 ./test/dir/
-rw-r--r-- root/root 137 2022-10-22 21:33 ./test/file
-rw-r--r-- root/root 20 2022-10-22 22:31 ./test/group
-rw-r--r-- root/root 22 2022-10-23 14:58 ./test/hostname
-rw-r--r-- root/root 158 2022-10-23 14:56 ./test/hosts
-rw-r--r-- root/root 99 2022-10-22 21:28 ./test/motd.hard
-rw-r--r-- root/root 99 2022-10-22 21:28 ./test/motd.soft
-rw-r--r-- root/root 2617 2022-10-22 22:30 ./test/passwd
-rw-r--r-- root/root 68 2022-10-22 22:37 ./test/profile
-rw-r--r-- root/root 4309 2022-10-22 22:20 ./test/sshd.conf
-rw------- root/root 4269 2022-10-23 15:04 ./test/sshd_config
drwxr-xr-x root/root 0 2022-10-22 21:30 ./test/yum.repos.d/
5、将newfile.tar.gz下载至windows客户端主机
6、在/test目录内,备份/etc下的所有文件并保留其权限
[root@localhost test]# tar -cvf etc.tar /etc