Linux的部分常用底子指令

[复制链接]
发表于 2025-10-24 15:20:13 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
目次

1. ls 指令
 2. pwd下令
3. cd 指令
4. touch 指令
5. mkdir指令
 6. rmdir指令&&rm指令
7. rm下令可以同时删除文件或目次
 8. man指令
9. cp指令
10. mv指令
 11. cat 指令
12. more指令
 13. less 指令
14. head指令
15. tail 指令
 16. find 指令
17. which指令
18. whereis 指令
19. alias 指令
 20. grep 指令


1. ls 指令

   语法: ls [ 选项 ] [ 文件 ]
  对于目次,该下令列出该目次下的全部子目次与文件。对于文件,将列出⽂件名以及其他信息。
常用选项:
   -a 列出⽬录下的全部文件,包罗以.开头的隐含⽂件。
  -d 将⽬录像⽂件⼀样表现,而不是表现其下的⽂件。如:ls ‒d 指定目次
  -i 输出⽂件的i节点的索引信息。如 ls ‒ ai 指定文件
  -k 以k字节的情势表现文件的巨细。如 ls ‒ alk 指定文件
  -l 列出文件的详细信息
  -r 对目次反向排序
  -t 以时间排序
  举例: 
  1. [iu@iZ2ze5ncfh4b12o80084czZ study]$ ls lesson2
  2. dir  pd1  test.c  test.zip
  3. [iu@iZ2ze5ncfh4b12o80084czZ lesson2]$ ls -a
  4. .  ..  dir  pd1  test.c  test.zip
  5. [iu@iZ2ze5ncfh4b12o80084czZ lesson2]$ ls -a -l
  6. total 24
  7. drwxr-xr-x 4 root root 4096 Feb 23 18:13 .
  8. drwxr-xrwx 8 root root 4096 Feb 26 22:03 ..
  9. drwxr-xr-x 2 root root 4096 Feb 23 18:13 dir
  10. drwxr-xr-x 3 root root 4096 Feb 23 18:13 pd1
  11. -rw-r--r-- 1 root root   72 Feb 23 18:13 test.c
  12. -rw-r--r-- 1 root root  193 Feb 23 18:13 test.zip
  13. [iu@iZ2ze5ncfh4b12o80084czZ lesson2]$ ls -a -l -f
  14. ..  dir  .  test.zip  test.c  pd1
  15. [iu@iZ2ze5ncfh4b12o80084czZ lesson2]$ ls -a -l -F
  16. total 24
  17. drwxr-xr-x 4 root root 4096 Feb 23 18:13 ./
  18. drwxr-xrwx 8 root root 4096 Feb 26 22:03 ../
  19. drwxr-xr-x 2 root root 4096 Feb 23 18:13 dir/
  20. drwxr-xr-x 3 root root 4096 Feb 23 18:13 pd1/
  21. -rw-r--r-- 1 root root   72 Feb 23 18:13 test.c
  22. -rw-r--r-- 1 root root  193 Feb 23 18:13 test.zip
  23. [iu@iZ2ze5ncfh4b12o80084czZ lesson2]$ ls -a -l -F -n
  24. total 24
  25. drwxr-xr-x 4 0 0 4096 Feb 23 18:13 ./
  26. drwxr-xrwx 8 0 0 4096 Feb 26 22:03 ../
  27. drwxr-xr-x 2 0 0 4096 Feb 23 18:13 dir/
  28. drwxr-xr-x 3 0 0 4096 Feb 23 18:13 pd1/
  29. -rw-r--r-- 1 0 0   72 Feb 23 18:13 test.c
  30. -rw-r--r-- 1 0 0  193 Feb 23 18:13 test.zip
复制代码
 2. pwd下令

   语法:pwd
   表现⽤户当前地点的目次。
  1. [iu@iZ2ze5ncfh4b12o80084czZ study]$ pwd
  2. /home/iu/study
复制代码
3. cd 指令

   Linux体系中,磁盘上的文件和目次被构成⼀棵目次树,每个节点都是目次或文件,此中寻常⽂件⼀定是目次树的叶子节点。
  明白路径存在的意义:树状构造方式,都是为了包管快速定位查找到指定的文件,而定位⽂件就必要具有唯⼀性的方案来举行定位⽂件。此中任何⼀个节点,都只有⼀个父节点,以是,从根目次开始,定位指定文件,路径具有唯⼀性。
     路径:
  绝对路径:⼀般从/开始,不依赖其他目次的定位⽂件的方式
  相对路径:相对于当前用户所处目次,定位⽂件的路径方式
  绝对路径⼀般不会随着用户的路径变革而丧失唯⼀性,⼀般在特定服务的设置文件中经常被利用;相对路径由于它的便捷性,⼀般在下令行中利用较多
  1. [iu@iZ2ze5ncfh4b12o80084czZ study]$ cd /home/iu/study[iu@iZ2ze5ncfh4b12o80084czZ study]$ pwd
  2. /home/iu/study// .. 可以返回上级目次[iu@iZ2ze5ncfh4b12o80084czZ study]$ cd ..[iu@iZ2ze5ncfh4b12o80084czZ ~]$ pwd/home/iu[iu@iZ2ze5ncfh4b12o80084czZ ~]$ cd /home/iu/study/lesson1[iu@iZ2ze5ncfh4b12o80084czZ lesson1]$ pwd/home/iu/study/lesson1[iu@iZ2ze5ncfh4b12o80084czZ lesson1]$ cd ../lesson2[iu@iZ2ze5ncfh4b12o80084czZ lesson2]$ pwd/home/iu/study/lesson2// - 直接回退到近来一次所处的目次[iu@iZ2ze5ncfh4b12o80084czZ lesson2]$ cd -/home/iu/study/lesson1// ~ 返回抵家目次[iu@iZ2ze5ncfh4b12o80084czZ lesson1]$ cd ~[iu@iZ2ze5ncfh4b12o80084czZ ~]$ pwd/home/iu
复制代码
4. touch 指令

   语法: touch  [选项]...  [文件] ...
   touch下令参数可更改文档或目次的日期时间,包罗存取时间和更改时间,大概新建⼀个不存在的文件。
常用选项:
   -a: change only the access time
  -c: change only the modification time
  举例:
  1. //创建普通⽂件
  2. [iu@iZ2ze5ncfh4b12o80084czZ test]$ ls
  3. dir  file.txt
  4. [iu@iZ2ze5ncfh4b12o80084czZ test]$ touch newFile.txt
  5. [iu@iZ2ze5ncfh4b12o80084czZ test]$ ls
  6. dir  file.txt  newFile.txt
  7. //修改⽂件access时间  
  8. [iu@iZ2ze5ncfh4b12o80084czZ test]$ touch -a newFile.txt
  9. //修改⽂件Modify时间
  10. [iu@iZ2ze5ncfh4b12o80084czZ test]$ touch -m newFile.txt
复制代码
5. mkdir指令

   语法: mkdir [选项] [文件]...
  在当前目次下创建⼀个名为“dirname”的目次
常用选项:
   -p: 可以是⼀个路径名称。此时若路径中的某些目次尚不存在,加上此选项后,体系将自动创建好那些尚不存在的目次,即⼀次可以创建多个目次。
  1. //创建普通空⽬录
  2. [iu@iZ2ze5ncfh4b12o80084czZ test]$ ls -l
  3. total 4
  4. drwxrwxr-x 2 iu iu 4096 Jan 11 14:22 dir
  5. -rw-rw-r-- 1 iu iu    0 Jan 11 14:22 file.txt
  6. -rw-rw-r-- 1 iu iu    0 Jan 11 15:09 newFile.txt
  7. [iu@iZ2ze5ncfh4b12o80084czZ test]$ mkdir mydir
  8. [iu@iZ2ze5ncfh4b12o80084czZ test]$ ls -l
  9. total 8
  10. drwxrwxr-x 2 iu  iu  4096 Jan 11 14:22 dir
  11. -rw-rw-r-- 1 iu  iu     0 Jan 11 14:22 file.txt
  12. drwxrwxr-x 2 iu  iu  4096 Jan 11 15:15 mydir
  13. -rw-rw-r-- 1 iu  iu     0 Jan 11 15:09 newFile.txt
  14. //递归建⽴多个⽬录,创建指定路径
  15. [iu@iZ2ze5ncfh4b12o80084czZ test]$ mkdir -p path1/path2/path3/path4
  16. [iu@iZ2ze5ncfh4b12o80084czZ test]$ ls -l
  17. total 12
  18. drwxrwxr-x 2 iu  iu  4096 Jan 11 14:22 dir
  19. -rw-rw-r-- 1 iu  iu     0 Jan 11 14:22 file.txt
  20. drwxrwxr-x 2 iu  iu 4096 Jan 11 15:15 mydir
  21. -rw-rw-r-- 1 iu  iu     0 Jan 11 15:09 newFile.txt
  22. drwxrwxr-x 3 iu  iu  4096 Jan 11 15:16 path1
  23. [whb@bite-alicloud test]$ tree path1
  24. path1
  25. └── path2
  26.      └── path3
  27.          └── path4
复制代码
 6. rmdir指令

rmdir是⼀个与mkdir相对应的下令,mkdir是创建目次,而rmdir是删除下令
   语法:rmdir [参数]  [文件]                                
  删除空目次 
   实用对象:具有当前目次利用权限的全部利用者
  常用选项:
   -p 当子目次被删除后假如父目次也酿成空目次的话,就连带父目次⼀起删除。
   举例:
  1. //删除空⽬录
  2. [iu@iZ2ze5ncfh4b12o80084czZ test]$ ll
  3. total 12
  4. drwxrwxr-x 2 iu  iu 4096 Jan 11 14:22 dir
  5. -rw-rw-r-- 1 iu  iu    0 Jan 11 14:22 file.txt
  6. drwxrwxr-x 2 iu  iu 4096 Jan 11 15:15 mydir
  7. -rw-rw-r-- 1 iu  iu    0 Jan 11 15:09 newFile.txt
  8. drwxrwxr-x 3 iu  iu 4096 Jan 11 15:16 path1
  9. [iu@iZ2ze5ncfh4b12o80084czZ test]$ tree mydir/
  10. mydir/
  11. 0 directories, 0 files
  12. [wiu@iZ2ze5ncfh4b12o80084czZ test]$ rmdir mydir
  13. [iu@iZ2ze5ncfh4b12o80084czZ test]$ ll
  14. total 8
  15. drwxrwxr-x 2  iu  iu 4096 Jan 11 14:22 dir
  16. -rw-rw-r-- 1  iu  iu    0 Jan 11 14:22 file.txt
  17. -rw-rw-r-- 1  iu  iu    0 Jan 11 15:09 newFile.txt
  18. drwxrwxr-x 3  iu  iu 4096 Jan 11 15:16 path1
  19. //删除路径
  20. [iu@iZ2ze5ncfh4b12o80084czZ test]$ tree path1
  21. path1
  22. └── path2
  23.      └── path3
  24.         └── path4
  25. 3 directories, 0 files
  26. [iu@iZ2ze5ncfh4b12o80084czZ test]$ rmdir -p path1/path2/path3/path4
  27. [iu@iZ2ze5ncfh4b12o80084czZ test]$ ll
  28. total 4
  29. drwxrwxr-x 2 iu iu 4096 Jan 11 14:22 dir
  30. -rw-rw-r-- 1 iu iu 0    Jan 11 14:22 file.txt  
  31. -rw-rw-r-- 1 iu iu 0    Jan 11 15:09 newFile.txt   
  32. //指定路径中有不为空的路径,便⽆法删除
  33. [iu@iZ2ze5ncfh4b12o80084czZ test]$ rmdir -p path1/path2/path3
  34. rmdir: failed to remove ‘path1/path2/path3’: Directory not empty
  35. [iu@iZ2ze5ncfh4b12o80084czZ test]$ touch path1/myfile.txt
  36. [iu@iZ2ze5ncfh4b12o80084czZ test]$ touch path1/path2/myfile.txt
  37. [iu@iZ2ze5ncfh4b12o80084czZ test]$ tree path1/
  38. path1/
  39. ├── myfile.txt
  40. └── path2
  41.         ├── myfile.txt
  42.         └── path3
  43.             └── path4
  44. 3 directories, 2 files
  45. [iu@iZ2ze5ncfh4b12o80084czZ test]$ rmdir -p path1/path2/path3/path4
  46. rmdir: failed to remove directory ‘path1/path2’: Directory not empt
复制代码
7. rm下令

   语法: rm [参数] [文件]
  删除文件或目次
    适⽤对象:全部利用者
  常用选项:
   -f 纵然文件属性为只读,直接删除
  -i 删除前逐⼀扣问确认
  -r 删除⽬录及其下全部文件
   举例:
  1. //删除普通⽂件
  2. [iu@iZ2ze5ncfh4b12o80084czZ test]$ ll
  3. total 8
  4. drwxrwxr-x 2 iu iu 4096 Jan 11 14:22 dir
  5. -rw-rw-r-- 1 iu iu    0 Jan 11 14:22 file.txt
  6. -rw-rw-r-- 1 iu iu    0 Jan 11 15:09 newFile.txt   
  7. drwxrwxr-x 3 iu iu 4096 Jan 11 15:26 path1
  8. [iu@iZ2ze5ncfh4b12o80084czZ test]$ rm file.txt
  9. [iu@iZ2ze5ncfh4b12o80084czZ test]$ ll
  10. total 8
  11. drwxrwxr-x 2 iu iu 4096 Jan 11 14:22 dir
  12. -rw-rw-r-- 1 iu iu    0 Jan 11 15:09 newFile.txt
  13. drwxrwxr-x 3 iu iu 4096 Jan 11 15:26 path1
  14. //删除⽬录⽂件
  15. [iu@iZ2ze5ncfh4b12o80084czZ test]$ ll
  16. total 8
  17. drwxrwxr-x 2 iu iu 4096 Jan 11 14:22 dir
  18. -rw-rw-r-- 1 iu iu    0 Jan 11 15:09 newFile.txt
  19. drwxrwxr-x 3 iu iu 4096 Jan 11 15:26 path1
  20. [iu@iZ2ze5ncfh4b12o80084czZ test]$ rm dir
  21. rm: cannot remove ‘dir’: Is a directory
  22. [iu@iZ2ze5ncfh4b12o80084czZ test]$ rm -r dir
  23. [iu@iZ2ze5ncfh4b12o80084czZ test]$ ll
  24. total 4
  25. -rw-rw-r-- 1 iu iu    0 Jan 11 15:09 newFile.txt
  26. drwxrwxr-x 3 iu iu 4096 Jan 11 15:26 path1
复制代码
 8. man指令

   语法:man [ 选项 ] 下令
  查察联机手册获取资助
   常用选项:
  -k 根据关键字搜刮联机资助
  num 只在第num章节查找
  -a 将全部章节的都显⽰出来,⽐如man printf它缺省从第⼀章开始搜刮,知道就制止,用a选 项,当按下q退出,他会继承今后⾯搜刮,直到全部章节都搜刮完毕
  举例:
  1. [iu@iZ2ze5ncfh4b12o80084czZ test]$ man printf
  2. [iu@iZ2ze5ncfh4b12o80084czZ test]$ man fork      
  3. [iu@iZ2ze5ncfh4b12o80084czZ test]$ man 2 frok   
  4. [iu@iZ2ze5ncfh4b12o80084czZ test]$ man 3 printf  
  5. [iu@iZ2ze5ncfh4b12o80084czZ test]$ man 7 signal  
  6. [iu@iZ2ze5ncfh4b12o80084czZ test]$ man man
复制代码
9. cp指令

   语法: cp [ 选项 ] 源文件或目次 目的文件或目次
   复制文件或目次(cp指令用于复制文件或目次,如同时指定两个以上的文件或目次,且末了的目的地是⼀个已经存在的目次,则它会把前面指定的全部文件或目次复制到此目次中
   常用选项:
  -f或--force 强⾏复制文件或目次,岂论目的⽂件或目次是否已经存在
  -i或--interactive  覆盖文件先扣问用户
  -r 递归处理处罚,将指定目次下的文件与子目次⼀并处理处罚。
  举例:
  1. //cp普通⽂件
  2. [iu@iZ2ze5ncfh4b12o80084czZ test]$ echo "hello ">myfile.txt
  3. [iu@iZ2ze5ncfh4b12o80084czZ test]$ cat myfile.txt
  4. hello
  5. [iu@iZ2ze5ncfh4b12o80084czZ test]$ ll
  6. total 4-rw-rw-r-- 1 iu iu 22 Jan 11 15:47 myfile.txt
  7. [iu@iZ2ze5ncfh4b12o80084czZ test]$ cp myfile.txt myfile-backup.txt
  8. [iu@iZ2ze5ncfh4b12o80084czZ test]$ ll
  9. total 8
  10. -rw-rw-r-- 1 iu iu 22 Jan 11 15:47 myfile-backup.txt
  11. -rw-rw-r-- 1 iu iu 22 Jan 11 15:47 myfile.txt
  12. [iu@iZ2ze5ncfh4b12o80084czZ test]$ cat myfile-backup.txt
  13. hello
  14. //cp如果⽬标⽂件存在,就覆盖
  15. [iu@iZ2ze5ncfh4b12o80084czZ test]$ echo "hello iu" > myfile.txt
  16. [iu@iZ2ze5ncfh4b12o80084czZ test]$ cat myfile.txt
  17. hello iu
  18. [iu@iZ2ze5ncfh4b12o80084czZ test]$ cp myfile.txt myfile-backup.txt
  19. [iu@iZ2ze5ncfh4b12o80084czZ test]$ cat myfile-backup.txt
  20. hello iu
复制代码
10. mv指令

   语法: mv [选项] 源文件或目次 目的文件或目次
   mv下令是move的缩写,可以用来移动文件大概将文件改名,经常用备份文件大概目次
 a)mv下令中第⼆个参数范例的差异(是文件还是目次),mv下令将文件重定名或将其移至⼀个新的目次中。
b)当第⼆个参数范例是文件时,mv下令完成文件重定名,此时,源文件只能有⼀个,它将所给的源文件或目次重定名为给定的目的⽂件名。
c)当第⼆个参数是已存在的目次名称时,目次参数可以有多个,mv下令将各参数指定的源文件都移至目的目次中。
   常用选项:
  -f:force欺压的意思,假如目的文件已经存在,不会扣问而直接覆盖
  -i:若目的文件已经存在时,就会扣问是否覆盖。
  
  举例:
  1. //更改名称
  2. [iu@iZ2ze5ncfh4b12o80084czZ test]$ touch myfile.txt
  3. [iu@iZ2ze5ncfh4b12o80084czZ test]$ ll
  4. total 0-rw-rw-r-- 1 iu iu 0 Jan 11 15:56 myfile.txt
  5. [iu@iZ2ze5ncfh4b12o80084czZ test]$ mv myfile.txt yourfile.txt
  6. [iu@iZ2ze5ncfh4b12o80084czZ test]$ ll
  7. total 0
  8. -rw-rw-r-- 1 iu iu 0 Jan 11 15:56 yourfile.txt
  9. //如果当前路径存在同名⽂件,改名即覆盖
  10. [iu@iZ2ze5ncfh4b12o80084czZ test]$ touch myfile.txt
  11. [iu@iZ2ze5ncfh4b12o80084czZ test]$ ll
  12. total 0
  13. -rw-rw-r-- 1 iu iu 0 Jan 11 15:58 myfile.txt
  14. -rw-rw-r-- 1 iu iu 0 Jan 11 15:57 yourfile.txt
  15. [iu@iZ2ze5ncfh4b12o80084czZ test]$ mv yourfile.txt myfile.txt
  16. [iu@iZ2ze5ncfh4b12o80084czZ test]$ ll
  17. total 0
  18. -rw-rw-r-- 1 iu iu 0 Jan 11 15:57 myfile.txt
复制代码
 11. cat 指令

   语法: cat [ 选项 ] [ 文件 ]
   查察目的文件的内容
   常用选项:
   -b 对非空输出行编号 
   -n 对输出的全部行编号
   -s 不输出多行空行
  举例:
  1. [whb@bite-alicloud test]$ cnt=0; while [ $cnt -le 20 ]; do echo "hello iu";
  2. let cnt++; done > temp.txt
  3. [whb@bite-alicloud test]$ cat -b temp.txt
  4.         1        hello iu
  5.         2        hello iu
  6.         3        hello iu
  7.         4        hello iu
  8.         5        hello iu
  9.         6        hello iu
  10.         7        hello iu
  11.         8        hello iu
  12.         9        hello iu
  13.         10       hello iu
  14.         ...
复制代码
12. more指令

   语法: more [选项]
   more下令,功能雷同cat,但是可以通过下键,向下查找,但不能向上查找
   常用选项:
  -n 指定输出行数
   q 退出more
  举例:
  1. [iu@iZ2ze5ncfh4b12o80084czZ test]$ cnt=0; while [ $cnt -le 2000 ]; do echo "hello
  2. iu"; let cnt++; done > temp.txt
  3. //-n指定输出⾏数
  4. [iu@iZ2ze5ncfh4b12o80084czZ test]$ more -10 temp.txt
  5. hello iu
  6. hello iu
  7. hello iu
  8. hello iu
  9. hello iu
  10. hello iu
  11. hello iu
  12. hello iu
  13. hello iu
  14. hello iu
  15. --More--(0%)
复制代码
 13. less 指令

   语法: less [ 参数 ] 文件
  less与more雷同,但利用less可以随意欣赏文件,而more仅能向前移动,却不能向后移动,而且less在查察之前不会加载全部文件。
   常用选项:
  -i 忽略搜刮时的巨细写
  -N 表现每行的行号
   /字符串:向下搜刮“字符串”的功能
  ?字符串:向上搜刮“字符串”的功能
  q 退出
  举例:
  1. //命令⾏输出多⾏⽂本
  2. [iu@iZ2ze5ncfh4b12o80084czZ test]$ cnt=0; while [ $cnt -le 2000 ]; do echo "hello
  3. $cnt"; let cnt++; done > temp.txt
  4. // 测试搜索和-N等功能
  5. [iu@iZ2ze5ncfh4b12o80084czZ test]$ less -N temp.txt
  6. 1 hello 0
  7. 2 hello 1
  8. 3 hello 2
  9. 4 hello 3
  10. 5 hello 4
  11. 6 hello 5
  12. 7 hello 6
  13. 8 hello 7
  14. 9 hello 8
  15. 10 hello 9
  16. 11 hello 10
  17. 12 hello 11
  18. 13 hello 12
  19. 14 hello 13
  20. ...
复制代码
14. head指令

   语法: head[参数]  [文件]
   head用来表现文件的开头至标准输出中(默认head下令打印其文件的开头10行)。
    常用选项:
   -n <行数> 表现的行数
   举例:
  1. [iu@iZ2ze5ncfh4b12o80084czZ test]$ head temp.txt
  2. hello 0
  3. hello 1
  4. hello 2
  5. hello 3
  6. hello 4
  7. hello 5
  8. hello 6
  9. hello 7
  10. hello 8
  11. hello 9
  12. [iu@iZ2ze5ncfh4b12o80084czZ test]$ head -5 temp.txt
  13. hello 0
  14. hello 1
  15. hello 2
  16. hello 3
  17. hello 4
复制代码
15. tail 指令

   语法: tail [参数] [文件]
   用于表现指定文件末了内容,作为输入信息举行处理处罚
   常用选项:
  -f 循环读取
  -n 表现行数
   举例:
  1. [iu@iZ2ze5ncfh4b12o80084czZ test]$ tail temp.txt
  2. hello 1991
  3. hello 1992
  4. hello 1993
  5. hello 1994
  6. hello 1995
  7. hello 1996
  8. hello 1997
  9. hello 1998
  10. hello 1999
  11. hello 2000
  12. [iu@iZ2ze5ncfh4b12o80084czZ test]$ tail -3 temp.txt
  13. hello 1998
  14. hello 1999
  15. hello 2000
复制代码
 16. find 指令

   语法: find [选项] [文件]
   ⽤于在文件树中查找文件,并作出相应的处理处罚
   常用选项:
  -name 按照文件名查找文件
   举例:
  1. //在指定路径下搜索执⾏名称的⽂件
  2. [iu@iZ2ze5ncfh4b12o80084czZ test]$ find ~ -name test.c
  3. /home/iu/test_code/code/test.c
  4. /home/iu/test_code/test.c
复制代码
17. which指令

   语法: which [体系下令文件]
   搜刮体系指定的下令
举例:
  1. [iu@iZ2ze5ncfh4b12o80084czZ test]$ which ls
  2. alias ls='ls --color=auto'
  3. /usr/bin/ls
  4. [iu@iZ2ze5ncfh4b12o80084czZ test]$ which pwd
  5. /usr/bin/pwd
复制代码
18. whereis 指令

   语法: whereis [文件]
   用于找到步伐的源、⼆进制文件或手册
举例:
  1. [iu@iZ2ze5ncfh4b12o80084czZ test]$ whereis ls
  2. ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz /usr/share/man/man1p/ls.1p.gz
  3. [iu@iZ2ze5ncfh4b12o80084czZ test]$ whereis libc.so
  4. libc: /usr/lib64/libc.so /usr/lib64/libc.a /usr/share/man/man7/libc.7.gz
复制代码
19. alias 指令

   语法:alias [文件]=“name”
   设置下令的别名
举例:
  1. [iu@iZ2ze5ncfh4b12o80084czZ test]$ alias iu='ls -a -l -n'
  2. [iu@iZ2ze5ncfh4b12o80084czZ test]$ which iu
  3. alias iu='ls -a -l -n'
  4. /usr/bin/ls
  5. [iu@iZ2ze5ncfh4b12o80084czZ test]$ iu
  6. total 36
  7. drwxrwxr-x  2 1000 1003  4096 Jan 11 17:59 .
  8. drwx------ 22 1003 1003  4096 Jan 11 17:57 ..
  9. -rw-rw-r--  1 1003 1003 28667 Jan 11 18:29 temp.txt
复制代码
 20. grep 指令

   语法: grep [选项] 征采字符串 文件
   在⽂件中搜刮字符串,将找到的行并打印出来
   常用选项:
  -i: 忽略巨细写,巨细写视为雷同
  -n:输出行号
  -v:反向选择,亦即表现出没有'征采字符串'内容的那一行
  举例:
  1. [iu@iZ2ze5ncfh4b12o80084czZ test]$ cat temp.txt
  2. abcd
  3. ABCD
  4. hello
  5. iu
  6. 1234
  7. //基本查找
  8. [iu@iZ2ze5ncfh4b12o80084czZ test]$ grep "abcd" temp.txt
  9. abcd
  10. //忽略⼤⼩写的不同,所以⼤⼩写视为相同
  11. [iu@iZ2ze5ncfh4b12o80084czZ test]$ grep -i "abcd" temp.txt
  12. abcd
  13. ABCD
  14. //输出⾏号
  15. [iu@iZ2ze5ncfh4b12o80084czZ test]$ grep -n "abcd" temp.txt
  16. 1:abcd
  17. [iu@iZ2ze5ncfh4b12o80084czZ test]$ grep -ni "abcd" temp.txt
  18. 1:abcd
  19. 2:ABCD
  20. //反向选择,亦即显⽰出没有搜寻字符串内容的那⼀⾏
  21. [iu@iZ2ze5ncfh4b12o80084czZ test]$ grep -v "abcd" temp.txt
  22. ABCD
  23. hello
  24. iu
  25. 1234
  26. [iu@iZ2ze5ncfh4b12o80084czZ test]$ grep -vn "abcd" temp.txt
  27. 2:ABCD
  28. 3:hello
  29. 4:iu
  30. 5:1234
  31. [iu@iZ2ze5ncfh4b12o80084czZ test]$ grep -vni "abcd" temp.txt
  32. 3:hello
  33. 4:iu
  34. 5:1234
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
继续阅读请点击广告
回复

使用道具 举报

×
登录参与点评抽奖,加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表