6.7总结与练习

这篇博客详细记录了在Linux环境中进行文件复制、移动、查找以及打包压缩的操作步骤。包括使用`cp`和`mv`命令在目录间复制和移动文件,使用`find`命令查找特定条件的文件,以及利用`zip`、`tar`和`gzip`进行文件压缩和解压。此外,还展示了如何在Windows和Linux之间通过SFTP进行文件传输。
摘要由CSDN通过智能技术生成

1、复制、移动
(1)在/test目录下创建一个子目录dir,将/etc/passwd复制到该目录

[root@server test]# mkdir /test/dir && cp -r /etc/passwd /test/dir/
[root@server test]# ll -i /test/dir/
total 4
1363097 -rw-r--r--. 1 root root 2545 Oct 23 09:12 passwd

(2)将/etc/ssh/sshd_config文件复制到/test目录

[root@server test]# cp -r /etc/ssh/sshd_config /test/
[root@server test]# ll /test/sshd_config 
-rw-r--r--. 1 root root 4269 Oct 23 09:14 /test/sshd_config

(3)将/etc/yum.repos.d/目录复制到/test目录

[root@server test]# cp /etc/yum.repos.d -r /test/
[root@server test]# ll /test/yum.repos.d/
total 4
-rw-r--r--. 1 root root 358 Oct 23 09:17 redhat.repo

(4)将/etc/hosts文件复制到/test目录

[root@server test]# cp /etc/hosts /test
[root@server test]# ll /test/hosts 
-rw-r--r--. 1 root root 158 Oct 23 09:18 /test/hosts

(5)将/etc/hostname文件复制到/test目录

[root@server test]# cp -r /etc/hostname /test/
[root@server test]# ll /test/hostname 
-rw-r--r--. 1 root root 13 Oct 23 09:19 /test/hostname

(6)将/test/sshd_config文件移动到/test/dir目录下并改名为sshd.conf

[root@server test]# mv /test/sshd_config /test/dir/sshd.conf
[root@server test]# ll /test/dir/sshd.conf
-rw-r--r--. 1 root root 4269 Oct 23 09:14 /test/dir/sshd.conf

2、文件查找
(1)在$HOME目录及其子目录中,查找2天前被更改过的文件

[root@server test]# find $HOME -mtime +2

(2)在/etc/目录下寻找以host开头的文件

[root@server test]# find /etc -name "host*"
/etc/host.conf
/etc/hosts
/etc/avahi/hosts
/etc/hostname
/etc/nvme/hostnqn
/etc/nvme/hostid

(3)在/test/下面查找目录文件

[root@server test]# find /test/ -type d | xargs ls -ld 
drwxr-xr-x. 4 root root 196 Oct 23 09:20 /test/
drwxr-xr-x. 2 root root  37 Oct 23 09:20 /test/dir
drwxr-xr-x. 2 root root  25 Oct 23 09:17 /test/yum.repos.d

(4)在/test目录及子目录中,查找超过2KB的文件

[root@server test]# find /test/ -size +2 |xargs ls -lh
-rw-r--r--. 1 root root 2.5K Oct 23 09:12 /test/dir/passwd
-rw-r--r--. 1 root root 4.2K Oct 23 09:14 /test/dir/sshd.conf
-rw-r--r--. 1 root root 2.6K Oct 21 10:55 /test/passwd
-rw-r--r--. 1 root root 4.2K Oct 21 08:03 /test/sshd.conf

3、打包压缩
(1)将/test目录下的所有文件和文件夹全部压缩成myfile.zip文件

[root@server test]# zip -r ./myfile.zip /test

(2)把myfile.zip文件解压到 /opt

[root@server test]# unzip -d /opt ./myfile.zip 

(3)将/opt目录下的文件全部打包并用gzip压缩成/test/newfile.tar.gz

[root@server test]# tar -zcvf /test/newfile.tar.gz /opt

(5)查看/test/newfile.tar.gz文件中有哪些文件?

[root@server test]# tar -tf /test/newfile.tar.gz

(6)将newfile.tar.gz下载至windows客户端主机

[C:\Users\LiAoYiNG\Desktop]$ sftp root@192.168.0.105 
sftp:/test> get /test/newfile.tar.gz ./
sftp:/> get /test/newfile.tar.gz ./
sftp: cannot open C:\Users\LiAoYiNG\Desktop to write!
Fetching /test/newfile.tar.gz to newfile.tar.gz
sftp: received 4.25 KB in 0.02 seconds

在这里插入图片描述

(7)在/test目录内,备份/etc下的所有文件并保留其权限

[root@server test]# tar -cvfp /test/test.tar  /etc
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值