Linux (常用命令总结)

发布于:2024-12-08 ⋅ 阅读:(107) ⋅ 点赞:(0)

cd   切换路径

[root@linux-lyz ~]# cd /opt/
[root@linux-lyz opt]# 

ls    查看当前目录下文件

 [root@linux-lyz opt]# ls
modules  rh  software

pwd   查看当前目录

[root@linux-lyz opt]# pwd
/opt

mkdir   创建新目录 

[root@linux-lyz test]# mkdir test
[root@linux-lyz test]# ls
test

touch    创建空文件或更新文件的时间戳 

[root@linux-lyz test]# cd test
[root@linux-lyz test]# touch test.txt
[root@linux-lyz test]# touch test1.txt
[root@linux-lyz test]# touch test2.txt
[root@linux-lyz test]# ls
test1.txt  test2.txt  test.txt

rm    删除文件

[root@linux-lyz test]# ls
test1.txt  test2.txt  test.txt
[root@linux-lyz test]# rm test.txt
rm: remove regular empty file ‘test.txt’? y
[root@linux-lyz test]# ls
test1.txt  test2.txt

[root@linux-lyz test]# ls
test  test1  test2  test3

[root@linux-lyz test]# ls 
test  test1  test2  test3
[root@linux-lyz test]# rm -r test
rm: descend into directory ‘test’? y
rm: remove regular empty file ‘test/test1.txt’? y
rm: remove regular empty file ‘test/test2.txt’? y
rm: remove directory ‘test’? y
[root@linux-lyz test]# 

 cp  复制文件或目录

[root@linux-lyz test]# ls
test1  test2  test3

[root@linux-lyz test]# cp -r test1 ./cptest1
[root@linux-lyz test]# ls
cptest1  test1  test2  test3

 mv    移动或重命名文件或目录

 [root@linux-lyz test]# ls
cptest1  test1  test2  test3
[root@linux-lyz test]# mv cptest1 test4
[root@linux-lyz test]# ls
test1  test2  test3  test4

vi   vim  编辑文件进入文件编辑

[root@linux-lyz test1]# touch aa.txt
[root@linux-lyz test1]# vim aa.txt 

cat    连接和显示文件内容 

 [root@linux-lyz test1]# cat aa.txt
aaaa
aaa
...
7324
88

head/tail   输出文件信息

[root@linux-lyz test1]# tail aa.txt -n 3
7
7324
88
[root@linux-lyz test1]#  

more/less   逐页显示文本文件内容 

[root@linux-lyz test1]# more aa.txt 
aaaa
aaa
....
7324
88
[root@linux-lyz test1]# 

 grep    在文件中搜索指定文本

[root@linux-lyz test1]# grep 32 aa.txt 
7324

ps   显示当前运行的进程 

 [root@linux-lyz test1]# ps
   PID TTY          TIME CMD
  5013 pts/0    00:00:00 ps
 77122 pts/0    00:00:00 bash

netstat -nltp 查看网络端口号占用 

[root@linux-lyz test1]# netstat -nltp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      2191/master         
tcp        0      0 0.0.0.0:40222           0.0.0.0:*               LISTEN      1541/rpc.statd      
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1406/rpcbind        
tcp        0      0 0.0.0.0:4369            0.0.0.0:*               LISTEN      115149/epmd         
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1276/sshd           
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      75528/cupsd         
tcp6       0      0 ::1:25                  :::*                    LISTEN      2191/master         
tcp6       0      0 :::33540                :::*                    LISTEN      1541/rpc.statd      
tcp6       0      0 :::111                  :::*                    LISTEN      1406/rpcbind        
tcp6       0      0 :::4369                 :::*                    LISTEN      115149/epmd         
tcp6       0      0 :::22                   :::*                    LISTEN      1276/sshd           
tcp6       0      0 ::1:631                 :::*                    LISTEN      75528/cupsd         
[root@linux-lyz test1]#  

kill   终止进程 

ping    测试与主机的连通性

 [root@linux-lyz test1]# ping www.baidu.com
PING www.a.shifen.com (183.2.172.185) 56(84) bytes of data.
64 bytes from 183.2.172.185: icmp_seq=1 ttl=128 time=38.0 ms
64 bytes from 183.2.172.185: icmp_seq=2 ttl=128 time=38.5 ms
^C64 bytes from 183.2.172.185: icmp_seq=3 ttl=128 time=37.2 ms

wget/curl:从网络下载文件 

chmod:修改文件或目录的权限 

 [root@linux-lyz test1]# chmod 777 aa.txt 

 chown:修改文件或目录的所有者

tar:用于压缩和解压文件和目录 

[root@linux-lyz test]# tar -czvf test1.tar.gz test1
test1/
test1/aa.txt
[root@linux-lyz test]# ls
test1  test1.tar.gz  test2  test3  test4
[root@linux-lyz test]# tar zxvf test1.tar.gz
test1/
test1/aa.txt
[root@linux-lyz test]# ls

df/du   显示磁盘使用情况 

[root@linux-lyz test]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda3       48017504 8097232  39920272  17% /
devtmpfs          926932       0    926932   0% /dev
tmpfs             935380       0    935380   0% /dev/shm
tmpfs             935380   25376    910004   3% /run
tmpfs             935380       0    935380   0% /sys/fs/cgroup
/dev/sda1         303788  107896    195892  36% /boot 

[root@linux-lyz test]# du -h test1
4.0K    test1
[root@linux-lyz test]# 

top  显示系统资源的实时使用情况和进程信息

[root@linux-lyz test]# tmpfs             935380       0    935380   0% /dev/shm
bash: tmpfs: command not found...
[root@linux-lyz test]# tmpfs             935380   25376    910004   3% /run
top - 08:56:15 up  9:59,  2 users,  load average: 0.09, 0.13, 0.13
Tasks: 380 total,   2 running, 378 sleeping,   0 stopped,   0 zombie
%Cpu(s):  4.4 us,  2.7 sy,  0.0 ni, 92.9 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem:   1870760 total,  1605972 used,   264788 free,     8772 buffers
KiB Swap:  4079612 total,      396 used,  4079216 free.  1117756 cached Mem

   PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND                                                             
   778 root      20   0  267160   4192   3356 S  0.7  0.2   0:58.39 vmtoolsd                       

free  显示系统内存使用情况

[root@linux-lyz test]# free
             total       used       free     shared    buffers     cached
Mem:       1870760    1605460     265300      25304       8772    1117860
-/+ buffers/cache:     478828    1391932
Swap:      4079612        396    40796 

crontab -e 编辑定时任务