一、复制、移动

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 -ls1551175      8 -rw-r--r--   1  root     root         4309 Oct 22 22:20 /test/sshd.conf1551169      4 -rw-r--r--   1  root     root         2617 Oct 22 22:30 /test/passwd34288565      4 -rw-r--r--   1  root     root         2548 Oct 23 14:45 /test/dir/passwd1551174      8 -rw-------   1  root     root         4269 Jul 12  2021 /test/dir/sshd.conf1551180      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.zipLength   Method    Size  Cmpr    Date    Time   CRC-32   Name
--------  ------  ------- ---- ---------- ----- --------  ----164  Defl:N      111  32% 10-22-2022 22:32 563ce98b  test/bashrc0  Stored        0   0% 10-23-2022 15:02 00000000  test/dir/137  Defl:N      109  20% 10-22-2022 21:33 d27e1bfc  test/file20  Defl:N       17  15% 10-22-2022 22:31 1e76fbd5  test/group22  Defl:N       21   5% 10-23-2022 14:58 48c50885  test/hostname158  Defl:N       56  65% 10-23-2022 14:56 6ab3fd78  test/hosts99  Defl:N       96   3% 10-22-2022 21:28 8878450c  test/motd.hard99  Defl:N       96   3% 10-22-2022 21:28 8878450c  test/motd.soft2617  Defl:N     1017  61% 10-22-2022 22:30 3aeb434f  test/passwd68  Defl:N       39  43% 10-22-2022 22:37 9fc7642d  test/profile4309  Defl:N     1967  54% 10-22-2022 22:20 9248bbe5  test/sshd.conf4269  Defl:N     1940  55% 10-23-2022 15:04 40610ac7  test/sshd_config0  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.zipinflating: /opt/test/bashrccreating: /opt/test/dir/inflating: /opt/test/fileinflating: /opt/test/groupinflating: /opt/test/hostnameinflating: /opt/test/hostsinflating: /opt/test/motd.hardinflating: /opt/test/motd.softinflating: /opt/test/passwdinflating: /opt/test/profileinflating: /opt/test/sshd.confinflating: /opt/test/sshd_configcreating: /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

Linux文件其他操作相关推荐

  1. linux文件测试操作

    1.文件测试操作 返回 true 如果... -e 文件存在 -a 文件存在 这个选项的效果与-e 相同.但是它已经被弃用了,并且不鼓励使用 -f file 是一个 regular 文件(不是目录或者 ...

  2. 嵌入式 Linux 文件IO操作

    目录 Linux 文件操作 1 Linux 系统环境文件操作概念 2 缓冲 IO 文件操作 1 文件的创建,打开与关闭 fopen 函数函数 2 freopen 函数 3.fdopen函数 4.fcl ...

  3. linux文件怎么操作,linux文件操作学习1

    由于实验室的项目需要开始学习linux,为了更好的学习和掌握linux的一些基本操作以及顺便做个备忘录,时间久了也可以看看自己的学习成果. 学习linux应该先抛开windows的C.D.E...盘的 ...

  4. Linux文件权限操作

    权限的意义在于允许某个用户或者某个组以规定的方式去访问某个文件 基本权限: U,G,O这三个字母所代表的意义 U:owner,属主 G:group,属组 O:other,其他用户 UGO方式 Linu ...

  5. linux文件编辑操作,Linux下文本编辑及其文件操作

    文本编辑及其文件操作 Vim 命令模式: dd 删除当前行 yy 2yy nyy 复制 从光标算起,复制n行 p 粘贴 默认粘贴在光标的下一行 u 撤销 末行模式: :wq 保存退出 :wq! 强制保 ...

  6. linux 文件路径操作

    查看文件&路径 ls 查看名称 ll 查看详细信息 移动文件&路径 命令格式 运行结果 mv 文件名 文件名 将源文件名改为目标文件名 mv 文件名 目录名 将文件移动到目标目录 mv ...

  7. Linux文件读取操作:read函数的使用

    read函数作用:读取文件内容,读取打开/创建(open)文件中写入(write)的内容. 包含的头文件: #include <unistd.h> 函数原型: ssize_t read(i ...

  8. linux文件查找操作

    1. 在当前目录及子目录中,查找大写字母开头的txt文件  指令:       $ find . -name '[A-Z]*.txt' -print 2.在/etc及其子目录中,查找host开头的文件 ...

  9. linux 遍历文件及文件夹,linux文件夹操作及递归遍历文件夹(示例代码)

    文件夹相关函数介绍 //mkdir 函数创建文件夹 #include #include int mkdir(const char *pathname, mode_t mode); //rmdir 删除 ...

  10. linux的文件io操作(转)

    linux文件IO操作有两套大类的操作方式:不带缓存的文件IO操作,带缓存的文件IO操作.不带缓存的属于直接调用系统调用(system call)的方式,高效完成文件输入输出.它以文件标识符(整型)作 ...

最新文章

  1. CTFshow php特性 web89
  2. Android Studio错误代码汇总
  3. 组合模式(Composition)
  4. CAP 3.0 版本正式发布
  5. IPhone之NSXMLParser的使用
  6. Angular环境配置及创建新的项目
  7. [CTO札记]社区领域模型-SRC抽象模型
  8. (转载)c#常用的资料
  9. 微信小程序源码打包合集 游戏商城抽奖转盘预约点餐等-1
  10. 3D MAX插件大全介绍
  11. js原型继承的几种方式
  12. element表格头部换行
  13. PHP Screw php代码解密,运用php screw进行源代码加密
  14. 数据之美(九):50个精美绝伦的 Infographics(上)
  15. 思科序列号无服务器,查看思科设备序列号以及序列号的命名格式
  16. 连续函数原函数(不定积分)存在定理证明
  17. ILI9341的使用之【八】ASCII字符显示及驱动分析
  18. php 微博获取粉丝,新浪API,提取微博账号的信息,粉丝数、微博数等
  19. pd调节规律_PD控制规律指的是比例、微分控制。
  20. 【数据分析】基于核主成分分析 (KPCA)实现 信号降维、重构、特征提取、故障检测附matlab代码

热门文章

  1. matlab生成指数分布,如何在matlab中生成负指数分布和均匀分布的随机数
  2. 一天狂点3.7万个赞! 男子因“点赞过多”被大众点评网处罚 法庭上吵翻
  3. hiveserver2 HA
  4. 国培 计算机远程培训心得,信息技术国培学习心得体会(2)
  5. MapGIS完美转ArcGIS ShapeFile攻略
  6. 手机b站封面提取网站_B端网站SEO优化思路:外链SEO与站内SEO优化结合才有效
  7. 计算机语言培训机构排行榜,TIOBE 2月编程语言排行榜
  8. 用html计算长方形的面积公式,长方形面积公式是什么
  9. Excel中对合并单元格后不同行数对应数据处理的三种特技
  10. 介绍一下什么是静态独享代理ip。