Linux常用指令/命令总结

目录

ls指令

cd指令

pwd指令

创建/删除文件

touch指令

mkdir指令

rm指令/rmdir指令

复制/粘贴/剪切文件 

cp指令

mv指令

查看文件内容

cat指令

more指令

less指令

head指令

tail指令

Q:如何查看某个文件第50-60行的代码 

时间相关 

date指令

cal指令

寻找文件

find指令

其他

grep指令

zip/unzip指令

tar指令


ls指令

语法 ls [ 选项][目录 或文件 ]
功能 :对于目录,该命令列出该目录下的所有子目录与文件。对于文件,将列出文件名以及其他信息。
常用选项:
-a 列出目录下的所有文件,包括以 . 开头的隐含文件。
-d 将目录像文件一样显示,而不是显示其下的文件。 如:ls –d 指定目录
-l 列出文件的详细信息。(ls -l ,可以简写为ll)
-R 列出所有子目录下的文件。(递归)
-1 一行只输出一个文件
[zebra@VM-8-12-centos test]$ ls -a
.  ..  a.out  hello.c  h_static
[zebra@VM-8-12-centos test]$ ls -l
total 28
-rwxrwxr-x 1 zebra zebra 8360 Oct 22 15:01 a.out
-rw-rw-r-- 1 zebra zebra  427 Oct 22 19:50 hello.c
-rwxrwxr-x 1 zebra zebra 9384 Oct 22 23:19 h_static
[zebra@VM-8-12-centos test]$ ll
total 28
-rwxrwxr-x 1 zebra zebra 8360 Oct 22 15:01 a.out
-rw-rw-r-- 1 zebra zebra  427 Oct 22 19:50 hello.c
-rwxrwxr-x 1 zebra zebra 9384 Oct 22 23:19 h_static
[zebra@VM-8-12-centos test]$ ls -al
total 36
drwxrwxr-x 2 zebra zebra 4096 Oct 22 23:19 .
drwxrwxr-x 3 zebra zebra 4096 Oct 22 15:00 ..
-rwxrwxr-x 1 zebra zebra 8360 Oct 22 15:01 a.out
-rw-rw-r-- 1 zebra zebra  427 Oct 22 19:50 hello.c
-rwxrwxr-x 1 zebra zebra 9384 Oct 22 23:19 h_static
[zebra@VM-8-12-centos test]$ ls -R
.:
a.out  hello.c  h_static
[zebra@VM-8-12-centos test]$ ls -1
a.out
hello.c
h_static

cd指令

语法 :cd 目录名
功能 :改变工作目录。将当前工作目录改变到指定的目录下。
  • cd -

可以返回最近一次访问的目录

比如我从zebra cd /到root,然后我cd-可以回到zebra,再cd-又会到root,可以来回切换。

  • cd / 直接到根目录
  • cd ~ 进入当前的用户目录(~就表示当前用户的工作目录
[zebra@VM-8-12-centos test]$ pwd
/home/zebra/code/test
[zebra@VM-8-12-centos test]$ cd ..
[zebra@VM-8-12-centos code]$ pwd
/home/zebra/code
[zebra@VM-8-12-centos code]$ cd test
[zebra@VM-8-12-centos test]$ pwd
/home/zebra/code/test
[zebra@VM-8-12-centos ~]$ cd ~
[zebra@VM-8-12-centos ~]$ pwd
/home/zebra
[zebra@VM-8-12-centos ~]$ cd code
[zebra@VM-8-12-centos code]$ pwd
/home/zebra/code
[zebra@VM-8-12-centos code]$ cd -
/home/zebra
[zebra@VM-8-12-centos ~]$ cd -
/home/zebra/code
[zebra@VM-8-12-centos code]$ cd /
[zebra@VM-8-12-centos /]$ pwd
/

pwd指令

语法 : pwd
功能 :显示用户当前所在的目录

创建/删除文件

touch指令

语法 :touch [ 选项 ]...  文件 ...
功能 touch 命令可以创建文件,或者更改文档或目录的日期时间,包括存取时间和更改时间
常用选项
-a    --time=atime --time=access --time=use 只更改存取时间。
-c    --no-create  不建立任何文档。
-m    --time=mtime --time=modify  只更改变动时间。
-d  使用指定的日期时间,而非现在的时间 
  • stat指令 

可以查看文件的访问时间,修改时间和状态时间

1. Access Time:简写为atime,表示文件的访问时间。当文件内容被访问时,更新这个时间

2. Modify Time:简写为mtime,表示文件内容的修改时间,当文件的数据内容被修改时,更新这个时间。

3. Change Time:简写为ctime,表示文件的状态时间,当文件的状态被修改时,更新这个时间,例如文件的链接数,大小,权限,Blocks数。

[zebra@VM-8-12-centos test]$ ll
total 28
-rwxrwxr-x 1 zebra zebra 8360 Oct 22 15:01 a.out
-rw-rw-r-- 1 zebra zebra  427 Oct 22 19:50 hello.c
-rwxrwxr-x 1 zebra zebra 9384 Oct 22 23:19 h_static
[zebra@VM-8-12-centos test]$ touch test.c
[zebra@VM-8-12-centos test]$ ll
total 28
-rwxrwxr-x 1 zebra zebra 8360 Oct 22 15:01 a.out
-rw-rw-r-- 1 zebra zebra  427 Oct 22 19:50 hello.c
-rwxrwxr-x 1 zebra zebra 9384 Oct 22 23:19 h_static
-rw-rw-r-- 1 zebra zebra    0 Oct 23 12:38 test.c
[zebra@VM-8-12-centos test]$ touch test.c -a
[zebra@VM-8-12-centos test]$ ll
total 28
-rwxrwxr-x 1 zebra zebra 8360 Oct 22 15:01 a.out
-rw-rw-r-- 1 zebra zebra  427 Oct 22 19:50 hello.c
-rwxrwxr-x 1 zebra zebra 9384 Oct 22 23:19 h_static
-rw-rw-r-- 1 zebra zebra    0 Oct 23 12:38 test.c
[zebra@VM-8-12-centos test]$ stat test.c 
  File: ‘test.c’
  Size: 0         	Blocks: 0          IO Block: 4096   regular empty file
Device: fd01h/64769d	Inode: 656824      Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1001/   zebra)   Gid: ( 1001/   zebra)
Access: 2022-10-23 12:38:59.639680719 +0800
Modify: 2022-10-23 12:38:48.163672989 +0800
Change: 2022-10-23 12:38:59.639680719 +0800
 Birth: -
[zebra@VM-8-12-centos test]$ touch test.c
[zebra@VM-8-12-centos test]$ stat test.c 
  File: ‘test.c’
  Size: 0         	Blocks: 0          IO Block: 4096   regular empty file
Device: fd01h/64769d	Inode: 656824      Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1001/   zebra)   Gid: ( 1001/   zebra)
Access: 2022-10-23 12:40:37.740746795 +0800
Modify: 2022-10-23 12:40:37.740746795 +0800
Change: 2022-10-23 12:40:37.740746795 +0800
 Birth: -
[zebra@VM-8-12-centos test]$ 

 mkdir指令

语法 mkdir [ 选项 ] dirname...
功能 :在当前目录下创建一个名为 “dirname” 的目录
常用选项
-p, --parents   可以是一个路径名称。此时若路径中的某些目录尚不存在 , 加上此选项后 , 系统将自动建立好那些尚不存在的目录, 即一次可以建立多个目录 ;
[zebra@VM-8-12-centos test]$ ll
total 28
-rwxrwxr-x 1 zebra zebra 8360 Oct 22 15:01 a.out
-rw-rw-r-- 1 zebra zebra  427 Oct 22 19:50 hello.c
-rwxrwxr-x 1 zebra zebra 9384 Oct 22 23:19 h_static
-rw-rw-r-- 1 zebra zebra    0 Oct 23 12:40 test.c
[zebra@VM-8-12-centos test]$ mkdir new
[zebra@VM-8-12-centos test]$ ll
total 32
-rwxrwxr-x 1 zebra zebra 8360 Oct 22 15:01 a.out
-rw-rw-r-- 1 zebra zebra  427 Oct 22 19:50 hello.c
-rwxrwxr-x 1 zebra zebra 9384 Oct 22 23:19 h_static
drwxrwxr-x 2 zebra zebra 4096 Oct 23 12:43 new
-rw-rw-r-- 1 zebra zebra    0 Oct 23 12:40 test.c
[zebra@VM-8-12-centos test]$ mkdir new2/new3/new4
mkdir: cannot create directory ‘new2/new3/new4’: No such file or directory
[zebra@VM-8-12-centos test]$ mkdir new2/new3/new4 -p
[zebra@VM-8-12-centos test]$ ll
total 36
-rwxrwxr-x 1 zebra zebra 8360 Oct 22 15:01 a.out
-rw-rw-r-- 1 zebra zebra  427 Oct 22 19:50 hello.c
-rwxrwxr-x 1 zebra zebra 9384 Oct 22 23:19 h_static
drwxrwxr-x 2 zebra zebra 4096 Oct 23 12:43 new
drwxrwxr-x 3 zebra zebra 4096 Oct 23 12:43 new2
-rw-rw-r-- 1 zebra zebra    0 Oct 23 12:40 test.c
[zebra@VM-8-12-centos test]$ tree new2
new2
`-- new3
    `-- new4

2 directories, 0 files

rm指令/rmdir指令

rmdir 是一个与 mkdir 相对应的命令。 mkdir 是建立目录,而 rmdir 是删除命令。
语法 rmdir [-p][dirName]
适用对象 :具有当前目录操作权限的所有使用者
功能 :删除 目录(注意只能删除空目录)
rm 命令可以同时删除文件或目录
语法 rm [-f-i-r-v][dirName/dir]
适用对象 :所有使用者
功能 :删除文件或目录
常用选项
-f 即使文件属性为只读 ( 即写保护 ) ,也直接删除,f是force的意思,强制删除
-i 删除前逐一询问确认
-r 删除目录及其下所有文件(递归删除)
[zebra@VM-8-12-centos test]$ ll
total 36
-rwxrwxr-x 1 zebra zebra 8360 Oct 22 15:01 a.out
-rw-rw-r-- 1 zebra zebra  427 Oct 22 19:50 hello.c
-rwxrwxr-x 1 zebra zebra 9384 Oct 22 23:19 h_static
drwxrwxr-x 2 zebra zebra 4096 Oct 23 12:43 new
drwxrwxr-x 3 zebra zebra 4096 Oct 23 12:43 new2
-rw-rw-r-- 1 zebra zebra    0 Oct 23 12:40 test.c
[zebra@VM-8-12-centos test]$ rmdir new
[zebra@VM-8-12-centos test]$ rmdir new2
rmdir: failed to remove ‘new2’: Directory not empty
[zebra@VM-8-12-centos test]$ ll
total 32
-rwxrwxr-x 1 zebra zebra 8360 Oct 22 15:01 a.out
-rw-rw-r-- 1 zebra zebra  427 Oct 22 19:50 hello.c
-rwxrwxr-x 1 zebra zebra 9384 Oct 22 23:19 h_static
drwxrwxr-x 3 zebra zebra 4096 Oct 23 12:43 new2
-rw-rw-r-- 1 zebra zebra    0 Oct 23 12:40 test.c
[zebra@VM-8-12-centos test]$ rm new2 -r
[zebra@VM-8-12-centos test]$ ll
total 28
-rwxrwxr-x 1 zebra zebra 8360 Oct 22 15:01 a.out
-rw-rw-r-- 1 zebra zebra  427 Oct 22 19:50 hello.c
-rwxrwxr-x 1 zebra zebra 9384 Oct 22 23:19 h_static
-rw-rw-r-- 1 zebra zebra    0 Oct 23 12:40 test.c
[zebra@VM-8-12-centos test]$ rm test.c
[zebra@VM-8-12-centos test]$ ll
total 28
-rwxrwxr-x 1 zebra zebra 8360 Oct 22 15:01 a.out
-rw-rw-r-- 1 zebra zebra  427 Oct 22 19:50 hello.c
-rwxrwxr-x 1 zebra zebra 9384 Oct 22 23:19 h_static
[zebra@VM-8-12-centos test]$ 

复制/粘贴/剪切文件 

 cp指令

语法 cp [ 选项 ] 源文件或目录 目标文件或目录
功能 : 复制文件或目录
说明 : cp 指令用于复制文件或目录,如同时指定两个以上的文件或目录,且最后的目的地是一个已经存在的目录, 则它会把前面指定的所有文件或目录复制到此目录中。若同时指定多个文件或目录,而最后的目的地并非一个已存在的目录,则会报错。
常用选项
-f --force  强行复制文件或目录, 不论目的文件或目录是否已经存在
-r  递归处理,将指定目录下的文件与子目录一并处理。
[zebra@VM-8-12-centos test]$ ll
total 28
-rwxrwxr-x 1 zebra zebra 8360 Oct 22 15:01 a.out
-rw-rw-r-- 1 zebra zebra  427 Oct 22 19:50 hello.c
-rwxrwxr-x 1 zebra zebra 9384 Oct 22 23:19 h_static
[zebra@VM-8-12-centos test]$ cp hello.c hellocp.c
[zebra@VM-8-12-centos test]$ ll
total 32
-rwxrwxr-x 1 zebra zebra 8360 Oct 22 15:01 a.out
-rw-rw-r-- 1 zebra zebra  427 Oct 22 19:50 hello.c
-rw-rw-r-- 1 zebra zebra  427 Oct 23 13:07 hellocp.c
-rwxrwxr-x 1 zebra zebra 9384 Oct 22 23:19 h_static

 

mv指令

1. mv 命令中第二个参数类型的不同(是目标文件还是目标目录), mv
mv 命令是 move 的缩写,可以用来 移动文件或者修改文件改名 move (rename) fifiles ),是 Linux 系统下常用的 命令,经常用来备份文件或者目录。
语法 : mv [ 选项 源文件或目录 目标文件或目录
功能 :
  • 1.视mv命令中第二个参数类型的不同(是目标文件还是目标目录),mv命令将文件重命名或将其移至一个新的 目录中。
  • 2. 当第二个参数类型是文件时,mv命令完成文件重命名,此时,源文件只能有一个(也可以是源目录名),它将所给的源文件或目录重命名为给定的目标文件名。
  • 3. 当第二个参数是已存在的目录名称时,源文件或目录参数可以有多个,mv命令将各参数指定的源文件均移至目标目录中。

-f  force  强制的意思,如果目标文件已经存在,不会询问而直接覆盖
-i  :若目标文件  (destination)  已经存在时,就会询问是否覆盖!
[zebra@VM-8-12-centos test]$ ll
total 32
-rwxrwxr-x 1 zebra zebra 8360 Oct 22 15:01 a.out
-rw-rw-r-- 1 zebra zebra  427 Oct 22 19:50 hello.c
-rw-rw-r-- 1 zebra zebra  427 Oct 23 13:08 hellocp.c
-rwxrwxr-x 1 zebra zebra 9384 Oct 22 23:19 h_static
[zebra@VM-8-12-centos test]$ mv hello.c ..
[zebra@VM-8-12-centos test]$ cd ..
[zebra@VM-8-12-centos code]$ ll
total 8
-rw-rw-r-- 1 zebra zebra  427 Oct 22 19:50 hello.c
drwxrwxr-x 2 zebra zebra 4096 Oct 23 13:08 test
[zebra@VM-8-12-centos code]$ ^C
[zebra@VM-8-12-centos code]$ 

查看文件内容

cat指令

语法 cat [ 选项 ][ 文件 ]
功能 : 查看目标文件的内容
常用选项:
-b 对非空输出行编号
-n 对输出的所有行编号
-s 不输出多行空行
  •  tac指令

按行反向输出,选项和cat一样

[zebra@VM-8-12-centos code]$ ll
total 8
-rw-rw-r-- 1 zebra zebra  427 Oct 22 19:50 hello.c
drwxrwxr-x 2 zebra zebra 4096 Oct 23 13:08 test
[zebra@VM-8-12-centos code]$ cat hello.c 
#include<stdio.h>
int main() {
    printf("hello vim");
    printf("hello vim");
    printf("hello vim");
    printf("hello vim");
    printf("hello vim");
    printf("jj6k");
    printf("hello vim");
    printf("hello vim");
    printf("jj6k");
    printf("hello vim");
    printf("hello vim");
    printf("jj6k");
    printf("hello vim");
    printf("hello vim");
    printf("jj6k");
    printf("hello vim");
    return 0;
}
[zebra@VM-8-12-centos code]$ cat hello.c -n
     1	#include<stdio.h>
     2	int main() {
     3	    printf("hello vim");
     4	    printf("hello vim");
     5	    printf("hello vim");
     6	    printf("hello vim");
     7	    printf("hello vim");
     8	    printf("jj6k");
     9	    printf("hello vim");
    10	    printf("hello vim");
    11	    printf("jj6k");
    12	    printf("hello vim");
    13	    printf("hello vim");
    14	    printf("jj6k");
    15	    printf("hello vim");
    16	    printf("hello vim");
    17	    printf("jj6k");
    18	    printf("hello vim");
    19	    return 0;
    20	}
[zebra@VM-8-12-centos code]$ 
[zebra@VM-8-12-centos code]$ tac hello.c 
}
    return 0;
    printf("hello vim");
    printf("jj6k");
    printf("hello vim");
    printf("hello vim");
    printf("jj6k");
    printf("hello vim");
    printf("hello vim");
    printf("jj6k");
    printf("hello vim");
    printf("hello vim");
    printf("jj6k");
    printf("hello vim");
    printf("hello vim");
    printf("hello vim");
    printf("hello vim");
    printf("hello vim");
int main() {
#include<stdio.h>

more指令

语法 more [ 选项 ][ 文件 ]
功能 more 命令,功能类似 cat 分批显示文件内容,-n表示显示n行,默认是显示
满整个屏幕;之后要继续查看就按回车。
常用选项
-n 对输出的所有行编号
q 退出 more
[zebra@VM-8-12-centos code]$ more -3 hello.c
#include<stdio.h>
int main() {
    printf("hello vim");

 less指令

语法: less [ 参数 ] 文件
功能
less more 类似,但使用 less 可以随意浏览文件,而 more 仅能向前移动,却不能向后移动,而且 less 在查看之前不会加载整个文件。
选项
-i   忽略搜索时的大小写
-N   显示每行的行号
/ 字符串:向下搜索 字符串 的功能
? 字符串:向上搜索 字符串 的功能
n :重复前一个搜索(与  /   ?  有关)
N :反向重复前一个搜索(与  /   ?  有关)
q: quit

head指令

语法: head [ 参数 ]... [ 文件 ]... 
功能
head  用来显示档案的开头至标准输出中,默认 head 命令打印其相应文件的开头 10 行。 
选项
-n< 行数 显示的行数

 

tail指令

语法: tail[ 必要参数 ][ 选择参数 ][ 文件
功能: 用于显示指定文件末尾内容,不指定文件时,作为输入信息进行处理。常用查看日志文件。
选项:
-n< 行数 显示的行数
[zebra@VM-8-12-centos code]$ head -5N hello.c
head: invalid trailing option -- N
Try 'head --help' for more information.
[zebra@VM-8-12-centos code]$ head -5 hello.c
#include<stdio.h>
int main() {
    printf("hello vim");
    printf("zebra 666");
    printf("zebra 666");
[zebra@VM-8-12-centos code]$ tail -5 hello.c
    printf("hello vim");
    printf("jj6k");
    printf("hello vim");
    return 0;
}
[zebra@VM-8-12-centos code]$ 

Q:如何查看某个文件第50-60行的代码 

方法一:将head的结果重定向到一个tmp文件中,然后再执行tail指令

[zebra@VM-8-12-centos code]$ head -60 hello.c > temp.txt
[zebra@VM-8-12-centos code]$ ll
total 36
-rw-rw-r-- 1 zebra zebra 25552 Oct 23 13:17 hello.c
-rw-rw-r-- 1 zebra zebra  1481 Oct 23 16:03 temp.txt
drwxrwxr-x 2 zebra zebra  4096 Oct 23 13:08 test
[zebra@VM-8-12-centos code]$ tail -10 temp.txt
    printf("zebra 666");
    printf("zebra 666");
    printf("zebra 666");
    printf("zebra 666");
    printf("zebra 666");
    printf("zebra 666");
    printf("zebra 666");
    printf("zebra 666");
    printf("zebra 666");
    printf("zebra 666");

方法二:使用管道,将head指令的结果通过管道给到tail指令

[zebra@VM-8-12-centos code]$ head -60 hello.c | tail -10
    printf("zebra 666");
    printf("zebra 666");
    printf("zebra 666");
    printf("zebra 666");
    printf("zebra 666");
    printf("zebra 666");
    printf("zebra 666");
    printf("zebra 666");
    printf("zebra 666");
    printf("zebra 666");

时间相关 

date指令

date 指定格式显示时间: date +%Y:%m:%d 中间的:可以改成任何内容,比如kkkk
date 用法: date [OPTION]... [+FORMAT]
选项
%H : 小时 (00..23)
%M : 分钟 (00..59)
%S : (00..61)
%X : 相当于 %H:%M:%S
%d : (01..31)
%m : 月份 (01..12)
%Y : 完整年份 (0000..9999)
%F : 相当于 %Y-%m-%d

时间戳 :

时间 -> 时间戳: date +%s ,将当前时间换算成时间戳显示
时间戳 -> 时间: date -d@1508749502 ,将1508749502这个时间戳换算成年月日时分秒的格式
Unix 时间戳(英文为 Unix epoch, Unix time, POSIX time Unix timestamp )是 1970 1 1 日( UTC/GMT 的 午夜,对应中国的北京时间是早上8:00,中国的机器是从8:00开始算的)开始所经过的秒数,不考虑闰秒。
[zebra@VM-8-12-centos code]$ date
Sun Oct 23 15:57:38 CST 2022
[zebra@VM-8-12-centos code]$ clear
[zebra@VM-8-12-centos code]$ date
Sun Oct 23 15:57:44 CST 2022
[zebra@VM-8-12-centos code]$ date +%Y:%m:%d
2022:10:23
[zebra@VM-8-12-centos code]$ date +%s
1666511908

cal指令

命令格式 cal [ 参数 ][ 月份 ][ 年份 ]
功能 : 用于查看日历等时间信息,如只有一个参数,则表示年份 (1-9999) ,如有两个参数,则表示月份和年份
常用选项
-3  显示系统前一个月,当前月,下一个月的月历
-j   显示在当年中的第几天(一年日期按天算,从 1 1 号算起,默认显示当前月在一年中的天数)
-y   显示当前年份的日历
[zebra@VM-8-12-centos code]$ cal
    October 2022    
Su Mo Tu We Th Fr Sa
                   1
 2  3  4  5  6  7  8
 9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31
[zebra@VM-8-12-centos code]$ cal -3
   September 2022         October 2022          November 2022   
Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa
             1  2  3                     1         1  2  3  4  5
 4  5  6  7  8  9 10   2  3  4  5  6  7  8   6  7  8  9 10 11 12
11 12 13 14 15 16 17   9 10 11 12 13 14 15  13 14 15 16 17 18 19
18 19 20 21 22 23 24  16 17 18 19 20 21 22  20 21 22 23 24 25 26
25 26 27 28 29 30     23 24 25 26 27 28 29  27 28 29 30         
                      30 31                                     
[zebra@VM-8-12-centos code]$ cal -j
        October 2022       
Sun Mon Tue Wed Thu Fri Sat
                        274
275 276 277 278 279 280 281
282 283 284 285 286 287 288
289 290 291 292 293 294 295
296 297 298 299 300 301 302
303 304

寻找文件

find指令

语法: fifind pathname -options
功能: 用于在文件树种查找文件,并作出相应的处理(可能访问磁盘)
常用选项:
-name   按照文件名查找文件。
[zebra@VM-8-12-centos /]$ find -name hello.c
./tmp/cquery/cache/@home@zebra@code/hello.c
./tmp/cquery/cache/@home@zebra@code@test/hello.c

其他

grep指令

语法: grep [ 选项 ] 搜寻字符串 文件
功能: 在文件中搜索字符串,将存在该字符串的行打印出来
常用选项:
-i :忽略大小写的不同 ,所以大小写视为相同
-n :顺便输出行号
-v :反向选择 ,亦即显示出没有 ' 搜寻字符串 ' 内容的行

 

[zebra@VM-8-12-centos code]$ ll
total 36
-rw-rw-r-- 1 zebra zebra 25552 Oct 23 13:17 hello.c
-rw-rw-r-- 1 zebra zebra  1481 Oct 23 16:03 temp.txt
drwxrwxr-x 2 zebra zebra  4096 Oct 23 13:08 test
[zebra@VM-8-12-centos code]$ find -name hello.c
./hello.c
[zebra@VM-8-12-centos code]$ grep -n vim hello.c 
3:    printf("hello vim");
1008:    printf("hello vim");
1009:    printf("hello vim");
1011:    printf("hello vim");
1012:    printf("hello vim");
1014:    printf("hello vim");
1015:    printf("hello vim");
1017:    printf("hello vim");
1018:    printf("hello vim");
1020:    printf("hello vim");
1021:    printf("hello vim");
1023:    printf("hello vim");
[zebra@VM-8-12-centos code]$ 

zip/unzip指令

语法: zip 压缩文件 .zip 目录或文件
功能: 将目录或文件压缩成 zip 格式
常用选项:
-r 递归处理,将指定目录下的所有文件和子目录一并处理
-d 指定解压路径
[zebra@VM-8-12-centos code]$ ll
total 36
-rw-rw-r-- 1 zebra zebra 25552 Oct 23 13:17 hello.c
-rw-rw-r-- 1 zebra zebra  1481 Oct 23 16:03 temp.txt
drwxrwxr-x 2 zebra zebra  4096 Oct 23 13:08 test
[zebra@VM-8-12-centos code]$ zip test.zip test
  adding: test/ (stored 0%)
[zebra@VM-8-12-centos code]$ ll
total 40
-rw-rw-r-- 1 zebra zebra 25552 Oct 23 13:17 hello.c
-rw-rw-r-- 1 zebra zebra  1481 Oct 23 16:03 temp.txt
drwxrwxr-x 2 zebra zebra  4096 Oct 23 13:08 test
-rw-rw-r-- 1 zebra zebra   160 Oct 23 16:12 test.zip
[zebra@VM-8-12-centos code]$ unzip test/ test.zip
unzip:  cannot find or open test/, test/.zip or test/.ZIP.
[[zebra@VM-8-12-centos code]$ unzip -d test/myunzip test.zip 
Archive:  test.zip
   creating: test/myunzip/test/
[zebra@VM-8-12-centos code]$ tree
.
|-- hello.c
|-- temp.txt
|-- test
|   |-- a.out
|   |-- hellocp.c
|   |-- h_static
|   `-- myunzip
|       `-- test
`-- test.zip

3 directories, 6 files
[zebra@VM-8-12-centos code]$ 

tar指令

tar [-cxtzjvf]  文件与目录  ....
常用选项:
-c  建立一个压缩文件的参数指令 (create  的意思 ) (打包,压缩)
-x  解开一个压缩文件的参数指令 (解包,解压缩,要把c换成x)
-t  :查看  tarfifile  里面的文件!
-z  是否同时具有  gzip  的属性?亦即是否需要用  gzip  压缩?
-j  :是否同时具有  bzip2  的属性?亦即是否需要用  bzip2  压缩?
-v  :压缩的过程中显示文件!这个常用,但不建议用在背景执行过程!
-f  :使用档名(指定压缩后的文件名) ,请留意,在  f  之后要立即接档名喔!不要再加参数!
-C : 解压到指定目录(和unzip里面的-d指定路径一样的效果)
[zebra@VM-8-12-centos code]$ ll
total 40
-rw-rw-r-- 1 zebra zebra 25552 Oct 23 13:17 hello.c
-rw-rw-r-- 1 zebra zebra  1481 Oct 23 16:03 temp.txt
drwxrwxr-x 3 zebra zebra  4096 Oct 23 16:18 test
-rw-rw-r-- 1 zebra zebra   160 Oct 23 16:12 test.zip
[zebra@VM-8-12-centos code]$ tar -czvf test.tgz test
test/
test/h_static
test/myunzip/
test/myunzip/test/
test/a.out
test/hellocp.c
[zebra@VM-8-12-centos code]$ ll
total 44
-rw-rw-r-- 1 zebra zebra 25552 Oct 23 13:17 hello.c
-rw-rw-r-- 1 zebra zebra  1481 Oct 23 16:03 temp.txt
drwxrwxr-x 3 zebra zebra  4096 Oct 23 16:18 test
-rw-rw-r-- 1 zebra zebra  3471 Oct 23 16:24 test.tgz
-rw-rw-r-- 1 zebra zebra   160 Oct 23 16:12 test.zip
[zebra@VM-8-12-centos code]$ 

[zebra@VM-8-12-centos code]$ tar -xzvf test.tgz -C test/myunzip
test/
test/h_static
test/myunzip/
test/myunzip/test/
test/a.out
test/hellocp.c

  • 6
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值