常用的Linux命令

常用的Linux命令


前言

总结一下我们经常用到的命令


1.pwd

pwd获取当前目录的绝对路径

2.帮助命令

man
按‘q’退出

[localhost.com ~]$ man ls
LS(1)                                                                                          User Commands                                                                                          LS(1)

NAME
       ls - list directory contents

SYNOPSIS
       ls [OPTION]... [FILE]...

DESCRIPTION
       List information about the FILEs (the current directory by default).  Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.

       Mandatory arguments to long options are mandatory for short options too.

       -a, --all
              do not ignore entries starting with .

       -A, --almost-all
              do not list implied . and ..

       --author
              with -l, print the author of each file

       -b, --escape
              print C-style escapes for nongraphic characters

       --block-size=SIZE
              scale sizes by SIZE before printing them; e.g., '--block-size=M' prints sizes in units of 1,048,576 bytes; see SIZE format below

       -B, --ignore-backups
              do not list implied entries ending with ~

       -c     with -lt: sort by, and show, ctime (time of last modification of file status information); with -l: show ctime and sort by name; otherwise: sort by ctime, newest first

       -C     list entries by columns

       --color[=WHEN]
              colorize the output; WHEN can be 'never', 'auto', or 'always' (the default); more info below

       -d, --directory
              list directories themselves, not their contents


help

[localhost.com ~]$ help
GNU bash, version 4.2.46(1)-release (x86_64-redhat-linux-gnu)
These shell commands are defined internally.  Type `help' to see this list.
Type `help name' to find out more about the function `name'.
Use `info bash' to find out more about the shell in general.
Use `man -k' or `info' to find out more about commands not in this list.

A star (*) next to a name means that the command is disabled.

 job_spec [&]                                                                                            history [-c] [-d offset] [n] or history -anrw [filename] or history -ps arg [arg...]
 (( expression ))                                                                                        if COMMANDS; then COMMANDS; [ elif COMMANDS; then COMMANDS; ]... [ else COMMANDS; ] fi
 . filename [arguments]                                                                                  jobs [-lnprs] [jobspec ...] or jobs -x command [args]
 :                                                                                                       kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]
 [ arg... ]                                                                                              let arg [arg ...]
 [[ expression ]]                                                                                        local [option] name[=value] ...
 alias [-p] [name[=value] ... ]                                                                          logout [n]
 bg [job_spec ...]                                                                                       mapfile [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [-c quantum] [array]
 bind [-lpvsPVS] [-m keymap] [-f filename] [-q name] [-u name] [-r keyseq] [-x keyseq:shell-command] [>  popd [-n] [+N | -N]
 break [n]                                                                                               printf [-v var] format [arguments]
 builtin [shell-builtin [arg ...]]                                                                       pushd [-n] [+N | -N | dir]
 caller [expr]                                                                                           pwd [-LP]
 case WORD in [PATTERN [| PATTERN]...) COMMANDS ;;]... esac                                              read [-ers] [-a array] [-d delim] [-i text] [-n nchars] [-N nchars] [-p prompt] [-t timeout] [-u fd]>
 cd [-L|[-P [-e]]] [dir]                                                                                 readarray [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [-c quantum] [array]
 command [-pVv] command [arg ...]                                                                        readonly [-aAf] [name[=value] ...] or readonly -p
 compgen [-abcdefgjksuv] [-o option]  [-A action] [-G globpat] [-W wordlist]  [-F function] [-C comman>  return [n]
 complete [-abcdefgjksuv] [-pr] [-DE] [-o option] [-A action] [-G globpat] [-W wordlist]  [-F function>  select NAME [in WORDS ... ;] do COMMANDS; done
 compopt [-o|+o option] [-DE] [name ...]                                                                 set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]
 continue [n]                                                                                            shift [n]
 coproc [NAME] command [redirections]                                                                    shopt [-pqsu] [-o] [optname ...]
 declare [-aAfFgilrtux] [-p] [name[=value] ...]                                                          source filename [arguments]
 dirs [-clpv] [+N] [-N]                                                                                  suspend [-f]
 disown [-h] [-ar] [jobspec ...]                                                                         test [expr]
 echo [-neE] [arg ...]                                                                                   time [-p] pipeline
 enable [-a] [-dnps] [-f filename] [name ...]                                                            times
 eval [arg ...]                                                                                          trap [-lp] [[arg] signal_spec ...]
 exec [-cl] [-a name] [command [arguments ...]] [redirection ...]                                        true
 exit [n]                                                                                                type [-afptP] name [name ...]
 export [-fn] [name[=value] ...] or export -p                                                            typeset [-aAfFgilrtux] [-p] name[=value] ...
 false                                                                                                   ulimit [-SHacdefilmnpqrstuvx] [limit]
 fc [-e ename] [-lnr] [first] [last] or fc -s [pat=rep] [command]                                        umask [-p] [-S] [mode]
 fg [job_spec]                                                                                           unalias [-a] name [name ...]
 for NAME [in WORDS ... ] ; do COMMANDS; done                                                            unset [-f] [-v] [name ...]
 for (( exp1; exp2; exp3 )); do COMMANDS; done                                                           until COMMANDS; do COMMANDS; done
 function name { COMMANDS ; } or name () { COMMANDS ; }                                                  variables - Names and meanings of some shell variables
 getopts optstring name [arg]                                                                            wait [id]
 hash [-lr] [-p pathname] [-dt] [name ...]                                                               while COMMANDS; do COMMANDS; done
 help [-dms] [pattern ...]                                                                               { COMMANDS ; }

3.查看文件命令 --ls

ls:查看当前目录—ls
查看指定目录 —ls 绝对路径/相对路径
查看所有 — ls -a

[localhost.com ~]$ ls -al
total 232
drwxrwxr-x     2 ck176460 ck176460   4096 Jun 29  2021 -
drwxrwxr-x     3 ck176460 ck176460   4096 Feb 24  2021 ,
drwx------     9 ck176460 ck176460   4096 Oct 25 21:15 .
drwxrwxr-x. 6790 root     root     151552 Apr 12 11:58 ..
-rw-rw-r--     1 ck176460 ck176460      0 Jul  8  2021 1.txt
-rw-r--r--     1 ck176460 ck176460  12288 Jul  8  2021 .1.txt.swp
drwxrwxr-x     3 ck176460 ck176460   4096 Jun 29  2021 a
lrwxrwxrwx     1 ck176460 ck176460      8 Oct 25 19:54 b -> ./test/b
-rw-------     1 ck176460 ck176460   3636 Oct 27 07:03 .bash_history
-rw-r--r--     1 ck176460 ck176460     18 Dec  7  2016 .bash_logout
-rw-r--r--     1 ck176460 ck176460    193 Dec  7  2016 .bash_profile
-rw-r--r--     1 ck176460 ck176460    231 Dec  7  2016 .bashrc
-rw-rw-r--     1 ck176460 ck176460      0 Feb 24  2021 hello.txt
drwxrwxr-x     2 ck176460 ck176460   4096 Jun 29  2021 help
-rw-------     1 ck176460 ck176460     35 Feb 24  2021 .lesshst
drwxrwxr-x     2 ck176460 ck176460   4096 Jun 29  2021 pei.text
drwxrwxr-x     2 ck176460 ck176460   4096 Jun 29  2021 pytest
drwxrwxr-x     4 ck176460 ck176460   4096 Oct 25 19:54 test
-rw-------     1 ck176460 ck176460  12288 Feb 24  2021 .test.sh.swp
-rw-------     1 ck176460 ck176460   2994 Oct 25 21:15 .viminfo
[localhost ~]$ ls -a
-  ,  .  ..  1.txt  .1.txt.swp  a  b  .bash_history  .bash_logout  .bash_profile  .bashrc  hello.txt  help  .lesshst  pei.text  pytest  test  .test.sh.swp  .viminfo
[localhost.com ~]$ ls -ll
total 28
drwxrwxr-x 2 ck176460 ck176460 4096 Jun 29  2021 -
drwxrwxr-x 3 ck176460 ck176460 4096 Feb 24  2021 ,
-rw-rw-r-- 1 ck176460 ck176460    0 Jul  8  2021 1.txt
drwxrwxr-x 3 ck176460 ck176460 4096 Jun 29  2021 a
lrwxrwxrwx 1 ck176460 ck176460    8 Oct 25 19:54 b -> ./test/b
-rw-rw-r-- 1 ck176460 ck176460    0 Feb 24  2021 hello.txt
drwxrwxr-x 2 ck176460 ck176460 4096 Jun 29  2021 help
drwxrwxr-x 2 ck176460 ck176460 4096 Jun 29  2021 pei.text
drwxrwxr-x 2 ck176460 ck176460 4096 Jun 29  2021 pytest
drwxrwxr-x 4 ck176460 ck176460 4096 Oct 25 19:54 test

4.创建新的目录–mkdir

ls:mkdir a
mkdir b/c/d -p 创建递归目录

[localhost ~]$ mkdir A
[localhost ~]$ ls
A  make  study
[localhost ~]$ mkdir b/c/d -p
[localhost ~]$ ls
A  b  make  study
[localhost ~]$ cd b/c/d
[localhost ~]$ pwd
/home/ck176460/b/b/c/d

5.创建文件–touch

[localhost ~]$ ls
kill  pytest
[localhost ~]$ touch game.txt
[localhost ~]$ ls
game.txt  kill  pytest

6.删除文件/目录–rm

[localhost ~]$ ls
game.txt  kill  pytest
[localhost ~]$ rm -ri pytest 
rm: remove regular empty file ‘pytest’? y
[localhost ~]$ ls
game.txt  kill

7.拷贝–cp

[localhost.com ~]$ ls
game.txt  kill
[localhost.com ~]$ ls ..
d
[localhost.com ~]$ cp kill ./..
[localhost.com ~]$ ls ..
d  kill

8.移动–mv

ls:
重命名:mv game.txt hello.txt #同一目录
移动文件: mv hello.txt ./…
移动文件并重命名:mv f ./hogwarts/study

[localhost.com ~]$ mv game.txt hello.txt
[localhost.com ~]$ ls
hello.txt  kill
[localhost.com ~]$ ls ..
d  kill
[localhost.com ~]$ mv hello.txt ./..
[localhost.com ~]$ ls
kill
[localhost.com ~]$ ls ..
d  hello.txt  kill

[localhost.com ~]$ ls
d  hello.txt  kill
[localhost.com ~]$ mv hello.txt ./d/name.txt
[localhost.com ~]$ ls ./d/
kill  name.txt 

9.查找文件–find

全名称查询:find ./d/name.txt
根据后缀名查询:find ./d/*.txt

[localhost.com ~]$ find ./d/*.txt
./d/name.txt
[localhost.com ~]$ ls ./d
kill  name.txt
[localhost.com ~]$ find ./d/name.txt
./d/name.txt

10.建立链接文件–ln

在当前目录创建链接

[localhost.com ~]$ ln ./d/name.txt 
[localhost.com ~]$ ls
d  kill  name.txt

11.文本编辑–vi

进入插入模式 I
输入完成后
按键esc
保存退出 :wq
退出不保存 :q!

[localhost.com ~]$ vi name.txt 

12.查看–cat

[localhost.com ~]$ cat ./name.txt 
hello word

13.打包压缩–tar

打包压缩

[localhost.com ~]$ ls
d  kill  name.txt
[localhost.com ~]$ tar -zcvf D.tar.gz kill name.txt
kill
name.txt
[localhost.com ~]$ ls
d  D.tar.gz  kill  name.txt

解压:
tar -xf 需要解压的文件
1.后面不加目录,解压再当前目录;
2.tar -xf f.tar.gz -C 接目录后,解压在指定目录中)

[localhost.com ~]$ ls
d  D.tar.gz
[localhost.com ~]$ tar -xf D.tar.gz 
[localhost.com ~]$ ls
d  D.tar.gz  kill  name.txt

14.权限属性–chmod

chmod 777 文件
r:读权限 read —4
w:写权限write —2
x:执行权限execute —1
-: 无权限—0

[localhost.com ~]$ ll
total 12
drwxrwxr-x 2 ck176460 ck176460 4096 Apr 12 16:30 d
-rw-rw-r-- 1 ck176460 ck176460  157 Apr 12 16:36 D.tar.gz
-rw-rw-r-- 1 ck176460 ck176460    0 Apr 12 14:45 kill
-rw-rw-r-- 1 ck176460 ck176460   11 Apr 12 16:30 name.txt
[localhost.com ~]$ chmod 777 name.txt 
[localhost.com ~]$ ll
total 12
drwxrwxr-x 2 ck176460 ck176460 4096 Apr 12 16:30 d
-rw-rw-r-- 1 ck176460 ck176460  157 Apr 12 16:36 D.tar.gz
-rw-rw-r-- 1 ck176460 ck176460    0 Apr 12 14:45 kill
-rwxrwxrwx 1 ck176460 ck176460   11 Apr 12 16:30 name.txt


在这里插入图片描述

15.查看网络–ifconfig

[localhost.com ~]$ ifconfig

16.检测网络–ping

ping -c 22 -I 33
-c:ping 的次数
-I:每次ping的时间间隔

[localhost.com ~]$ ping -c 22 -l 3 127.0.0.1
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.032 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.003 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.002 ms
64 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=0.038 ms
64 bytes from 127.0.0.1: icmp_seq=5 ttl=64 time=0.038 ms
64 bytes from 127.0.0.1: icmp_seq=6 ttl=64 time=0.038 ms
64 bytes from 127.0.0.1: icmp_seq=7 ttl=64 time=0.042 ms
64 bytes from 127.0.0.1: icmp_seq=8 ttl=64 time=0.039 ms
64 bytes from 127.0.0.1: icmp_seq=9 ttl=64 time=0.039 ms
64 bytes from 127.0.0.1: icmp_seq=10 ttl=64 time=0.039 ms
64 bytes from 127.0.0.1: icmp_seq=11 ttl=64 time=0.038 ms
64 bytes from 127.0.0.1: icmp_seq=12 ttl=64 time=0.039 ms
64 bytes from 127.0.0.1: icmp_seq=13 ttl=64 time=0.039 ms
64 bytes from 127.0.0.1: icmp_seq=14 ttl=64 time=0.039 ms
64 bytes from 127.0.0.1: icmp_seq=15 ttl=64 time=0.039 ms
64 bytes from 127.0.0.1: icmp_seq=16 ttl=64 time=0.038 ms
64 bytes from 127.0.0.1: icmp_seq=17 ttl=64 time=0.039 ms
64 bytes from 127.0.0.1: icmp_seq=18 ttl=64 time=0.042 ms
64 bytes from 127.0.0.1: icmp_seq=19 ttl=64 time=0.039 ms
64 bytes from 127.0.0.1: icmp_seq=20 ttl=64 time=0.050 ms
64 bytes from 127.0.0.1: icmp_seq=21 ttl=64 time=0.045 ms
64 bytes from 127.0.0.1: icmp_seq=22 ttl=64 time=0.052 ms

--- 127.0.0.1 ping statistics ---
22 packets transmitted, 22 received, 0% packet loss, time 19000ms
rtt min/avg/max/mdev = 0.002/0.036/0.052/0.013 ms, pipe 3

17.打印网络信息状态–netstat

-t:列出所有tcp
-n:以数字形式显示地址何端口号
-p:显示进程的pid 和名字

[localhost.com ~]$ netstat -tnp
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 172.19.147.8:22         27.38.83.250:36470      ESTABLISHED 27327/sshd: dx66732 
tcp        0      0 172.19.147.8:22         1.83.124.47:51796       ESTABLISHED 23896/sshd: ck21820 
tcp        0      0 172.19.147.8:22         110.188.104.179:31036   ESTABLISHED 23293/sshd: jy21990 
tcp        0      0 172.19.147.8:22         153.37.196.3:54407      ESTABLISHED 22187/sshd: 6170588 
tcp        0      0 172.19.147.8:22         27.38.83.250:36419      ESTABLISHED 27322/sshd: dx66732 
tcp        0      0 172.19.147.8:22         1.83.124.47:51795       ESTABLISHED 23893/sshd: ck21820 
tcp        0      0 172.19.147.8:22         110.188.104.179:31190   ESTABLISHED 23722/sshd: jy21990 
tcp        0      0 127.0.0.1:25            127.0.0.1:54326         TIME_WAIT   -                   
tcp        0      0 172.19.147.8:37022      100.100.30.26:80        ESTABLISHED 15545/AliYunDun     
tcp        0     36 172.19.147.8:22         183.195.98.240:2712     ESTABLISHED 16174/sshd: ck17646 
tcp6       0      0 172.19.147.8:9100       123.57.157.48:15460     ESTABLISHED 28845/node_exporter 

18.查看cpu信息–cat /proc/cpuinfo

[localhost.com ~]$ cat /proc/cpuinfo

19.负载信息–top

[localhost.com ~]$ top

20.查看内存–free

-m 根据M单位换算

[localhost.com ~]$ free

21.三剑客(grep、sed、awk)

linux三剑客参考下面的文档
https://blog.csdn.net/gsjthxy/article/details/106985813?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522164975351916781683931778%2522%252C%2522scm%2522%253A%252220140713.130102334…%2522%257D&request_id=164975351916781683931778&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2alltop_click~default-1-106985813.142v7article_score_rank,157v4control&utm_term=linux%E4%B8%89%E5%89%91%E5%AE%A2%E8%AF%A6%E8%A7%A3&spm=1018.2226.3001.4187

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值