Linux基本指令(一)

news2024/10/6 18:35:39

文章目录

  • Linux常用基本指令
    • 1. ls
    • 2. pwd
    • 3. cd
    • 4. touch
    • 5. tree
    • 6. mkdir
    • 7. rmdir
    • 8. rm
    • 9. man
    • 10. cp
    • 11. mv
    • 12. cat
    • 13. echo
    • 14. wc
    • 15. more
    • 16. less
    • 17. head
    • 18. tail
    • 19. date
    • 20. cal
    • 21. sort
    • 22. uniq
    • 23. find
    • 24. which
    • 25. whereis
    • 26. alias
    • 27. grep
    • 28. zip/unzip
    • 29. tar
    • 30. bc
    • 31. uname -r
    • 32. 热键
    • 33. 创建私人用户

Linux常用基本指令

前言:linux不止命令,命令这是工具文件

1. ls

ls [选项] [目录或文件]

作用:列出该目录下所有的子目录与文件

常见选项:

-a 列出目录下的所有文件,包括以.开头的隐含文件

[root@VM-12-12-centos ~]# ls -a
.  ..  .bash_history  .bash_logout  .bash_profile  .bashrc  .cache  .config  .cshrc  jyh  .pip  .pydistutils.cfg  .ssh  .tcshrc

-l 列出文件详细信息(ls -l = ll)

[root@VM-12-12-centos ~]# ls -l
total 4
drwxr-xr-x 3 root root 4096 Nov 11 16:26 jyh

-R 列出所有子目录下的文件(递归)

[root@VM-12-12-centos ~]# tree
.
`-- jyh
    `-- instruction
        |-- a.out
        |-- README.txt
        `-- test.c

2 directories, 3 files
[root@VM-12-12-centos ~]# ls -R
.:
jyh

./jyh:
instruction

./jyh/instruction:
a.out  README.txt  test.c

-i 输出文件的i节点的索引信息。如ls -ai 指定文件

[root@VM-12-12-centos ~]# ls -ai
393219 .       2 ..  393318 .bash_history  397151 .bash_logout  397152 .bash_profile  397153 .bashrc  393280 .cache  393313 .config  397154 .cshrc  656510 jyh  393690 .pip  394368 .pydistutils.cfg  135701 .ssh  397155 .tcshrc

-r 对目录反向排序

[root@VM-12-12-centos jyh]# ls -r
test  instruction
[root@VM-12-12-centos jyh]# ls
instruction  test

-n 用数字的UID,GID代替名称(Linux 系统中,每个用户的 ID 细分为 2 种,分别是用户 ID(User ID,简称 UID)和组 ID(Group ID,简称 GID))

[root@VM-12-12-centos jyh]# ls -n
total 8
drwxr-xr-x 2 0 0 4096 Nov 11 16:57 instruction
drwxr-xr-x 2 0 0 4096 Nov 11 17:26 test
[root@VM-12-12-centos jyh]# ls -l
total 8
drwxr-xr-x 2 root root 4096 Nov 11 16:57 instruction
drwxr-xr-x 2 root root 4096 Nov 11 17:26 test

2. pwd

作用:显示用户当前所在目录

[root@VM-12-12-centos ~]# pwd
/root

建议:每一次登录,或者长时间没操作都指向此指令

3. cd

cd 目录名

作用:改变工作目录

.表示当前路径,…表示上级路径

cd … :返回上级目录

[root@VM-12-12-centos ~]# cd jyh
[root@VM-12-12-centos jyh]# pwd
/root/jyh
[root@VM-12-12-centos jyh]# cd test
[root@VM-12-12-centos test]# pwd
/root/jyh/test
[root@VM-12-12-centos test]# cd ..
[root@VM-12-12-centos jyh]# pwd
/root/jyh

cd /root/jyh/linux/ : 绝对路径(/表示Linux的路径分隔符)

[root@VM-12-12-centos ~]# ls -R
.:
jyh

./jyh:
instruction  test

./jyh/instruction:
a.out  README.txt  test.c

./jyh/test:
test.txt
[root@VM-12-12-centos ~]# pwd
/root
[root@VM-12-12-centos ~]# cd jyh/test/
[root@VM-12-12-centos test]# pwd/root/jyh/test

cd …/day01/ : 相对路径

[root@VM-12-12-centos ~]# ls -R
.:
jyh

./jyh:
instruction  test

./jyh/instruction:
a.out  README.txt  test.c

./jyh/test:
test.txt
[root@VM-12-12-centos ~]# pwd
/root
[root@VM-12-12-centos ~]# cd jyh/instruction/
[root@VM-12-12-centos instruction]# pwd
/root/jyh/instruction
[root@VM-12-12-centos instruction]# cd ../test/
[root@VM-12-12-centos test]# pwd
/root/jyh/test

cd ~ : 进入用户家目录

[root@VM-12-12-centos ~]# ls -R
.:
jyh

./jyh:
instruction  test

./jyh/instruction:
a.out  README.txt  test.c

./jyh/test:
test.txt
[root@VM-12-12-centos ~]# cd jyh/test/
[root@VM-12-12-centos test]# pwd
/root/jyh/test
[root@VM-12-12-centos test]# cd ~
[root@VM-12-12-centos ~]# pwd
/root

cd - :返回最近访问目录

[root@VM-12-12-centos ~]# pwd
/root
[root@VM-12-12-centos ~]# ls -R
.:
jyh

./jyh:
instruction  test

./jyh/instruction:
a.out  README.txt  test.c

./jyh/test:
test.txt
[root@VM-12-12-centos ~]# cd jyh/instruction/
[root@VM-12-12-centos instruction]# pwd
/root/jyh/instruction
[root@VM-12-12-centos instruction]# cd ../test/
[root@VM-12-12-centos test]# pwd
/root/jyh/test
[root@VM-12-12-centos test]# cd -
/root/jyh/instruction
[root@VM-12-12-centos instruction]# pwd
/root/jyh/instruction

补充:/ : 表示linux的根目录

[root@VM-12-12-centos /]# pwd
/

4. touch

touch [选项]

作用:在当前路径下创建一个普通文件

5. tree

作用:以树状结构显示Linux执行的目录结构(当没有此指令时,在root用户下,输入yum install -y tree

[root@VM-12-12-centos ~]# pwd
/root
[root@VM-12-12-centos ~]# whoami
root
[root@VM-12-12-centos ~]# tree
.
`-- jyh
    |-- instruction
    |   |-- a.out
    |   |-- README.txt
    |   `-- test.c
    |-- study_2022_11_11
    `-- test
        `-- test.txt

4 directories, 4 files

6. mkdir

mkdir [选项] 目录名

功能:在当前目录下创建一个目录

mkdir -p test/test1/ :递归建立多个目录

7. rmdir

rmdir [选项] [文件名]

作用:删除空目录

8. rm

rm [选项] [目录/文件名]

作用:删除文件或目录

-f : 强制删除

-r : 删除目录及其下所有文件

9. man

man [选项] 命令

作用:查看联机手册

没有此指令可以直接指向该指令下载:

yum install -y man-pages

手册分为八册:

  1. 普通命令
  2. 系统调用
  3. 库函数
  4. 特殊文件
  5. 文件的格式和约定
  6. 游戏
  7. 杂项(包括宏包和约定)
  8. 系统管理命令
  9. 内核例程[非标准]

man 1 printf(在1号手册中查找printf指令)

10. cp

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

作用:复制文件或目录

//操作:把instruction1目录中的cp.txt复制到mydir目录中
[root@VM-12-12-centos instruction1]# ll
total 4
-rw-r--r-- 1 root root    0 Nov 15 20:19 cp.txt
drwxr-xr-x 2 root root 4096 Nov 16 21:06 mydir
[root@VM-12-12-centos instruction1]# tree
.
|-- cp.txt
`-- mydir

1 directory, 1 file
[root@VM-12-12-centos instruction1]# cp cp.txt mydir/
[root@VM-12-12-centos instruction1]# ll
total 4
-rw-r--r-- 1 root root    0 Nov 15 20:19 cp.txt
drwxr-xr-x 2 root root 4096 Nov 16 21:06 mydir
[root@VM-12-12-centos instruction1]# tree
.
|-- cp.txt
`-- mydir
    `-- cp.txt

1 directory, 2 files

-f 或 --force 强行复制文件或目录

-r 递归处理 将指定目录下的文件与子目录一并处理

//操作:把当前目录下的文件复制到上级目录
[root@VM-12-12-centos instruction1]# ll
total 4
-rw-r--r-- 1 root root    0 Nov 15 20:19 cp.txt
drwxr-xr-x 2 root root 4096 Nov 16 21:06 mydir
[root@VM-12-12-centos instruction1]# cd ..
[root@VM-12-12-centos study_2022_11_11]# ll
total 8
drwxr-xr-x 3 root root 4096 Nov 16 21:05 instruction1
-rw-r--r-- 1 root root   53 Nov 12 16:58 README.txt
[root@VM-12-12-centos study_2022_11_11]# cd instruction1/
[root@VM-12-12-centos instruction1]# ll
total 4
-rw-r--r-- 1 root root    0 Nov 15 20:19 cp.txt
drwxr-xr-x 2 root root 4096 Nov 16 21:06 mydir
[root@VM-12-12-centos instruction1]# cp cp.txt ..
[root@VM-12-12-centos instruction1]# cd ..
[root@VM-12-12-centos study_2022_11_11]# ll
total 8
-rw-r--r-- 1 root root    0 Nov 16 21:11 cp.txt
drwxr-xr-x 3 root root 4096 Nov 16 21:05 instruction1
-rw-r--r-- 1 root root   53 Nov 12 16:58 README.txt
//把当前目录下的目录复制到上级目录中
drwxr-xr-x 2 root root 4096 Nov 16 21:06 mydir
[root@VM-12-12-centos instruction1]# tree
.
|-- cp.txt
`-- mydir
    `-- cp.txt

1 directory, 2 files
[root@VM-12-12-centos instruction1]# cd ..
[root@VM-12-12-centos study_2022_11_11]# ll
total 8
drwxr-xr-x 3 root root 4096 Nov 16 21:05 instruction1
-rw-r--r-- 1 root root   53 Nov 12 16:58 README.txt
[root@VM-12-12-centos study_2022_11_11]# cd instruction1/
[root@VM-12-12-centos instruction1]# ll
total 4
-rw-r--r-- 1 root root    0 Nov 15 20:19 cp.txt
drwxr-xr-x 2 root root 4096 Nov 16 21:06 mydir
[root@VM-12-12-centos instruction1]# tree
.
|-- cp.txt
`-- mydir
    `-- cp.txt

1 directory, 2 files
[root@VM-12-12-centos instruction1]# cp mydir ..
cp: omitting directory ‘mydir’ //报错:省略目录
[root@VM-12-12-centos instruction1]# cp -r mydir/
cp: missing destination file operand after ‘mydir/’ //报错:没有目标文件
Try 'cp --help' for more information.
[root@VM-12-12-centos instruction1]# cp -r mydir ..
[root@VM-12-12-centos instruction1]# ll
total 4
-rw-r--r-- 1 root root    0 Nov 15 20:19 cp.txt
drwxr-xr-x 2 root root 4096 Nov 16 21:06 mydir
[root@VM-12-12-centos instruction1]# cd ..
[root@VM-12-12-centos study_2022_11_11]# ll
total 12
drwxr-xr-x 3 root root 4096 Nov 16 21:05 instruction1
drwxr-xr-x 2 root root 4096 Nov 16 21:16 mydir
-rw-r--r-- 1 root root   53 Nov 12 16:58 README.txt

11. mv

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

-f : 强制剪切

作用一:剪切目录或文件

//剪切文件和目录到上级目录下
[root@VM-12-12-centos instruction1]# ll
total 4
-rw-r--r-- 1 root root    0 Nov 16 21:24 mv.txt
drwxr-xr-x 2 root root 4096 Nov 16 21:06 mydir
[root@VM-12-12-centos instruction1]# ls .. //上级目录
instruction1  README.txt
[root@VM-12-12-centos instruction1]# mv mv.txt 
mv: missing destination file operand after ‘mv.txt’ //报错:没有目标文件或目录
Try 'mv --help' for more information.
[root@VM-12-12-centos instruction1]# mv mv.txt ..
[root@VM-12-12-centos instruction1]# ls ..
instruction1  mv.txt  README.txt
[root@VM-12-12-centos instruction1]# ll
total 4
drwxr-xr-x 2 root root 4096 Nov 16 21:06 mydir
[root@VM-12-12-centos instruction1]# mv mydir/ .. //默认递归剪切
[root@VM-12-12-centos instruction1]# ls .. 
instruction1  mv.txt  mydir  README.txt
[root@VM-12-12-centos instruction1]# ll
total 0
[root@VM-12-12-centos instruction1]# cd .. //回到上级目录
[root@VM-12-12-centos study_2022_11_11]# tree
.
|-- instruction1
|-- mv.txt
|-- mydir
|   `-- cp.txt
`-- README.txt

作用二:剪切自身且目标文件在当前目录中不存在的时候就是重命名

//重命名文件和目录
[root@VM-12-12-centos instruction1]# ll
total 4
-rw-r--r-- 1 root root    0 Nov 16 21:24 mv.txt
drwxr-xr-x 2 root root 4096 Nov 16 21:06 mydir
[root@VM-12-12-centos instruction1]# mv mydir dir
[root@VM-12-12-centos instruction1]# ll
total 4
drwxr-xr-x 2 root root 4096 Nov 16 21:06 dir
-rw-r--r-- 1 root root    0 Nov 16 21:24 mv.txt
[root@VM-12-12-centos instruction1]# mv mv.txt mymv.txt
[root@VM-12-12-centos instruction1]# ll
total 4
drwxr-xr-x 2 root root 4096 Nov 16 21:06 dir
-rw-r--r-- 1 root root    0 Nov 16 21:24 mymv.txt
[root@VM-12-12-centos instruction1]# tree
.
|-- dir
|   `-- cp.txt
`-- mymv.txt

1 directory, 2 files

12. cat

cat [选项] [文件]

-n : 对输出的所有行进行编号

作用:查看目标文件的内容

[root@VM-12-12-centos instruction1]# nano myfile.txt  //编辑
[root@VM-12-12-centos instruction1]# ll
total 4
-rw-r--r-- 1 root root 31 Nov 16 21:35 myfile.txt
[root@VM-12-12-centos instruction1]# cat myfile.txt 
这是我要展示的内容!
[root@VM-12-12-centos instruction1]# cat -n myfile.txt 
     1	这是我要展示的内容!

13. echo

echo 内容

作用:在显示器上显示内容(用于查看短文本)

-e : 打印出转义字符

-n : 去掉echo末尾的换行符

[root@VM-12-12-centos instruction1]# clear
[root@VM-12-12-centos instruction1]# echo "hello Linux"
hello Linux
[root@VM-12-12-centos instruction1]# echo "hello Linux\n"
hello Linux\n
[root@VM-12-12-centos instruction1]# echo -e "hello Linux\n"
hello Linux

[root@VM-12-12-centos instruction1]# 
[root@VM-12-12-centos instruction1]# echo -e -n  "hello Linux\n"
hello Linux
[root@VM-12-12-centos instruction1]#

补充:> :输出重定向(覆盖式写入)

>文件名:清空文件内容

[root@VM-12-12-centos instruction1]# ll
total 4
-rw-r--r-- 1 root root 31 Nov 16 21:35 myfile.txt
[root@VM-12-12-centos instruction1]# cat myfile.txt 
这是我要展示的内容!
[root@VM-12-12-centos instruction1]# echo "hello Linux" > myfile.txt 
[root@VM-12-12-centos instruction1]# ll
total 4
-rw-r--r-- 1 root root 12 Nov 16 21:49 myfile.txt
[root@VM-12-12-centos instruction1]# cat myfile.txt 
hello Linux
[root@VM-12-12-centos instruction1]#

怎么去理解这个输出重定向呢?

//现象一:覆盖式写入(写入之前会先清空文件)
[root@VM-12-12-centos instruction1]# ll
total 4
-rw-r--r-- 1 root root 12 Nov 16 21:49 myfile.txt
[root@VM-12-12-centos instruction1]# cat myfile.txt 
hello Linux
[root@VM-12-12-centos instruction1]# echo "hello" > myfile.txt 
[root@VM-12-12-centos instruction1]# cat myfile.txt 
hello
[root@VM-12-12-centos instruction1]# echo "qqqweef" > myfile.txt 
[root@VM-12-12-centos instruction1]# cat myfile.txt 
qqqweef
[root@VM-12-12-centos instruction1]#
//现象二:追加
[root@VM-12-12-centos instruction1]# ll
total 4
-rw-r--r-- 1 root root 8 Nov 16 21:59 myfile.txt
[root@VM-12-12-centos instruction1]# cat myfile.txt 
qqqweef
[root@VM-12-12-centos instruction1]# echo "hello" >> myfile.txt 
[root@VM-12-12-centos instruction1]# cat myfile.txt 
qqqweef
hello
[root@VM-12-12-centos instruction1]# echo "hello" >> myfile.txt
[root@VM-12-12-centos instruction1]# echo "hello" >> myfile.txt
[root@VM-12-12-centos instruction1]# cat  myfile.txt 
qqqweef
hello
hello
hello
[root@VM-12-12-centos instruction1]#

补充: >> :追加重定向

补充: < :输入重定向

[root@VM-12-12-centos instruction1]# ll
total 4
-rw-r--r-- 1 root root 26 Nov 16 22:02 myfile.txt
[root@VM-12-12-centos instruction1]# cat myfile.txt 
qqqweef
hello
hello
hello
[root@VM-12-12-centos instruction1]# cat < myfile.txt  //把文件内容读到cat打印
qqqweef
hello
hello
hello

14. wc

作用:计算字数

[root@VM-12-12-centos instruction1]# ll
total 4
-rw-r--r-- 1 root root 26 Nov 16 22:02 myfile.txt
[root@VM-12-12-centos instruction1]# cat myfile.txt 
qqqweef
hello
hello
hello
[root@VM-12-12-centos instruction1]# wc -l myfile.txt 
4 myfile.txt
[root@VM-12-12-centos instruction1]# 

-c或–bytes 或–chars 只显示bytes数

-l或–lines 显示行数

-w或–words 只显示字数

–version 显示版本信息

15. more

more [选项] [文件]

作用:查看长文本内容

-n : 对输出的所有行编号

q : 退出more

//查看一下myfile.txt大文本
[root@VM-12-12-centos instruction1]# ll
total 4
-rw-r--r-- 1 root root 26 Nov 16 22:02 myfile.txt
[root@VM-12-12-centos instruction1]# pwd
/root/study_2022_11_11/instruction1
[root@VM-12-12-centos instruction1]# cnt=0; while [ $cnt -le 100 ]; do echo "hello $cnt"; let cnt++; done > myfile.txt 
[root@VM-12-12-centos instruction1]# ll
total 4
-rw-r--r-- 1 root root 900 Nov 17 23:25 myfile.txt
[root@VM-12-12-centos instruction1]# cat myfile.txt 
hello 0
hello 1
hello 2
hello 3
hello 4
hello 5
hello 6
hello 7
hello 8
hello 9
hello 10
hello 11
hello 12
hello 13
hello 14
hello 15
hello 16
hello 17
hello 18
hello 19
hello 20
hello 21
hello 22
hello 23
hello 24
hello 25
hello 26
hello 27
hello 28
hello 29
hello 30
hello 31
hello 32
hello 33
hello 34
hello 35
hello 36
hello 37
hello 38
hello 39
hello 40
hello 41
hello 42
hello 43
hello 44
hello 45
hello 46
hello 47
hello 48
hello 49
hello 50
hello 51
hello 52
hello 53
hello 54
hello 55
hello 56
hello 57
hello 58
hello 59
hello 60
hello 61
hello 62
hello 63
hello 64
hello 65
hello 66
hello 67
hello 68
hello 69
hello 70
hello 71
hello 72
hello 73
hello 74
hello 75
hello 76
hello 77
hello 78
hello 79
hello 80
hello 81
hello 82
hello 83
hello 84
hello 85
hello 86
hello 87
hello 88
hello 89
hello 90
hello 91
hello 92
hello 93
hello 94
hello 95
hello 96
hello 97
hello 98
hello 99
hello 100
[root@VM-12-12-centos instruction1]# more myfile.txt

16. less

less [选项] 文件

作用:查看大文本内容

  1. 可以使用 pageup和pagedown等按键的功能来往前往后翻看文件,更容易用来查看一个文件的内容!
  2. less 工具也是对文件或其它输出进行分页显示的工具

/字符串:向下搜索“字符串”

?字符串:向上搜索”字符串“

q : 退出

17. head

head [选项] [文件]

作用:用来显示档案的开头至标准输出中,默认head命令打印其相应文件的开头10行

-n<行数> 显示的行数

//原本myfile.txt文件中有一百行,head默认显示前十行
[root@VM-12-12-centos instruction1]# ll
total 4
-rw-r--r-- 1 root root 900 Nov 17 23:25 myfile.txt
[root@VM-12-12-centos instruction1]# head myfile.txt 
hello 0
hello 1
hello 2
hello 3
hello 4
hello 5
hello 6
hello 7
hello 8
hello 9
[root@VM-12-12-centos instruction1]# 
[root@VM-12-12-centos instruction1]# ll
total 4
-rw-r--r-- 1 root root 900 Nov 17 23:25 myfile.txt
[root@VM-12-12-centos instruction1]# head -n3 myfile.txt 
hello 0
hello 1
hello 2
[root@VM-12-12-centos instruction1]# 

18. tail

tail [必要选项] [选择选项] [文件]

作用: 用于显示指定文件末尾内容,不指定文件时,作为输入信息进行处理。常用查看日志文件

-f : 循环读取

-n<行数> 显示行数

//myfile.txt文件中有100行hello
[root@VM-12-12-centos instruction1]# ll
total 4
-rw-r--r-- 1 root root 900 Nov 17 23:25 myfile.txt
[root@VM-12-12-centos instruction1]# tail myfile.txt 
hello 91
hello 92
hello 93
hello 94
hello 95
hello 96
hello 97
hello 98
hello 99
hello 100
//默认是文本最后十行

补充:| : 此符号表示命令行管道

root@VM-12-12-centos instruction1]# clear
[root@VM-12-12-centos instruction1]# ll
total 4
-rw-r--r-- 1 root root 900 Nov 17 23:25 myfile.txt
[root@VM-12-12-centos instruction1]# cat myfile.txt | wc -l
101
[root@VM-12-12-centos instruction1]#

怎么理解管道呢?

//管道用途:显示大文本中的中间内容或任意想提取的内容
[root@VM-12-12-centos instruction1]# ll
total 4
-rw-r--r-- 1 root root 900 Nov 17 23:25 myfile.txt
[root@VM-12-12-centos instruction1]# wc -l myfile.txt 
101 myfile.txt
[root@VM-12-12-centos instruction1]# cat myfile.txt | head -n50 | tail -n10
hello 40
hello 41
hello 42
hello 43
hello 44
hello 45
hello 46
hello 47
hello 48
hello 49
[root@VM-12-12-centos instruction1]# 

19. date

data [选项] [+format]

作用:显示时间

  • %H : 小时
  • %M : 分钟
  • %S : 秒
  • %X : 相当于 %H:%M:%S
  • %d : 日
  • %m : 月份
  • %Y : 完整年份
  • %F :相当于%Y-%m-%d
[root@VM-12-12-centos instruction1]# date +%F/%X
2022-11-18/12:00:31 AM

补充:时间戳

时间->时间戳:date +%s
时间戳->时间:date -d@时间戳

[root@VM-12-12-centos ~]# date +%s
1668781140
[root@VM-12-12-centos ~]# date -d@1668781140
Fri Nov 18 22:19:00 CST 2022
[root@VM-12-12-centos ~]# 

20. cal

cal [参数] [月份] [年份]

作用:用于查看日历等时间信息

-y 显示当前年份的日历

-j 显示当年中的第几天(一年日期按天算,从1月1号算起,默认显示当前月在一年中的天数)

[root@VM-12-12-centos ~]# cal -y 2019
                               2019                               

       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  2  3  4  5                   1  2                   1  2
 6  7  8  9 10 11 12    3  4  5  6  7  8  9    3  4  5  6  7  8  9
13 14 15 16 17 18 19   10 11 12 13 14 15 16   10 11 12 13 14 15 16
20 21 22 23 24 25 26   17 18 19 20 21 22 23   17 18 19 20 21 22 23
27 28 29 30 31         24 25 26 27 28         24 25 26 27 28 29 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  3  4  5  6             1  2  3  4                      1
 7  8  9 10 11 12 13    5  6  7  8  9 10 11    2  3  4  5  6  7  8
14 15 16 17 18 19 20   12 13 14 15 16 17 18    9 10 11 12 13 14 15
21 22 23 24 25 26 27   19 20 21 22 23 24 25   16 17 18 19 20 21 22
28 29 30               26 27 28 29 30 31      23 24 25 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  3  4  5  6                1  2  3    1  2  3  4  5  6  7
 7  8  9 10 11 12 13    4  5  6  7  8  9 10    8  9 10 11 12 13 14
14 15 16 17 18 19 20   11 12 13 14 15 16 17   15 16 17 18 19 20 21
21 22 23 24 25 26 27   18 19 20 21 22 23 24   22 23 24 25 26 27 28
28 29 30 31            25 26 27 28 29 30 31   29 30

       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  2  3  4  5                   1  2    1  2  3  4  5  6  7
 6  7  8  9 10 11 12    3  4  5  6  7  8  9    8  9 10 11 12 13 14
13 14 15 16 17 18 19   10 11 12 13 14 15 16   15 16 17 18 19 20 21
20 21 22 23 24 25 26   17 18 19 20 21 22 23   22 23 24 25 26 27 28
27 28 29 30 31         24 25 26 27 28 29 30   29 30 31


[root@VM-12-12-centos ~]# 

21. sort

sort [选项] 文件名

作用:按照每行的第一个字母依次向后对齐比较ASCII码值(类似strcmp函数),默认升序

-r 按照降序排序

[root@VM-12-12-centos instruction1]# ll
total 0
-rw-r--r-- 1 root root 0 Nov 18 22:26 test.txt
[root@VM-12-12-centos instruction1]# nano test.txt
[root@VM-12-12-centos instruction1]# cat test.txt 
1111
111
2222
22222
3333
4444
7777
9999
[root@VM-12-12-centos instruction1]# sort test.txt 
111
1111
2222
22222
3333
4444
7777
9999
[root@VM-12-12-centos instruction1]#

22. uniq

作用:相邻内容去重

[root@VM-12-12-centos instruction1]# ll
total 4
-rw-r--r-- 1 root root 40 Nov 18 22:29 test.txt
[root@VM-12-12-centos instruction1]# nano test.txt
[root@VM-12-12-centos instruction1]# ll
total 4
-rw-r--r-- 1 root root 61 Nov 18 22:32 test.txt
[root@VM-12-12-centos instruction1]# clear
[root@VM-12-12-centos instruction1]# ll
total 4
-rw-r--r-- 1 root root 61 Nov 18 22:32 test.txt
[root@VM-12-12-centos instruction1]# cat test.txt 
1111
111
2222
22222
3333
4444
7777
9999
9999
0000
0000
1111

[root@VM-12-12-centos instruction1]# uniq test.txt 
1111
111
2222
22222
3333
4444
7777
9999
0000
1111

[root@VM-12-12-centos instruction1]# sort test.txt | uniq

0000
111
1111
2222
22222
3333
4444
7777
9999
[root@VM-12-12-centos instruction1]# 

23. find

find pathname -options filename

作用:用于在文件树中查看文件

-name 按照文件名查找文件

[root@VM-12-12-centos ~]# tree
.
`-- study_2022_11_11
    |-- instruction1
    |   `-- test.txt
    `-- README.txt

2 directories, 2 files
[root@VM-12-12-centos ~]# cd study_2022_11_11/instruction1/
[root@VM-12-12-centos instruction1]# pwd
/root/study_2022_11_11/instruction1
[root@VM-12-12-centos instruction1]# find ~ -name test.txt 
/root/study_2022_11_11/instruction1/test.txt
[root@VM-12-12-centos instruction1]# 

24. which

作用:搜索指令路径

[root@VM-12-12-centos instruction1]# which ls
alias ls='ls --color=auto'
	/usr/bin/ls
[root@VM-12-12-centos instruction1]# which man
/usr/bin/man
[root@VM-12-12-centos instruction1]# which touch
/usr/bin/touch
[root@VM-12-12-centos instruction1]# which echo
/usr/bin/echo
[root@VM-12-12-centos instruction1]# 

25. whereis

作用:查找文件

[root@VM-12-12-centos instruction1]# whereis test
test: /usr/bin/test /usr/share/man/man1/test.1.gz /usr/share/man/man1p/test.1p.gz
[root@VM-12-12-centos instruction1]# whereis ls
ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz /usr/share/man/man1p/ls.1p.gz

26. alias

作用:给特定命令起别名

[root@VM-12-12-centos instruction1]# alias myls='ls -a -l -i -n'
[root@VM-12-12-centos instruction1]# myls
total 12
656403 drwxr-xr-x 2 0 0 4096 Nov 18 22:45 .
656417 drwxr-xr-x 3 0 0 4096 Nov 16 21:29 ..
656463 -rw-r--r-- 1 0 0   61 Nov 18 22:32 test.txt
[root@VM-12-12-centos instruction1]# which myls
alias myls='ls -a -l -i -n'
	/usr/bin/ls
[root@VM-12-12-centos instruction1]# 

27. grep

grep [选项] 搜寻字符串 文件

作用:在文件中搜索字符串,将找到的行打印出来

-n 输出行号

-v 反向选择

-i 忽略大小写

[root@VM-12-12-centos instruction1]# ll
total 4
-rw-r--r-- 1 root root 61 Nov 18 22:32 test.txt
[root@VM-12-12-centos instruction1]# cat test.txt 
1111
111
2222
22222
3333
4444
7777
9999
9999
0000
0000
1111

[root@VM-12-12-centos instruction1]# grep '11' test.txt 
1111
111
1111
[root@VM-12-12-centos instruction1]# grep -v '11' test.txt 
2222
22222
3333
4444
7777
9999
9999
0000
0000
[root@VM-12-12-centos instruction1]# 

28. zip/unzip

zip 压缩文件.zip 目录或文件

作用:将目录或文件压缩成zip格式

-r 递 归处理,将指定目录下的所有文件和子目录一并处理

[root@VM-12-12-centos instruction1]# ll
total 4
drwxr-xr-x 2 root root 4096 Nov 18 23:02 test
[root@VM-12-12-centos instruction1]# zip test.zip .

zip error: Nothing to do! (test.zip) //err operation
[root@VM-12-12-centos instruction1]# zip test.zip test
  adding: test/ (stored 0%)
[root@VM-12-12-centos instruction1]# ll
total 8
drwxr-xr-x 2 root root 4096 Nov 18 23:02 test
-rw-r--r-- 1 root root  160 Nov 18 23:03 test.zip
[root@VM-12-12-centos instruction1]# tree
.
|-- test
|   `-- test.txt
`-- test.zip

1 directory, 2 files
[root@VM-12-12-centos instruction1]# 
//打包目录需要递归打包
[root@VM-12-12-centos instruction1]# ll
total 4
drwxr-xr-x 2 root root 4096 Nov 18 23:06 test
[root@VM-12-12-centos instruction1]# zip -r test.zip test
  adding: test/ (stored 0%)
  adding: test/test.txt (deflated 23%)
[root@VM-12-12-centos instruction1]# ll
total 8
drwxr-xr-x 2 root root 4096 Nov 18 23:06 test
-rw-r--r-- 1 root root  341 Nov 18 23:10 test.zip
[root@VM-12-12-centos instruction1]# tree
.
|-- test
|   `-- test.txt
`-- test.zip

1 directory, 2 files
[root@VM-12-12-centos instruction1]# ll
total 8
drwxr-xr-x 2 root root 4096 Nov 18 23:06 test
-rw-r--r-- 1 root root  341 Nov 18 23:10 test.zip
[root@VM-12-12-centos instruction1]# mkdir myfile
[root@VM-12-12-centos instruction1]# ll
total 12
drwxr-xr-x 2 root root 4096 Nov 18 23:11 myfile
drwxr-xr-x 2 root root 4096 Nov 18 23:06 test
-rw-r--r-- 1 root root  341 Nov 18 23:10 test.zip
[root@VM-12-12-centos instruction1]# mv test.zip myfile
[root@VM-12-12-centos instruction1]# ll
total 8
drwxr-xr-x 2 root root 4096 Nov 18 23:11 myfile
drwxr-xr-x 2 root root 4096 Nov 18 23:06 test
[root@VM-12-12-centos instruction1]# tree
.
|-- myfile
|   `-- test.zip
`-- test
    `-- test.txt

2 directories, 2 files
[root@VM-12-12-centos instruction1]# cd myfile/
[root@VM-12-12-centos myfile]# ll
total 4
-rw-r--r-- 1 root root 341 Nov 18 23:10 test.zip
[root@VM-12-12-centos myfile]# unzip test.zip 
Archive:  test.zip
   creating: test/
  inflating: test/test.txt           
[root@VM-12-12-centos myfile]# ll
total 8
drwxr-xr-x 2 root root 4096 Nov 18 23:06 test
-rw-r--r-- 1 root root  341 Nov 18 23:10 test.zip
[root@VM-12-12-centos myfile]# tree
.
|-- test
|   `-- test.txt
`-- test.zip

1 directory, 2 files
[root@VM-12-12-centos myfile]# 
//递归处理后就拿到了目录中的文件

补充:

解压到tmp目录:unzip test2.zip -d /tmp

29. tar

tar [-cxtzjvf] 文件与目录

-c : 创建一个压缩文件

-x : 解开一个压缩文件

-t : 查看tarfile里面文件

-z : 是否同时具有gzip的属性以及是否同时需要用gzip压缩

-f : 使用档名,在f之后立即接档名(建立f选项放在所有选项后)

-v : 压缩的过程中显示文件

-C : 解压到指定目录(和zip中的-d选项一样作用)

[yinhan@VM-12-12-centos trunk]$ ll
total 4
drwxrwxr-x 3 yinhan yinhan 4096 Nov 23 10:51 tar
[yinhan@VM-12-12-centos trunk]$ tar -czf tar.tgz tar
[yinhan@VM-12-12-centos trunk]$ ll=
total 8
drwxrwxr-x 3 yinhan yinhan 4096 Nov 23 10:51 tar
-rw-rw-r-- 1 yinhan yinhan  183 Nov 23 10:52 tar.tgz
[yinhan@VM-12-12-centos trunk]$ tree
.
|-- tar
|   |-- file.txt
|   |-- test.c
|   `-- tmp
`-- tar.tgz

2 directories, 3 files
[yinhan@VM-12-12-centos trunk]$ rm -rf tar
[yinhan@VM-12-12-centos trunk]$ ll
total 4
-rw-rw-r-- 1 yinhan yinhan 183 Nov 23 10:52 tar.tgz
[yinhan@VM-12-12-centos trunk]$ tar -xzf tar.tgz 
[yinhan@VM-12-12-centos trunk]$ ll
total 8
drwxrwxr-x 3 yinhan yinhan 4096 Nov 23 10:51 tar
-rw-rw-r-- 1 yinhan yinhan  183 Nov 23 10:52 tar.tgz
[yinhan@VM-12-12-centos trunk]$ tre
-bash: tre: command not found
[yinhan@VM-12-12-centos trunk]$ tree
.
|-- tar
|   |-- file.txt
|   |-- test.c
|   `-- tmp
`-- tar.tgz

2 directories, 3 files
[yinhan@VM-12-12-centos trunk]$ 

固定格式就是这样压缩用-czf,解压用-xzf

//查看压缩包内容操作
[yinhan@VM-12-12-centos ~]$ ll
total 8
-rw-rw-r-- 1 yinhan yinhan   50 Nov 23 00:26 README.txt
drwxrwxr-x 3 yinhan yinhan 4096 Nov 23 10:53 trunk
[yinhan@VM-12-12-centos ~]$ tree
.
|-- README.txt
`-- trunk
    |-- tar
    |   |-- file.txt
    |   |-- test.c
    |   `-- tmp
    `-- tar.tgz

3 directories, 4 files
[yinhan@VM-12-12-centos ~]$ cd trunk/
[yinhan@VM-12-12-centos trunk]$ ll
total 8
drwxrwxr-x 3 yinhan yinhan 4096 Nov 23 10:51 tar
-rw-rw-r-- 1 yinhan yinhan  183 Nov 23 10:52 tar.tgz
[yinhan@VM-12-12-centos trunk]$ tar -tf tar.tgz
tar/
tar/test.c
tar/file.txt
tar/tmp/
[yinhan@VM-12-12-centos trunk]$ tar -tzvf tar.tgz 
drwxrwxr-x yinhan/yinhan     0 2022-11-23 10:51 tar/
-rw-rw-r-- yinhan/yinhan     0 2022-11-23 10:51 tar/test.c
-rw-rw-r-- yinhan/yinhan     0 2022-11-23 10:51 tar/file.txt
drwxrwxr-x yinhan/yinhan     0 2022-11-23 10:51 tar/tmp/

30. bc

作用:进行运算

[yinhan@VM-12-12-centos trunk]$ echo "1+3+8" | bc
12

31. uname -r

uname [选项]

作用:uname用来获取电脑和操作系统的相关信息

-a或–all 详细输出所有信息,依次为内核名称,主机名,内核版本号,内核版本,硬件名,处理器类
型,硬件平台类型,操作系统名称

[yinhan@VM-12-12-centos trunk]$ uname -a
Linux VM-12-12-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
[yinhan@VM-12-12-centos trunk]$ 

32. 热键

ctrl + c : 强制终止非正常输入

tab : 补全文件或指令

ctrl + d : 退出的意思

向上或向下键:用来查阅上次或下次的指令

ctrl + insert : 复制

shift + insert : 粘贴

ctrl + r : 在历史指令中搜索

history : 列出所有历史指令

33. 创建私人用户

adduser + 用户 : 添加用户到home目录

passwd + 用户 : 设置密码 (这里设置密码是没有回显的)

userdel -r + 用户 : 删除用户

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/28207.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

MyBatisPlus入门学习笔记

目录 学习笔记 SQL文件 练习类 其他知识点 yaml配置文件 代码生成器 学习笔记 SQL文件 SQL SET NAMES utf8mb4; SET FOREIGN_KEY_CHECKS 0; -- ---------------------------- -- Table structure for user -- ---------------------------- DROP TABLE IF EXISTS u…

图/图的存储/图的遍历

图的概念&#xff1a;图的数据结构由两个集合构成&#xff0c;一个是顶点集V (vertex)&#xff0c;一个是边集E&#xff08;Edge&#xff09;&#xff1b;无向图一般记为G(V , E) &#xff1b;有向图记为 G<V&#xff0c; E> 有向图就是边的指向是有方向区分的&#xff…

CPT-PLGA/FITC/Bodipy/Biotin聚乳酸共聚物/荧光素/生物素/Bodipy系列染料修饰顺铂的制备

今天小编分享的知识是CPT-PLGA/FITC/Bodipy/Biotin聚乳酸共聚物/荧光素/生物素/Bodipy系列染料修饰顺铂&#xff0c;下面一起来看&#xff01; CPT-11-PLGA纳米粒制备研究&#xff1a; 将CPT-11负载于可生物降解的高分子聚合物聚乳酸-羟基乙酸共聚物(PLGA)中,制备成具有缓释性…

Hive 之拉链表

文章目录什么是拉链表&#xff1f;如何实现拉链&#xff1f;拉链表实现示例什么是拉链表&#xff1f; 一张存储历史数据的表&#xff0c;记录数据由 “生” 到 “死” 的过程&#xff0c;用于处理缓慢变化维。 好处是拉链表可以保存每条数据的所有历史记录&#xff0c;轨迹十…

Java高级之Git

Java高级之Git 第1章 Git简介 Git是一个免费的、开源的分布式版本控制系统&#xff0c;旨在快速高效地处理从小型到非常大的项目的所有内容。 Git易于学习&#xff0c;占用空间小&#xff0c;性能快如闪电。它超越了SCM工具&#xff0c;如Subversion&#xff0c;CVS&#xf…

10.0 SpringMVC源码分析之MVC 模型由来

0.MVC 模型由来 0.1 Model1 模型 Model1 模型是很早以前项目开发的一种常见模型&#xff0c;项目主要由 jsp 和 JavaBean 两部分组成。 它的优点是:结构简单&#xff0c;开发小型项目时效率高。 它的缺点也同样明显: 第一:JSP的职责兼顾于展示数据和处理数据(也就是干了控制…

m基于matlab的BTS天线设计,带GUI界面

目录 1.算法概述 2.仿真效果预览 3.MATLAB部分代码预览 4.完整MATLAB程序 1.算法概述 内容&#xff1a; N个天线按等距分布在z轴上&#xff0c;第N个和第N-1的之间的天线的距离是一定的为d。 在上述有红色的一块&#xff0c;是计算Taylor 公式的&#xff0c;有一个疑问就…

【计算机毕业设计】23.网上商城购物系统+vue

一、系统截图&#xff08;需要演示视频可以私聊&#xff09; 摘 要 随着科学技术的飞速发展&#xff0c;社会的方方面面、各行各业都在努力与现代的先进技术接轨&#xff0c;通过科技手段来提高自身的优势&#xff0c;网上商城购物系统当然也不能排除在外。网上商城购物系统是…

Java不得不知道的八股文之哈希表

哈希表简介 在哈希表中进行添加&#xff0c;删除&#xff0c;查找等操作&#xff0c;性能十分之高&#xff0c;不考虑哈希冲突的情况下&#xff08;后面会探讨下哈希冲突的情况&#xff09;&#xff0c;仅需一次定位即可完成&#xff0c;时间复杂度为O(1)&#xff0c;接下来我…

如何回复SCI审稿人评审意见(response letter)

如何高效地回复审稿意见&#xff1f;&#xff08;上&#xff09; 如何高效地回复审稿意见&#xff1f;&#xff08;中&#xff09; 如何高效地回复审稿意见&#xff1f;&#xff08;下&#xff09; 如何高效回复审稿人意见&#xff08;附实例&#xff09; 如何高效的回复审稿人…

机器学习笔记之核方法(一)核方法介绍

机器学习笔记之核方法——核方法介绍引言回顾&#xff1a;支持向量机的对偶问题核方法思想介绍线性可分与线性不可分非线性带来高维转换对偶表示带来内积核函数核函数满足的条件(2022/11/23)引言 本节将介绍核方法以及核函数。 回顾&#xff1a;支持向量机的对偶问题 在支持…

Ubuntu sudo apt update 过程中遇到的报错解决

文章目录参考资料1. 前言2. 换源方式1. 方式1&#xff1a; 更换/etc/apt/sources.list文件里的源2. 方式2&#xff1a;在设置中software&updates(软件和更新)里进行换源3. 问题解决--移除失效的ppa参考资料 E: 仓库 “https://mirrors.aliyun.com/docker-ce/linux/ubuntu …

目标检测算法——YOLOv5/YOLOv7改进结合涨点Trick之ASFF(自适应空间特征融合)

>>>深度学习Tricks,第一时间送达<<< 🚀🚀🚀NEW!!!魔改YOLOv5/YOLOv7目标检测算法来啦 ~ 💡💡魔法搭配计算机视觉领域各类创新新颖且行之有效的网络结构,平均精度均值mAP涨点明显,实验效果也俱佳。有需要的小伙伴可以在CSDN后台留言+点赞收藏…

闲人闲谈PS之三十三——项目承诺成本管理

惯例闲话&#xff1a;学习很苦&#xff0c;坚持很酷——最近看到这句话&#xff0c;苦和酷放在一起&#xff0c;总有一种感觉&#xff0c;吃苦是为了耍酷。这恰恰是这句话的问题之处&#xff0c;苦是自己的&#xff0c;酷是外部环境对自己的评价。所以&#xff0c;苦这件事情&a…

k8s1.25版本集群部署(亲测有效)

1.实验环境准备 准备三台centos7虚拟机&#xff0c;用来部署k8s集群&#xff1a; master&#xff08;hadoop1&#xff0c;192.168.229.111&#xff09;配置&#xff1a; 操作系统&#xff1a;centos7.3以及更高版本都可以配置&#xff1a;4核cpu&#xff0c;4G内存&#xff…

【JavaScript流程控制-分支】

JavaScript流程控制-分支1 本节目标2 流程控制3 顺序流程控制4 分支流程控制if语句4.1 分支结构4.2 if语句4.2.1 语法结构4.2.2 执行流程4.3 if else语句(双分支语句)4.3.1 语法结构4.3.2 执行流程4.4 if else if语句(多分支语句)4.4.1 语法结构4.4.2 执行流程5 三元表达式5.1 …

蓝桥杯嵌入式第一篇 点亮LED灯开启成功之路

文章目录前言一、准备工作1.拿到开发板第一步看原理图2.下载STM32cubeMX二、开始点灯1.查看LED原理图2.cubeMX配置3.代码实现总结前言 从这篇文章开始将为大家带来最详细最全面的蓝桥杯嵌入式教学&#xff0c;本教程将使用STM32cubeMX教大家快速入门STM32。花最少的时间拿下国…

电镀废水末端除镍工艺,除镍树脂如何使用?

电镀废水的处理方案分析 电镀废水中含有铜、镍等金属物质&#xff0c;具有较高的回收价值。因此&#xff0c;为了减少环境污染&#xff0c;提高电镀企业的经济效率&#xff0c;一般会对电镀废水进行 回收性的处理&#xff0c;来回收金属铜、镍等。而从目前情况看&#xff0c;…

ipv6地址概述——了解ipv6与ipv4不同

目录 一 ipv4与ipv6 1.ipv4的概述 2.ipv4存在的问题 3.ipv6的概述 4.ipv4与ipv6的优点和特点 5.ipv6与ipv4的变化 ipv4包头 ipv6包头 6.ipv6的基本术语 个人简介&#xff1a;云计算网络运维专业人员&#xff0c;了解运维知识&#xff0c;掌握TCP/IP协议&#xff0c;每…

三菱机床联网

一、设备信息确认 1、确认型号 数控面板拍照确认&#xff1a; 此系统为&#xff1a;M70控制器 注&#xff1a;目前M70和M80&#xff0c;基本上都有网络通讯和采集功能。 2、确认通讯接口 网口常见位置&#xff0c;LAN标号&#xff0c;可通过这个确认&#xff1a; 1、数控…