0
点赞
收藏
分享

微信扫一扫

Linux系统 (二)- 指令学习2

九月的栩 2022-11-02 阅读 193

BlogPicture

~~~~

前言

本节继续基本指令的学习!


mkdir

基本语法

mkdir [选项] dirname

功能

创建目录举例

[root@VM-4-17-centos dir]# pwd
/root/dir
[root@VM-4-17-centos dir]# ls
test1.txt  test2.txt  test3.txt
[root@VM-4-17-centos dir]# mkdir dir1
[root@VM-4-17-centos dir]# mkdir dir2
[root@VM-4-17-centos dir]# mkdir dir3
[root@VM-4-17-centos dir]# ls
dir1  dir2  dir3  test1.txt  test2.txt  test3.txt

image.png

选项 -p

功能

[root@VM-4-17-centos dir]# pwd
/root/dir
[root@VM-4-17-centos dir]# ls
test1.txt  test2.txt  test3.txt
[root@VM-4-17-centos dir]# mkdir -p dir1/dir2/dir3/dir4
[root@VM-4-17-centos dir]# ls
dir1  test1.txt  test2.txt  test3.txt
[root@VM-4-17-centos dir]# tree
.
|-- dir1
|   `-- dir2
|       `-- dir3
|           `-- dir4
|-- test1.txt
|-- test2.txt
`-- test3.txt

4 directories, 3 files

image.png


rmdir

基本语法

rmdir [选项] dirname

功能

[root@VM-4-17-centos dir]# mkdir dir1
[root@VM-4-17-centos dir]# mkdir -p dir2/dir3
[root@VM-4-17-centos dir]# tree .
.
|-- dir1
|-- dir2
|   `-- dir3
|-- test1.txt
|-- test2.txt
`-- test3.txt

3 directories, 3 files
[root@VM-4-17-centos dir]# rmdir dir1
[root@VM-4-17-centos dir]# tree
.
|-- dir2
|   `-- dir3
|-- test1.txt
|-- test2.txt
`-- test3.txt

2 directories, 3 files

image.png

[root@VM-4-17-centos dir]# tree
.
|-- dir2
|   `-- dir3
|-- test1.txt
|-- test2.txt
`-- test3.txt

2 directories, 3 files
[root@VM-4-17-centos dir]# rmdir dir2
rmdir: failed to remove ‘dir2’: Directory not empty

image.png


-p选项

[root@VM-4-17-centos dir]# mkdir -p a/b/c
[root@VM-4-17-centos dir]# tree .
.
|-- a
|   `-- b
|       `-- c
|-- test1.txt
|-- test2.txt
`-- test3.txt

3 directories, 3 files
[root@VM-4-17-centos dir]# rmdir -p a/b/c
[root@VM-4-17-centos dir]# tree .
.
|-- test1.txt
|-- test2.txt
`-- test3.txt

0 directories, 3 files

image.png


rm

基本语法

rm [选项] name

功能

[root@VM-4-17-centos dir]# tree .
.
|-- dir1
|-- dir2
|   `-- dir3
|-- test1.txt
|-- test2.txt
`-- test3.txt

3 directories, 3 files
[root@VM-4-17-centos dir]# rm test1.txt 
rm: remove regular empty file ‘test1.txt’? y
[root@VM-4-17-centos dir]# rm test2.txt 
rm: remove regular empty file ‘test2.txt’? y	
[root@VM-4-17-centos dir]# rm test3.txt
rm: remove regular empty file ‘test3.txt’? y
[root@VM-4-17-centos dir]# tree .
.
|-- dir1
`-- dir2
    `-- dir3

3 directories, 0 files

image.png


选项 -r

[root@VM-4-17-centos dir]# tree
.
|-- dir1
`-- dir2
    `-- dir3
        `-- dir4

4 directories, 0 files
[root@VM-4-17-centos dir]# rm -r dir1
rm: remove directory ‘dir1’? y
[root@VM-4-17-centos dir]# rm -r dir2
rm: descend into directory ‘dir2’? y
rm: descend into directory ‘dir2/dir3’? y
rm: remove directory ‘dir2/dir3/dir4’? y
rm: remove directory ‘dir2/dir3’? y
rm: remove directory ‘dir2’? y
[root@VM-4-17-centos dir]# tree .
.

0 directories, 0 files

image.png

选项 -f

[root@VM-4-17-centos dir]# tree
.
|-- dir1
|   `-- dir2
|       `-- dir3
|-- dir4
`-- test.txt

4 directories, 1 file
[root@VM-4-17-centos dir]# rm -f test.txt
[root@VM-4-17-centos dir]# rm -rf dir1
[root@VM-4-17-centos dir]# tree .
.
`-- dir4

1 directory, 0 files
[root@VM-4-17-centos dir]# rm -rf dir4
[root@VM-4-17-centos dir]# tree
.

0 directories, 0 files

image.png


选项 -i

防止用户的误操作导致某些文件或目录被删除

[root@VM-4-17-centos dir]# tree .
.
|-- dir1
|-- dir2
|   `-- dir3
|       `-- dir4
`-- test.txt

4 directories, 1 file
[root@VM-4-17-centos dir]# rm -ri test.txt 
rm: remove regular empty file ‘test.txt’? y
[root@VM-4-17-centos dir]# rm -r -i dir1
rm: remove directory ‘dir1’? y
[root@VM-4-17-centos dir]# tree
.
`-- dir2
    `-- dir3
        `-- dir4

3 directories, 0 files

image.png


stat

image.png


man

基本语法

man [选项] 命令

功能

查询C语言printf函数

[root@VM-4-17-centos ~]# man printf

image.png


在线手册介绍

查询man命令

[root@VM-4-17-centos dir]# man man

在线手册分为9章,每一章包含不同功能的文档;
1号手册包含可执行程序和命令
2号手册包含系统调用
3号手册包含库函数,是C语言的库函数
4号手册包含特别文件
5号手册文件格式
6号手册游戏相关
7号手册杂项,包括附件和一些变量
8号手册系统管理相关
9号手册内核例程

image.png


选项 number

已知pwd在1号手册,那么在其他手册中将找不到pwd命令
image.png

[root@VM-4-17-centos dir]# man pwd
[root@VM-4-17-centos dir]# man 1 pwd
[root@VM-4-17-centos dir]# man 2 pwd
No manual entry for pwd in section 2
[root@VM-4-17-centos dir]# man 3 pwd
No manual entry for pwd in section 3

image.png


选项 -k

[root@VM-4-17-centos dir]# man -k pwd
lckpwdf (3)          - get shadow password file entry
pwd (1)              - print name of current/working directory
pwd (1p)             - return working directory name
pwd (n)              - Return the absolute path of the current working directory
pwd.h (0p)           - password structure
pwdx (1)             - report current working directory of a process
ulckpwdf (3)         - get shadow password file entry
unix_chkpwd (8)      - Helper binary that verifies the password of the current user

image.png


选项 -a

[root@VM-4-17-centos dir]# man -a printf
--Man-- next: printf(1p) [ view (return) | skip (Ctrl-D) | quit (Ctrl-C) ]

image.png


cp

基本语法

cp [选项] 源文件/目录 目标文件/目录

功能

[root@VM-4-17-centos dir]# tree .
.
|-- dir1
|-- dir2
`-- test.txt

2 directories, 1 file
[root@VM-4-17-centos dir]# cp test.txt ./dir1
[root@VM-4-17-centos dir]# cp test.txt ./dir2
[root@VM-4-17-centos dir]# tree .
.
|-- dir1
|   `-- test.txt
|-- dir2
|   `-- test.txt
`-- test.txt

image.png


选项 - i

[root@VM-4-17-centos dir]# ls
dir1  dir2  text1.txt  text2.txt  text3.txt
[root@VM-4-17-centos dir]# cp -i text1.txt text2.txt 
cp: overwrite ‘text2.txt’? y

image.png


选项 -f/–force

[root@VM-4-17-centos dir]# cp -f text1.txt cp1.txt
[root@VM-4-17-centos dir]# ls
cp1.txt  dir1  dir2  text1.txt  text2.txt  text3.txt

image.png

[root@VM-4-17-centos dir]# cp --force text1.txt cp2.txt
[root@VM-4-17-centos dir]# ls
cp1.txt  cp2.txt  dir1  dir2  text1.txt  text2.txt  text3.txt

image.png


选项 -r/-R/–recursive

[root@VM-4-17-centos dir]# cp -r dir1 dircp
[root@VM-4-17-centos dir]# ls
cp1.txt  cp2.txt  dir1  dir2  dircp  text1.txt  text2.txt  text3.txt

image.png

[root@VM-4-17-centos dir]# cp -R dir1 dircp2
[root@VM-4-17-centos dir]# ls
dir1  dir2  dircp  dircp2  text1.txt  text2.txt  text3.txt

image.png

[root@VM-4-17-centos dir]# cp --recursive dir1 dircp3
[root@VM-4-17-centos dir]# ls
dir1  dir2  dircp  dircp2  dircp3  text1.txt  text2.txt  text3.txt

image.png



mv

基本语法

mv [选项] 源文件/目录 目标文件/目录

功能

重命名

[root@VM-4-17-centos dir]# ls
dir1  dir2  text1.txt  text2.txt  text3.txt
[root@VM-4-17-centos dir]# mv text1.txt name.txt
[root@VM-4-17-centos dir]# ls
dir1  dir2  name.txt  text2.txt  text3.txt
[root@VM-4-17-centos dir]# mv dir1 newdir1
[root@VM-4-17-centos dir]# ls
dir2  name.txt  newdir1  text2.txt  text3.txt

image.png
移动文件或目录

[root@VM-4-17-centos dir]# ls
dir1  dir2  text1.txt  text2.txt  text3.txt
[root@VM-4-17-centos dir]# mv text1.txt text2.txt 
mv: overwrite ‘text2.txt’? y
[root@VM-4-17-centos dir]# ls
dir1  dir2  text2.txt  text3.txt

image.png

[root@VM-4-17-centos dir]# ls
dir1  dir2  text1.txt  text2.txt  text3.txt
[root@VM-4-17-centos dir]# mv text1.txt dir1
[root@VM-4-17-centos dir]# tree
.
|-- dir1
|   `-- text1.txt
|-- dir2
|-- text2.txt
`-- text3.txt

2 directories, 3 file

image.png


选项 -f

[root@VM-4-17-centos dir]# tree .
.
|-- dir1
|-- dir2
|-- text1.txt
|-- text2.txt
`-- text3.txt

2 directories, 3 files
[root@VM-4-17-centos dir]# mv -f text1.txt text2.txt 
[root@VM-4-17-centos dir]# ls
dir1  dir2  text2.txt  text3.txt

选项 -i

[root@VM-4-17-centos dir]# tree .
.
|-- dir1
|-- dir2
|-- text2.txt
`-- text3.txt

2 directories, 2 files
[root@VM-4-17-centos dir]# mv -i text2.txt text3.txt 
mv: overwrite ‘text3.txt’? y
[root@VM-4-17-centos dir]# ls
dir1  dir2  text3.txt

cat

基本语法

cat [选项] 文件

功能

[root@VM-4-17-centos dir]# cat text1.txt 
hello world!
hello world!

image.png


选项 -n

[root@VM-4-17-centos dir]# cat -n text1.txt 
     1	hello world!
     2	hello world!
     3	hello world!
     4	
     5	hello world!
     6	hello world!
     7	hello world!
     8	
     9	
    10	hello world!
    11	hello world!
    12	
    13	hello world!
    14	hello world!
    15	hello world!
    16	hello world!
    17	hello

选项 -b

[root@VM-4-17-centos dir]# cat -b text1.txt 
     1	hello world!
     2	hello world!
     3	hello world!

     4	hello world!
     5	hello world!
     6	hello world!


     7	hello world!
     8	hello world!

     9	hello world!
    10	hello world!
    11	hello world!
    12	hello world!
    13	hello

选项 -s

[root@VM-4-17-centos dir]# cat -s text1.txt 
hello world!
hello world!
hello world!

hello world!
hello world!
hello world!

hello world!
hello world!

hello world!
hello world!
hello world!
hello world!
hello

tac

基本语法

tac [选项] 文件

功能

[root@VM-4-17-centos dir]# tac text1.txt 
hello 
hello world!
hello world!
hello world!
hello world!

hello world!
hello world!


hello world!
hello world!
hello world!

hello world!
hello world!
hello world!

more

基本语法

more [选项] 文件

功能

[root@VM-4-17-centos dir]# more text1.txt

按enter键可以向下翻阅文件内容,但是不能向上翻阅,还是不太方便
image.png
在查看文件内容时还可以搜索某一内容以/开始的文本内容

hello world!
hello world!
hello world!
hello world!
/weihe

image.png


选项 -n

[root@VM-4-17-centos dir]# more -5 text1.txt 
hello world!
hello world!

hello world!
hello world!
--More--(6%)

image.png


less

基本语法

less [选项] 文件

功能

[root@VM-4-17-centos dir]# less text1.txt

image.png


选项 -N

[root@VM-4-17-centos dir]# less -N text1.txt 

选项 -i

[root@VM-4-17-centos dir]# less -i text1.txt

image.png


选项 /字符串

image.png

选项 ?字符串

image.png


n

N




head

基本语法

head [选项] 文件

功能

[root@VM-4-17-centos dir]# head text1.txt 
hello world!
HELLO WORLD!
HELLO WORLD!

hello world!
hello world!
hello world!
hello world!
haha
HAHA

选项 -n

[root@VM-4-17-centos dir]# head -5 text1.txt 
hello world!
HELLO WORLD!
HELLO WORLD!

hello world!

tail

基本语法

tail [选项] 文件

功能

[root@VM-4-17-centos dir]# tail text1.txt 
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!

选项 -n<行数>

[root@VM-4-17-centos dir]# tail -n5 text1.txt 
hello world!
hello world!
hello world!
hello world!
hello world!

选项 -f

[root@VM-4-17-centos dir]# tail -f text1.txt 
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!

重定向

输出重定向 >

基本语法

命令 > 文件

功能

[root@VM-4-17-centos dir]# echo "you can see me" >  newfile.txt

image.png


输入重定向 <

基本语法

命令 < 文件

功能

[root@VM-4-17-centos dir]# echo "you can not see me" < newfile.txt
you can not see me

追加 >>

基本语法

命令 >> 文件

功能

[root@VM-4-17-centos dir]# echo hello world! >> newfile.txt 
[root@VM-4-17-centos dir]# cat newfile.txt 
you can see me
hello world!

标准输入/标准输出/标准错误

Linux运行时会默认打开三个文件:

>stdout重定向到文件,<stdin重定向到文件;


管道 |

功能

对于文件中的内容输出前五行

[root@VM-4-17-centos dir]# cat text1.txt | head -5
hello world!
HELLO WORLD!
HELLO WORLD!

hello world!

date

基本语法

date [选项] [+格式]

功能

[root@VM-4-17-centos dir]# date
Sun Oct 23 12:36:06 CST 2022

指定格式显示时间

[root@VM-4-17-centos dir]# date +%Y/%m/%d-%H:%M:%S
2022/10/23-12:40:21
[root@VM-4-17-centos dir]# date +%F--%X
2022-10-23--12:41:22 PM

时间戳

获取时间戳

[root@VM-4-17-centos dir]# date +%s
1666500176

时间戳转换为具体日期 -d

[root@VM-4-17-centos dir]# date -d @1666500176
Sun Oct 23 12:42:56 CST 2022

时间戳转换指定格式

[root@VM-4-17-centos dir]# date -d @1666500176 +%Y/%m/%d-%H:%M:%S
2022/10/23-12:42:56

设置时间 -s

[root@VM-4-17-centos dir]# date -s"2022-10-24 12:56:01"
Mon Oct 24 12:56:01 CST 2022

cal

基本语法

cal [选项][月份][年份]

功能

[root@VM-4-17-centos ~]# 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
[root@VM-4-17-centos ~]# cal 2022
                               2022                               

       January               February                 March       
Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa
                   1          1  2  3  4  5          1  2  3  4  5
 2  3  4  5  6  7  8    6  7  8  9 10 11 12    6  7  8  9 10 11 12
 9 10 11 12 13 14 15   13 14 15 16 17 18 19   13 14 15 16 17 18 19
16 17 18 19 20 21 22   20 21 22 23 24 25 26   20 21 22 23 24 25 26
23 24 25 26 27 28 29   27 28                  27 28 29 30 31
30 31
        April                   May                   June        
Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa
                1  2    1  2  3  4  5  6  7             1  2  3  4
 3  4  5  6  7  8  9    8  9 10 11 12 13 14    5  6  7  8  9 10 11
10 11 12 13 14 15 16   15 16 17 18 19 20 21   12 13 14 15 16 17 18
17 18 19 20 21 22 23   22 23 24 25 26 27 28   19 20 21 22 23 24 25
24 25 26 27 28 29 30   29 30 31               26 27 28 29 30

        July                  August                September     
Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa
                1  2       1  2  3  4  5  6                1  2  3
 3  4  5  6  7  8  9    7  8  9 10 11 12 13    4  5  6  7  8  9 10
10 11 12 13 14 15 16   14 15 16 17 18 19 20   11 12 13 14 15 16 17
17 18 19 20 21 22 23   21 22 23 24 25 26 27   18 19 20 21 22 23 24
24 25 26 27 28 29 30   28 29 30 31            25 26 27 28 29 30
31
       October               November               December      
Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa
                   1          1  2  3  4  5                1  2  3
 2  3  4  5  6  7  8    6  7  8  9 10 11 12    4  5  6  7  8  9 10
 9 10 11 12 13 14 15   13 14 15 16 17 18 19   11 12 13 14 15 16 17
16 17 18 19 20 21 22   20 21 22 23 24 25 26   18 19 20 21 22 23 24
23 24 25 26 27 28 29   27 28 29 30            25 26 27 28 29 30 31
30 31

[root@VM-4-17-centos ~]# cal 10 2022
    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


选项 -3

[root@VM-4-17-centos ~]# 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

选项 -j

[root@VM-4-17-centos ~]# 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

选项 -y

[root@VM-4-17-centos ~]#cal -y 2022

find

基本语法

find 文件名 选项

功能

[root@VM-4-17-centos dir]# find -name test.txt 
./test.txt
./dir2/test.txt
./dir1/test.txt
[root@VM-4-17-centos dir]# find /root/dir/ -name test.txt 
/root/dir/test.txt
/root/dir/dir2/test.txt
/root/dir/dir1/test.txt

whereis

基本语法

whereis [选项] 指令名或文件名

功能

[root@VM-4-17-centos dir]# whereis test.txt
test: /usr/bin/test /usr/share/man/man1/test.1.gz /usr/share/man/man1p/test.1p.gz

wc

基本语法

wc [选项] 文件名

功能

[root@VM-4-17-centos dir]# cat test.txt 
1111
22221111
1111
1111
hello
HELLO
heLLo
[root@VM-4-17-centos dir]# wc -l test.txt 
7 test.txt

grep

基本语法

grep [选项] 某个字符串 待查找文件 

功能

[root@VM-4-17-centos dir]# grep '1111' test.txt 
1111
1111
1111
1111
1111
1111
1111
1111

选项 -i

[root@VM-4-17-centos dir]# grep -i 'hello' test.txt 
hello
HELLO
heLLo

选项 -n

[root@VM-4-17-centos dir]# grep -i -n 'hello' test.txt 
21:hello
22:HELLO
23:heLLo

选项 -v

[root@VM-4-17-centos dir]# grep -v -n 'hello' test.txt 
1:1111
2:22221111
3:1111
4:1111
6:HELLO
7:heLLo

与 | 结合使用

[root@VM-4-17-centos dir]# cat test.txt 
1111
22221111
1111
1111
hello
HELLO
heLLo
[root@VM-4-17-centos dir]# grep '1111' test.txt | wc -l
4

#uniq

基本语法

nuiq [选项] 文件

功能

[root@VM-4-17-centos dir]# cat test.txt 
1111
2222
2222
1111
1111
4444
4444
1111
4444
[root@VM-4-17-centos dir]# uniq test.txt 
1111
2222
1111
4444
1111
4444

在这里插入图片描述


sort

基本语法

sort [选项] 文件

功能

[root@VM-4-17-centos dir]# sort test.txt 
1111
1111
1111
1111
1234
1324
2222
2222
4444
4444
4444
abcd
bcde

于是我们可以先排序再去重

[root@VM-4-17-centos dir]# cat test.txt 
1111
2222
2222
1111
1111
4444
4444
1111
4444
1234
1324
abcd
bcde
[root@VM-4-17-centos dir]# sort test.txt | uniq
1111
1234
1324
2222
4444
abcd
bcde

zip/unzip

打包和压缩的目的

zip

基本语法

tar [选项] 压缩后文件名.zip 待压缩文件

功能

[root@VM-4-17-centos dir]# ls
dir1  dir2  test.txt
[root@VM-4-17-centos dir]# zip dir1.zip dir1
  adding: dir1/ (stored 0%)
[root@VM-4-17-centos dir]# ls
dir1  dir1.zip  dir2  test.txt
[root@VM-4-17-centos dir]# zip test.zip test.txt 
  adding: test.txt (deflated 29%)
[root@VM-4-17-centos dir]# ls
dir1  dir1.zip  dir2  dir3  dir4  test.txt  test.zip

选项 -r

[root@VM-4-17-centos dir]# zip -r dir2.zip dir2
  adding: dir2/ (stored 0%)
  adding: dir2/test.txt (deflated 29%)

unzip

基本语法

unzip 压缩文件名.zip 解压后文件名

功能

image.png

[root@VM-4-17-centos dir]# unzip dir2.zip 
Archive:  dir2.zip
   creating: dir2/
  inflating: dir2/test.txt

image.png


选项 -d

[root@VM-4-17-centos dir]# unzip dir2.zip -d ./dir3/
Archive:  dir2.zip
   creating: ./dir3/dir2/
  inflating: ./dir3/dir2/test.txt 

image.png


tar

基本语法

tar [选项] 文件/目录

功能


选项 -c

选项 -t

选项 -z

image.png
打包dir1目录并压缩打包后的文件为dir1.tgz

[root@VM-4-17-centos dir]# tar -czf dir1.tgz dir1

image.png


选项 -j

[root@VM-4-17-centos dir]# tar -cjf dir2.tgz dir2

image.png

选项 -v

[root@VM-4-17-centos dir]# tar -czvf dir2.tgz dir2
dir2/
dir2/test.txt

image.png

选项 -f

选项 -x

[root@VM-4-17-centos dir3]# tar -xzvf dir1.tgz 
dir1/
dir1/test.txt

image.png


选项 -C

[root@VM-4-17-centos dir]# tar -xzvf dir2.tgz -C ./dir4

image.png


bc

功能

[root@VM-4-17-centos dir4]# bc

image.png


uname

基本语法

uname [选项] 

功能

[root@VM-4-17-centos dir4]# uname
Linux

选项 -r

[root@VM-4-17-centos dir4]# uname -r
3.10.0-1160.71.1.el7.x86_64

选项 -a/–all

[root@VM-4-17-centos dir4]# uname -a
Linux VM-4-17-centos 3.10.0-1160.71.1.el7.x86_64 #1 SMP Tue Jun 28 15:37:28 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
[root@VM-4-17-centos dir4]# uname --all
Linux VM-4-17-centos 3.10.0-1160.71.1.el7.x86_64 #1 SMP Tue Jun 28 15:37:28 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

lscpu

[root@VM-4-17-centos dir]# lscpu
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                2
On-line CPU(s) list:   0,1
Thread(s) per core:    1
Core(s) per socket:    2
Socket(s):             1
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 94
Model name:            Intel(R) Xeon(R) Gold 6133 CPU @ 2.50GHz
Stepping:              3
CPU MHz:               2494.140
BogoMIPS:              4988.28
Hypervisor vendor:     KVM
Virtualization type:   full
L1d cache:             32K
L1i cache:             32K
L2 cache:              4096K
L3 cache:              28160K
NUMA node0 CPU(s):     0,1
Flags:                 fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx rdseed adx smap clflushopt xsaveopt xsavec xgetbv1 arat

lsmem

[root@VM-4-17-centos dir]# lsmem
RANGE                                 SIZE  STATE REMOVABLE BLOCK
0x0000000000000000-0x000000007fffffff   2G online        no  0-15

Memory block size:       128M
Total online memory:       2G
Total offline memory:      0B

df

基本语法

df [选项] 文件

功能

[root@VM-4-17-centos dir]# df test.txt 
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/vda1       41152716 3978024  35396868  11% /
[root@VM-4-17-centos dir]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs         1012336       0   1012336   0% /dev
tmpfs            1023340      24   1023316   1% /dev/shm
tmpfs            1023340     540   1022800   1% /run
tmpfs            1023340       0   1023340   0% /sys/fs/cgroup
/dev/vda1       41152716 3977912  35396980  11% /
tmpfs             204672       0    204672   0% /run/user/0

选项 -h

[root@VM-4-17-centos dir]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        989M     0  989M   0% /dev
tmpfs          1000M   24K 1000M   1% /dev/shm
tmpfs          1000M  540K  999M   1% /run
tmpfs          1000M     0 1000M   0% /sys/fs/cgroup
/dev/vda1        40G  3.8G   34G  11% /
tmpfs           200M     0  200M   0% /run/user/0

热键相关

tab

CTRL+c

Ctrl+d

CTRL +r


关机指令

基本语法

shutdown [选项] 

选项 -h

[root@VM-4-17-centos ~]# shutdown -h
Shutdown scheduled for Thu 2022-10-27 20:23:58 CST, use 'shutdown -c' to cancel.
[root@VM-4-17-centos ~]# 
Broadcast message from root@VM-4-17-centos (Thu 2022-10-27 20:22:58 CST):

The system is going down for power-off at Thu 2022-10-27 20:23:58 CST!

image.png

选项 -r

[root@VM-4-17-centos ~]# shutdown -r
Shutdown scheduled for Thu 2022-10-27 20:22:59 CST, use 'shutdown -c' to cancel.
[root@VM-4-17-centos ~]# 
Broadcast message from root@VM-4-17-centos (Thu 2022-10-27 20:21:59 CST):

The system is going down for reboot at Thu 2022-10-27 20:22:59 CST!

image.png

选项 -t

[root@VM-4-17-centos ~]# shutdown -t 60
Shutdown scheduled for Thu 2022-10-27 20:21:12 CST, use 'shutdown -c' to cancel.
[root@VM-4-17-centos ~]# 
Broadcast message from root@VM-4-17-centos (Thu 2022-10-27 20:20:12 CST):

The system is going down for power-off at Thu 2022-10-27 20:21:12 CST!

image.png



echo

语法

echo 内容

功能

[root@VM-4-17-centos dir]# echo "hello world"
hello world
[root@VM-4-17-centos dir]# echo "hello world"
hello world
[root@VM-4-17-centos dir]# echo hello world
hello world

image.png

[root@VM-4-17-centos dir]# echo hello world! > text.txt
[root@VM-4-17-centos dir]# cat text.txt 
hello world!

image.png


printf

在命令行格式化输出内容,同C语言printf用法

[root@VM-4-17-centos ~]# printf "hello,%d\n" 100
hello,100

who

查看当前登录的所有的用户

[root@VM-4-17-centos ~]# who
root     pts/0        2022-10-27 20:17 (221.176.187.238)
weihe    pts/1        2022-10-27 20:27 (221.176.187.238)

image.png


which

基本语法

which [选项] 待查指令

命令

[root@VM-4-17-centos dir]# which pwd
/usr/bin/pwd
[root@VM-4-17-centos dir]# which ls
alias ls='ls --color=auto'
	/usr/bin/ls

image.png


alias/unalias

alias

格式

alias 新名字==指令串

功能

[root@VM-4-17-centos dir]# alias weihe='ls -l --color=auto'
[root@VM-4-17-centos dir]# weihe
total 12
drwxr-xr-x 2 root root 4096 Oct 27 17:26 dir1
drwxr-xr-x 2 root root 4096 Oct 27 17:26 dir2
-rw-r--r-- 1 root root   42 Oct 27 17:35 test.txt
[root@VM-4-17-centos dir]# alias
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias weihe='ls -l --color=red'
alias weihe2='=ls -l'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'

其中--color=auto是啥?
其实是让指令执行的结果带上高亮的颜色;


unalias

格式

unalics 指令别名

功能

[root@VM-4-17-centos dir]# unalias weihe
[root@VM-4-17-centos dir]# unalias weihe2


结语

本节主要介绍了Linux中一些常用的指令,但还有着许多的指令没有涉及,以后用到时需要主动查找学习。
下次再见!


举报

相关推荐

0 条评论