Linux利用体系学习——常见指令聚集

[复制链接]
发表于 2026-1-10 07:13:23 | 显示全部楼层 |阅读模式

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

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

×
本篇博客是对于linux体系学习的开端认识,相识一些常见指令以及底子知识 
ls指令

ls/ls -l :只表现文件名/表现更多文件的属性,此时留意末了一行开头位置字母为d就代表表现的是目次的文件属性,另有一点就是:ls -l 默认检察当前目次,ls -l 指定目次则可以检察指定目次,在指定目次后加 -d 则可以只检察目次的名称而不检察该目次的全下属性,下面是更多关于ls的一些其他下令指令
-a 列出目次下的全部文件,包罗以.开头的隐含文件。
-d 将目次象文件一样表现,而不是表现其下的文件。如:Is -d 指定目次
-i输出文件的i节点的索引信息。如 Is -ai 指定文件
-k 以k字节的情势表现文件的巨细。ls -alk 指定文件
-l 列出文件的详细信息。
-n 用数字的 UID,GID 代替名称。(先容 UID, GID)

-F在每个文件名后附上一个字符以分析该文件的范例“*"表现可实行的寻常文件;“/"表现目次;“@”表现符号链接;“|“表现FIFOS;“=“表现套接字(sockets)。(目次范例辨认)
-r对目次反向排序。
-t 以时间排序。
-s 在I文件名后输出该文件的巨细。(巨细排序,怎样找到目次下最大的文件)
-R 列出全部子目次下的文件。(递归)
-1 一行只输出一个文件。 
  1. root@hcss-ecs-91e0:~# ls
  2. snap
  3. root@hcss-ecs-91e0:~# ls -l
  4. total 4
  5. drwx------ 3 root root 4096 Sep  7 20:20 snap
复制代码
pwd指令

表现一个用户当前所处的目次,这里必要留意的是在Windows利用体系下是以 '\'作为路径分隔符,在Linux利用体系下是以'/'作为路径分隔符
  1. root@hcss-ecs-91e0:~# pwd
  2. /root
复制代码
cd指令 

切换文件路径,格式为 cd  空格  目的路径,这里引出一个Linux的新知识点:任何一个目次包罗根目次,体系都会默认自带 . 和 .. 目次,cd . 表现返回当前目次,cd .. 表现返回上一级目次,'/'代表Linux中的根目次,没有上级目次返回,这里我们要留意Linux的文件结构是一个以 '/' 为根目次的多叉树!
以是 a. 其叶子节点为空目次大概寻常文件,b. 非叶子节点则肯定好坏空目次
cd ~:通常的任何一个Linux用户在使用特定的用户名登岸时,默认在家目次的路径下,这时cd ~指令就可以直接返回到当前用户自己的家目次路径之下
cd -:在迩来一次的路径下跳转
  1. root@hcss-ecs-91e0:/# cd /root
  2. root@hcss-ecs-91e0:~# pwd
  3. /root
  4. root@hcss-ecs-91e0:~# cd .
  5. root@hcss-ecs-91e0:~# pwd
  6. /root
  7. root@hcss-ecs-91e0:~# cd ..root@hcss-ecs-91e0:/# pwd/
复制代码
touch指令 

touch下令参数可更改文档或目次的日期时间,包罗存取时间和更改时间,大概新建一个不存在的文件
-a:或--time=atime或--time=access或--time=use只更改存取时间。
-c:或--no-create 不创建任何文档。
-d:使用指定的日期时间,而非现在的时间。
-f:此参数将忽略不予处置惩罚,仅负责办理BSD版本touch指令的兼容性标题。
-m:或--time=mtime或--time=modify 只更改变更时间。
-r:把指定文档或目次的日期时间,齐备设成和参考文档或目次的日期时间雷同。
-t: 使用指定的日期时间,而非现在的时间。
  1. root@hcss-ecs-91e0:/# cd ~
  2. root@hcss-ecs-91e0:~# pwd
  3. /root
  4. root@hcss-ecs-91e0:~# touch hello.txt
  5. root@hcss-ecs-91e0:~# pwd
  6. /root
  7. root@hcss-ecs-91e0:~# lshello.txt  mydir  snaproot@hcss-ecs-91e0:~# ls -ltotal 8-rw-r--r-- 1 root root    0 Sep  8 21:43 hello.txtdrwxr-xr-x 2 root root 4096 Sep  8 20:00 mydirdrwx------ 3 root root 4096 Sep  7 20:20 snap
复制代码
makedir指令 
  1. root@hcss-ecs-91e0:~# mkdir yourdir
  2. \root@hcss-ecs-91e0:~# ll
  3. total 44
  4. drwx------  7 root root 4096 Sep  8 21:49 ./
  5. drwxr-xr-x 20 root root 4096 Sep  8 14:27 ../
  6. -rw-r--r--  1 root root  107 Sep  8 14:41 .bash_history
  7. -rw-r--r--  1 root root 3106 Oct 15  2021 .bashrc
  8. drwx------  2 root root 4096 Jul  7 12:08 .cache/
  9. -rw-r--r--  1 root root    0 Sep  8 21:43 hello.txt
  10. -rw-------  1 root root    0 Jul  7 12:15 .history
  11. drwxr-xr-x  2 root root 4096 Sep  8 20:00 mydir/
  12. -rw-r--r--  1 root root  161 Jul  9  2019 .profile
  13. drwx------  3 root root 4096 Sep  7 20:20 snap/
  14. drwx------  2 root root 4096 Sep  7 20:20 .ssh/
  15. -rw-------  1 root root   59 Sep  8 17:42 .Xauthority
  16. drwxr-xr-x  2 root root 4096 Sep  8 21:49 yourdir/
复制代码
创建一连的文件
  1. root@hcss-ecs-91e0:~# mkdir -p a/b/c
  2. root@hcss-ecs-91e0:~# ll
  3. total 48
  4. drwx------  8 root root 4096 Sep  8 21:51 ./
  5. drwxr-xr-x 20 root root 4096 Sep  8 14:27 ../
  6. drwxr-xr-x  3 root root 4096 Sep  8 21:51 a/
  7. -rw-r--r--  1 root root  107 Sep  8 14:41 .bash_history
  8. -rw-r--r--  1 root root 3106 Oct 15  2021 .bashrc
  9. drwx------  2 root root 4096 Jul  7 12:08 .cache/
  10. -rw-r--r--  1 root root    0 Sep  8 21:43 hello.txt
  11. -rw-------  1 root root    0 Jul  7 12:15 .history
  12. drwxr-xr-x  2 root root 4096 Sep  8 20:00 mydir/
  13. -rw-r--r--  1 root root  161 Jul  9  2019 .profile
  14. drwx------  3 root root 4096 Sep  7 20:20 snap/
  15. drwx------  2 root root 4096 Sep  7 20:20 .ssh/
  16. -rw-------  1 root root   59 Sep  8 17:42 .Xauthority
  17. drwxr-xr-x  2 root root 4096 Sep  8 21:49 yourdir/
  18. root@hcss-ecs-91e0:~# cd a
  19. root@hcss-ecs-91e0:~/a# ll
  20. total 12
  21. drwxr-xr-x 3 root root 4096 Sep  8 21:51 ./
  22. drwx------ 8 root root 4096 Sep  8 21:51 ../
  23. drwxr-xr-x 3 root root 4096 Sep  8 21:51 b/
  24. root@hcss-ecs-91e0:~/a# cd b
  25. root@hcss-ecs-91e0:~/a/b# ll
  26. total 12
  27. drwxr-xr-x 3 root root 4096 Sep  8 21:51 ./
  28. drwxr-xr-x 3 root root 4096 Sep  8 21:51 ../
  29. drwxr-xr-x 2 root root 4096 Sep  8 21:51 c/
  30. root@hcss-ecs-91e0:~/a/b#
复制代码
使用树形结构展示目次下的文件 ,如果使用tree下令会报错发起根据自己的体系手动安装tree指令
  1. root@hcss-ecs-91e0:~# tree ~
  2. /root
  3. ├── a
  4. │   └── b
  5. │       └── c
  6. ├── hello.txt
  7. ├── mydir
  8. ├── snap
  9. │   └── lxd
  10. │       ├── 22923
  11. │       ├── 29351
  12. │       ├── common
  13. │       └── current -> 29351
  14. └── yourdir
复制代码
which指令 

检察下令地点的路径,这里引出一个概念就是:下令就是可实行文件也就相当于我们寻常写的C/C++步伐 
  1. root@hcss-ecs-91e0:~# which tree
  2. /usr/bin/tree
  3. root@hcss-ecs-91e0:~# which pwd
  4. /usr/bin/pwd
  5. root@hcss-ecs-91e0:~# which ls
  6. /usr/bin/ls
复制代码
alias指令 

给下令起别名,好比 ll 就是 ls -l 的别名,二者实行后结果是一样的,固然这里alias起的别名在重起步伐后就会自动失效
  1. root@hcss-ecs-91e0:~# alias zhangsan=pwd
  2. root@hcss-ecs-91e0:~# alias lisi=ls
  3. root@hcss-ecs-91e0:~# zhangsan
  4. /root
  5. root@hcss-ecs-91e0:~# lisi
  6. a  hello.txt  mydir  snap  yourdir
复制代码
rm指令 

删除指定文件,默认只删除寻常文件,后缀 -r 表现递归删除,可以删除一串文件,后缀 -f 表现逼迫删除,-rf 可以删除大部分文件
  1. root@hcss-ecs-91e0:~# ll
  2. total 48
  3. drwx------  8 root root 4096 Sep  9 17:13 ./
  4. drwxr-xr-x 20 root root 4096 Sep  8 14:27 ../
  5. drwxr-xr-x  3 root root 4096 Sep  8 21:51 a/
  6. -rw-r--r--  1 root root 2000 Sep  8 22:10 .bash_history
  7. -rw-r--r--  1 root root 3106 Oct 15  2021 .bashrc
  8. drwx------  2 root root 4096 Jul  7 12:08 .cache/
  9. -rw-r--r--  1 root root    0 Sep  8 21:43 hello.txt
  10. -rw-------  1 root root    0 Jul  7 12:15 .history
  11. drwxr-xr-x  2 root root 4096 Sep  8 20:00 mydir/
  12. -rw-r--r--  1 root root  161 Jul  9  2019 .profile
  13. drwx------  3 root root 4096 Sep  7 20:20 snap/
  14. drwx------  2 root root 4096 Sep  7 20:20 .ssh/
  15. -rw-------  1 root root   59 Sep  9 17:13 .Xauthority
  16. drwxr-xr-x  2 root root 4096 Sep  8 21:49 yourdir/
  17. root@hcss-ecs-91e0:~# rm -rf mydir
  18. root@hcss-ecs-91e0:~# ll
  19. total 44
  20. drwx------  7 root root 4096 Sep  9 17:48 ./
  21. drwxr-xr-x 20 root root 4096 Sep  8 14:27 ../
  22. drwxr-xr-x  3 root root 4096 Sep  8 21:51 a/
  23. -rw-r--r--  1 root root 2000 Sep  8 22:10 .bash_history
  24. -rw-r--r--  1 root root 3106 Oct 15  2021 .bashrc
  25. drwx------  2 root root 4096 Jul  7 12:08 .cache/
  26. -rw-r--r--  1 root root    0 Sep  8 21:43 hello.txt
  27. -rw-------  1 root root    0 Jul  7 12:15 .history
  28. -rw-r--r--  1 root root  161 Jul  9  2019 .profile
  29. drwx------  3 root root 4096 Sep  7 20:20 snap/
  30. drwx------  2 root root 4096 Sep  7 20:20 .ssh/
  31. -rw-------  1 root root   59 Sep  9 17:13 .Xauthority
  32. drwxr-xr-x  2 root root 4096 Sep  8 21:49 yourdir/
  33. root@hcss-ecs-91e0:~#
复制代码
man指令 

查找体系手册返回所查找下令的实质
  1. root@hcss-ecs-91e0:~# man man
  2. root@hcss-ecs-91e0:~# man pwd
  3. root@hcss-ecs-91e0:~# man ll
复制代码

cp指令 

复制文件大概目次, cp指令用于复制文件或目次,犹如时指定两个以上的文件或目次,且末了的目的地是一个已经存在的目次,则它会把前面指定的全部文件或目次复制到此目次中,若同时指定多个文件或目次,而末了的目的地并非一个已存在的目次,则会出现错误信息,如果拷贝单个文件到一个未存在的文件,则体系会自动创建一个文件以供拷贝
格式:cp  源文件  目的文件(待拷贝文件)
常用选项:
-f或 --force 强行复制文件或目次,岂论目的文件或目次是否已经存在,-rf代表逼迫拷入
-i或 --interactive 覆盖文件之前先扣问用户
-r递归处置惩罚,将指定目次下的文件与子目次一并处置惩罚。若源文件或目次的形态,不属于目次或符号链接,则同等视为寻常文件处置惩罚,如果拷贝的源文件是一个目次则会直接拷贝到待拷贝文件内部
-R或 --recursive递归处置惩罚,将指定目次下的文件及子目次一并处置惩罚 
  1. root@hcss-ecs-91e0:~# ll
  2. total 48
  3. drwx------  7 root root 4096 Sep  9 18:10 ./
  4. drwxr-xr-x 20 root root 4096 Sep  8 14:27 ../
  5. drwxr-xr-x  3 root root 4096 Sep  8 21:51 a/
  6. -rw-r--r--  1 root root 2000 Sep  8 22:10 .bash_history
  7. -rw-r--r--  1 root root 3106 Oct 15  2021 .bashrc
  8. drwx------  2 root root 4096 Jul  7 12:08 .cache/
  9. -rw-r--r--  1 root root    0 Sep  8 21:43 hello.txt
  10. -rw-------  1 root root    0 Jul  7 12:15 .history
  11. -rw-------  1 root root   20 Sep  9 18:10 .lesshst
  12. -rw-r--r--  1 root root  161 Jul  9  2019 .profile
  13. drwx------  3 root root 4096 Sep  7 20:20 snap/
  14. drwx------  2 root root 4096 Sep  7 20:20 .ssh/
  15. -rw-------  1 root root   59 Sep  9 17:13 .Xauthority
  16. drwxr-xr-x  2 root root 4096 Sep  8 21:49 yourdir/
  17. root@hcss-ecs-91e0:~# cp hello.txt hellpcp.txt
  18. root@hcss-ecs-91e0:~# ll
  19. total 48
  20. drwx------  7 root root 4096 Sep  9 18:17 ./
  21. drwxr-xr-x 20 root root 4096 Sep  8 14:27 ../
  22. drwxr-xr-x  3 root root 4096 Sep  8 21:51 a/
  23. -rw-r--r--  1 root root 2000 Sep  8 22:10 .bash_history
  24. -rw-r--r--  1 root root 3106 Oct 15  2021 .bashrc
  25. drwx------  2 root root 4096 Jul  7 12:08 .cache/
  26. -rw-r--r--  1 root root    0 Sep  8 21:43 hello.txt
  27. -rw-r--r--  1 root root    0 Sep  9 18:17 hellpcp.txt
  28. -rw-------  1 root root    0 Jul  7 12:15 .history
  29. -rw-------  1 root root   20 Sep  9 18:10 .lesshst
  30. -rw-r--r--  1 root root  161 Jul  9  2019 .profile
  31. drwx------  3 root root 4096 Sep  7 20:20 snap/
  32. drwx------  2 root root 4096 Sep  7 20:20 .ssh/
  33. -rw-------  1 root root   59 Sep  9 17:13 .Xauthority
  34. drwxr-xr-x  2 root root 4096 Sep  8 21:49 yourdir/
  35. root@hcss-ecs-91e0:~#
复制代码
mv指令

mv下令是move的缩写,可以用来移动文件大概将文件改名(move (rename) files),是Linux体系下常用的下令,常常用来备份文件大概目次
语法:mv  [选项]   源文件或目次  目的文件或目次
功能:
1. 视mv下令中第二个参数范例的差异(是目的文件照旧目的目次),mv下令将文件重定名或将其移至一个新的目次中
2. 当第二个参数范例是文件时,mv下令完成文件重定名,此时源文件只能有一个(也可以是源目次名),它将所给的源文件或目次重定名为给定的目的文件名。
3. 当第二个参数是已存在的目次名称时,源文件或目次参数可以有多个,mv下令将各参数指定的源文件均移至目的目次中
常用选项:
-f :force 逼迫的意思,如果目的文件已经存在,不会扣问而直接覆盖
-i :若目的文件 (destination) 已经存在时,就会扣问是否覆盖!

cat指令

语法:cat [选项][文件]
功能: 检察目的文件的内容
常用选项:
-b 对非空输出行编号
-n 对输出的全部行编号
-s不输出多行空行

扩展 :重定向利用
1.输出重定向 >
 语法: echo "指定字符串" > 目的写入文件
特点:
a.当目的写入文件不存在就直接自动创建一个
b.每一次写入利用都会更换原来文件中的内容,先清空后写入
以是在没有字符串时可以使用该输出重定向来只新建文件大概清空文件

2.追加重定向 >>
语法:echo "字符串" >> 目的文件
特点: 
a.写入文件时不会清空原文件内容而是直接添加进目的写入文件中

输入重定向 < 
cat 默认从键盘读取输入内容,而输入重定向就是改变输入路径,可以是一个文件直接被cat读取后表现在表现屏上 
 

more指令 

功能:more下令,功能雷同 cat
语法:more [选项][文件]
常用选项:
-n 对输出的全部行编号 -
q 退出more
 less指令(告急)

less 工具也是对文件或别的输出举行分页表现的工具,应该说是linux正统检察文件内容的工具,功能极其强大
less 的用法比起 more 更加的有弹性。在 more 的时间,我们并没有办法向前面翻, 只能往反面看 但若使用了 less 时,就可以使用 [pageup][pagedown] 等按键的功能来往前去后翻看文件,更轻易用 来检察一个文件的内容! 除此之外,在 less 里头可以拥有更多的搜索功能,不止可以向下搜,也可以向上搜
语法: less [参数] 文件
功能: less与more雷同,但使用less可以随意欣赏文件,而more仅能向前移动,却不能向后移动,而且less在检察之前 不会加载整个文件
选项:
-i  忽略搜索时的巨细写
-N  表现每行的行号
/字符串:向下搜索“字符串”的功能
?字符串:向上搜索“字符串”的功能
n:重复前一个搜索(与 / 或 ? 有关)
N:反向重复前一个搜索(与 / 或 ? 有关)
q:quit
head指令

head 与 tail 就像它的名字一样的浅近易懂,它是用来表现开头或末端某个数目的笔墨区块,head 用来表现档案的 开头至尺度输出中,而 tail 想固然尔就是看档案的末端。 
语法: head [参数]... [文件]... 
功能: head 用来表现档案的开头至尺度输出中,默认head下令打印其相应文件的开头10行。 
选项:
-n<行数> 表现的行数

tail指令

tail 下令从指定点开始将文件写到尺度输出.使用tail下令的-f选项可以方便的查阅正在改变的日志日志文件,tail - f filename会把filename里最尾部的内容表现在屏幕上,而且不光革新,使你看到最新的文件内容.
语法: tail[须要参数][选择参数][文件] 
功能: 用于表现指定文件末了内容,不指定文件时,作为输入信息举行处置惩罚。常用检察日志日志文件。
选项:
-f 循环读取
-n<行数> 表现行数

扩展:管道 |
可以类比条件概率中的"|",这里指在"|"前面的利用指令完成后再举行"|"之后的利用指令

时间相干的指令

date: 表现时间

date 指定格式表现时间: date +%Y:%m:%d date
用法:date [OPTION]... [+FORMAT]

1.在表现方面,使用者可以设定欲表现的格式,格式设定为一个加号后接数个标志,此中常用的标志列表如下
%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
cal:检察日历
下令格式: cal [参数][月份][年份]
功能: 用于检察日历等时间信息,如只有一个参数,则表现年份(1-9999),如有两个参数,则表现月份和年份
常用选项:
-3 表现体系前一个月,当前月,下一个月的月历
-j  表现在当年中的第几天(一年日期按天算,从1月1号算起,默认表现当前月在一年中的天数)
-y  表现当前年份的日历

find 查找指令 
Linux下find下令在目次结构中搜索文件,并实行指定的利用
Linux下find下令提供了相当多的查找条件,功能很强大。由于find具有强大的功能,以是它的选项也很 多,此中大部分选项都值得我们花时间来相识一下。 纵然体系中含有网络文件体系( NFS),find下令在该文件体系中同样有用,只你具有相应的权限。 在运行一个非常斲丧资源的find下令时,许多人都倾向于把它放在背景实行,由于遍历一个大的文件系 统大概会淹灭很长的时间(这里是指30G字节以上的文件体系)。
语法: find pathname -options
功能: 用于在文件树种查找文件,并作出相应的处置惩罚(大概访问磁盘)
常用选项:
-neme:按照文件名查找

 grep指令

语法: grep [选项] 征采字符串 文件
功能: 在文件中搜索字符串,将找到的行打印出来
常用选项:
-i :忽略巨细写的差异,以是巨细写视为雷同
-n :趁便输出行号
-v :反向选择,亦即表现出没有 '征采字符串' 内容的那一行

 
zip与unzip指令 

功能: 将目次或文件压缩成zip格式
语法: zip 压缩文件.zip 目次或文件
常用选项:
-r 递归处置惩罚,将指定目次下的全部文件和子目次一并处置惩罚

解压到指定目次下必要添加 -d
 
将linux中的压缩包传给windows体系可以使用 sz 指令直接回车就会出现以下界面 

Linux体系担当Windows体系的压缩包就使用 rz 指令后回车出现以下界面,也可以直接拖拽
 
tar指令  (打包/解包,不打开直接看内容)

tar [-cxtzjvf] 文件与目次 .... 参数:
-c :创建一个压缩文件的参数指令(create 的意思);
-x :解开一个压缩文件的参数指令!
-t :检察 tarfile 内里的文件!
-z :是否同时具有 gzip 的属性?亦便是否必要用 gzip 压缩?
-j :是否同时具有 bzip2 的属性?亦便是否必要用 bzip2 压缩?
-v :压缩的过程中表现文件!这个常用,但不发起用在配景实行过程!
-f :使用档名,请留意,在 f 之后要立刻接档名喔!不要再加参数!
-C : 解压到指定目次

uname指令 

功能: uname用来获取电脑和利用体系的相干信息。
语法:uname [选项] 
增补分析:uname可表现linux主机所用的利用体系的版本、硬件的名称等根本信息。
常用选项:
-a或–all 详细输出全部信息,依次为内核名称,主机名,内核版本号,内核版本,硬件名,处置惩罚器类 型,硬件平台范例,利用体系名称
 
回复

使用道具 举报

登录后关闭弹窗

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