归档及压缩、重定向与管道操作、创建链接

简介: 归档及压缩、重定向与管道操作、创建链接

一、归档及压缩

将零碎的文件整理为一个文件并压缩

压缩格式:速度最快,最常用gzip(.gz),bzip2(.bz2),速度最慢xz(.xz)

格式:tar   选项   /路径/压缩包名字   /源数据…….

-c:动作为创建

-f:指定压缩包名字(必须在所有选项最后)

-z、-j、-J:调用 .gz、.bz2、.xz 格式工具进行处理

tar命令 :

.gz : 压缩    #tar zcvf 压缩后的文件名 需要被压缩目录

      解压     #tar zxvf 需要被解压的文件  -C 指定解压后的路径

.bz2 : 压缩    #tar jcvf 压缩后的文件名 需要被压缩目录

      解压     #tar jxvf 需要被解压的文件  -C 指定解压后的路径

[root@localhost mnt]# tar zcvf etc.tar.gz  /etc    
[root@localhost mnt]# file etc.tar.gz 
[root@localhost mnt]# tar jcvf etc.tar.bz2  /etc   
[root@localhost mnt]# file etc.tar.bz2   
[root@localhost mnt]# tar jxvf etc.tar.bz2  -C /media/  
[root@localhost mnt]# tar zxvf etc.tar.gz  -C /media/

二、重定向与管道操作

管道:将前面命令的输出做为后面命令的输入

[root@localhost ~]# ls /etc/ | wc -l    //统计一下当前目录下有多少文件(行)

重定向:

改变系统的正常输出方向,不在屏幕显示.

>  输出重定向  

[root@localhost ~]# ls /etc/ > file1  //将前面命令输出写到file1里

>> 追加重定向    

[root@localhost ~]# tail -1 /etc/passwd //查看文件最后一行
  [root@localhost ~]# head -1 /etc/passwd //查看文件的第一行
  [root@localhost ~]# tail -1 /etc/passwd  >> file1  //追加重定向,不覆盖

2> 错误重定向

[root@localhost mnt]# touch a   //新建文件a
    [root@localhost mnt]# ls
    a  hgfs
    [root@localhost mnt]# ls a b 
    ls: cannot access 'b': No such file or directory
    a
    [root@localhost mnt]# ls a b  > file1
    ls: cannot access 'b': No such file or directory
    [root@localhost mnt]# ls a b  2> file1
    a

三、创建链接

ln 为文件或目录建立链接(Link)

-s 创建软链接

不带-s选项创建硬链接

[root@localhost mnt]# ln file2 a
[root@localhost mnt]# ls -l
total 4612
-rw-r--r--. 2 root root       0 Mar 12 14:52 a              //硬链接
-rw-r--r--. 2 root root       0 Mar 12 14:52 file2
[root@localhost mnt]# ln -s file2 b
[root@localhost mnt]# ls -l
total 4612
-rw-r--r--. 2 root root       0 Mar 12 14:52 a
lrwxrwxrwx. 1 root root       5 Mar 12 15:43 b -> file2    //软链接
-rw-r--r--. 2 root root       0 Mar 12 14:52 file2
[root@localhost mnt]# rm -f file2
[root@localhost mnt]# ls -l
total 4612
-rw-r--r--. 1 root root       0 Mar 12 14:52 a      //不受影响
lrwxrwxrwx. 1 root root       5 Mar 12 15:43 b -> file2   //警告提示
相关文章
|
人工智能 监控 机器人
【Valgrind】如何使用Valgrind监控内存
【Valgrind】如何使用Valgrind监控内存
|
存储 SQL 关系型数据库
MySQL主键约束详解
MySQL是一个强大的关系型数据库管理系统,用于存储和管理大量数据。在数据库中,主键约束是一项非常重要的概念,它有助于确保数据的完整性和唯一性。本文将详细介绍MySQL主键约束,包括什么是主键、为什么需要主键、如何创建主键以及主键的最佳实践。
1080 1
|
存储 缓存 NoSQL
MongoDB内部的存储原理
这篇文章详细介绍了MongoDB的内部存储原理,包括存储引擎WiredTiger的架构、btree与b+tree的比较、cache机制、page结构、写操作流程、checkpoint和WAL日志,以及分布式存储的架构。
840 1
MongoDB内部的存储原理
|
Python
Python中的模块对象__package__
【6月更文挑战第13天】
199 5
|
Shell
shell获取命令输出和返回值
shell获取命令输出和返回值
2621 0
|
存储 关系型数据库 MySQL
MySQL 如何查看每个分区的数据量
MySQL 如何查看每个分区的数据量
637 3
|
存储 算法 Linux
.bz2是什么格式的文件?Linux如何解压这种类型的文件?
【8月更文挑战第3天】.bz2是什么格式的文件?Linux如何解压这种类型的文件?
2347 1
|
存储 关系型数据库 MySQL
[mysql]MGR简介与部署
[mysql]MGR简介与部署
334 1
使用delve调试golang
使用delve调试golang
200 0
|
安全 Shell Linux
【Shell 命令集合 系统设置 】Linux 创建一个与主系统分离的独立的运行环境 chroot命令 使用指南
【Shell 命令集合 系统设置 】Linux 创建一个与主系统分离的独立的运行环境 chroot命令 使用指南
290 0