这里为大家提供一下但不限于以下的Linux常用命令:
1.列出当前目录下所有内容
2.列出当前目录下所有内容的详细信息
3.显示当前工作目录
4.删除文件
5.删除目录
6.切换(进入)文件目录(返回上级目录)
7.文件copy(复制)
8.对文件或目录进行移动(文件名更改)
9.查看文件内容
10.显示出系统的重要信息
11.查看磁盘使用情况
12.显示系统中运行的程序
13.查看CPU占用——显示排行
14.关闭计算机以及重启计算机
1.列出当前目录下所有内容
ls — List
ls 指令(命令)会列出当前目录下所有(文件或文件夹)
darkperson@root:~/jc$ ls dp dp.go
2.列出当前目录下所有内容的详细信息
ls-l
ls-l 指令(命令)会列出当前目录下所有(文件或文件夹)的权限内容大小等参数
演示:
darkperson@root:~/jc$ ls -l total 8 drwxrwxr-x 2 root root 4096 Feb 12 11:53 dp -rw-rw-r-- 1 root root 5 Feb 12 11:56 dp.go
3.显示当前工作目录
pwd — Print Working Directory
pwd 指令(命令)会列出当前的工作目录
演示:
darkperson@root:~/jc$ pwd /root/jc
4.删除文件
rm— Remove
rm 指令(命令)可以指定删除某文件
演示:
darkperson@root:~/jc$ ls dp dp.go darkperson@root:~/jc$ rm dp.go darkperson@root:~/jc$ ls dp darkperson@root:~/jc$
5.删除目录
mdir— Remove Directory
mdir 指令(命令)可以删除指定目录
演示:
darkperson@root:~/jc$ ls dp dp.go sc darkperson@root:~/jc$ rmdir sc/ darkperson@root:~/jc$ ls dp dp.go darkperson@root:~/jc$
6.切换(进入)文件目录
cd — Change Directory
cd 指令(命令)可以进入指定目录
演示:
darkperson@root:~/jc$ ls dp darkperson@root:~/jc$ cd dp
也可以利用cd指令(命令)进行返回上级目录操作:
darkperson@root:~/jc/yanshi$ cd .. darkperson@root:~/jc$
7.文件copy(复制)
copy 指令(命令)可以进行复制文件或复制文件到指定目录
演示:
darkperson@root:~/jc$ ls dp dp.go yanshi darkperson@root:~/jc$ cp dp.go haha.go darkperson@root:~/jc$ ls dp dp.go haha.go yanshi darkperson@root:~/jc$
把文件复制到某目录:
darkperson@root:~/jc$ ls dp dp.go haha.go yanshi darkperson@root:~/jc$ ls dp dp.go haha.go yanshi darkperson@root:~/jc$ cp dp.go yanshi/ darkperson@root:~/jc$ cd yanshi/ darkperson@root:~/jc/yanshi$ ls dp.go
8.文件名更改
mv— Move
mv 指令(命令)可以对文件或目录进行移动,如果目录为当前目录则对其进行重命名
演示:
darkperson@root:~/jc$ cd yanshi darkperson@root:~/jc/yanshi$ ls dp.go haha darkperson@root:~/jc/yanshi$ mv dp.go haha/ darkperson@root:~/jc/yanshi$ ls haha //此时dp.go已经被移到 haha目录 darkperson@root:~/jc/yanshi$ cd haha darkperson@root:~/jc/yanshi/haha$ ls dp.go
对其进行改名:
darkperson@root:~/jc/yanshi/haha$ mv dp.go huahua.go darkperson@root:~/jc/yanshi/haha$ ls huahua.go
9.查看文件内容
cat— concatenate and print files
cat 指令(命令)用于在标准输出(监控器或屏幕)上查看文件内容
演示:
darkperson@root:~/jc/yanshi/haha$ cat dp.go haha
10.显示出系统的重要信息
uname
uname 指令(命令)会显示出关于系统的重要信息,如内核名称、主机名、内核版本、处理机类型等等
uname -a 指令(命令)可以查看所有信息
演示:
darkperson@root:~/jc/yanshi/haha$ uname Linux darkperson@root:~/jc/yanshi/haha$ uname -a Linux liang 5.0.0-1031-azure #33-Ubuntu SMP Thu Feb 6 22:26:13 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux darkperson@root:~/jc/yanshi/haha$
11.查看磁盘使用情况
df — Disk space Free
df 指令(命令)可以查看文件系统中磁盘的使用情况 硬盘已用和可用的存储空间以及其它存储设备
df -h 指令(命令)将结果以人可读的方式显示。
演示:
darkperson@root:~/jc/yanshi/haha$ df Filesystem 1K-blocks Used Available Use% Mounted on udev 16445400 0 16445400 0% /dev tmpfs 3291704 752 3290952 1% /run /dev/sda1 30309264 3933744 26359136 13% / tmpfs 16458500 0 16458500 0% /dev/shm tmpfs 5120 0 5120 0% /run/lock tmpfs 16458500 0 16458500 0% /sys/fs/cgroup /dev/sda15 106858 3668 103190 4% /boot/efi /dev/sdb1 131585988 61468 124797304 1% /mnt tmpfs 3291700 0 3291700 0% /run/user/1000 darkperson@root:~/jc/yanshi/haha$ df -h Filesystem Size Used Avail Use% Mounted on udev 16G 0 16G 0% /dev tmpfs 3.2G 752K 3.2G 1% /run /dev/sda1 29G 3.8G 26G 13% / tmpfs 16G 0 16G 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 16G 0 16G 0% /sys/fs/cgroup /dev/sda15 105M 3.6M 101M 4% /boot/efi /dev/sdb1 126G 61M 120G 1% /mnt tmpfs 3.2G 0 3.2G 0% /run/user/1000
12.显示系统中运行的程序
ps — ProcesseS
ps 指令(命令)是显示系统的运行进程
演示:
darkperson@root:~/jc/yanshi/haha$ ps PID TTY TIME CMD 25871 pts/0 00:00:00 bash 28459 pts/0 00:00:00 ps
13.查看CPU占用——显示排行
top — Top processes
top 指令(命令)会默认按照CPU的占用情况,显示占用量较大的进程,可以使用
top -u 指令(命令)查看某个用户的CPU使用排名情况。
演示:
darkperson@root:~/jc/yanshi/haha$ top top - 12:32:30 up 2 days, 1:04, 1 user, load average: 0.00, 0.00, 0.00 Tasks: 226 total, 2 running, 110 sleeping, 0 stopped, 0 zombie %Cpu(s): 1.0 us, 0.1 sy, 3.4 ni, 95.5 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem : 32917004 total, 28427940 free, 1093204 used, 3395860 buff/cache KiB Swap: 0 total, 0 free, 0 used. 31348196 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1866 root 20 0 239428 26920 10084 R 6.2 0.1 8:51.61 python3 1 root 20 0 225584 9492 6872 S 0.0 0.0 0:04.56 systemd 2 root 20 0 0 0 0 S 0.0 0.0 0:00.02 kthreadd 3 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 rcu_gp 4 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 rcu_par_gp 6 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/0:0H-kb 8 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 mm_percpu_wq 9 root 20 0 0 0 0 S 0.0 0.0 0:00.12 ksoftirqd/0 10 root 20 0 0 0 0 I 0.0 0.0 0:28.28 rcu_sched 11 root rt 0 0 0 0 S 0.0 0.0 0:00.44 migration/0 13 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cpuhp/0 14 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cpuhp/1 15 root rt 0 0 0 0 S 0.0 0.0 0:00.33 migration/1 16 root 20 0 0 0 0 S 0.0 0.0 0:00.05 ksoftirqd/1 18 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/1:0H-kb 19 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cpuhp/2 20 root rt 0 0 0 0 S 0.0 0.0 0:00.44 migration/2 21 root 20 0 0 0 0 S 0.0 0.0 0:00.03 ksoftirqd/2 23 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/2:0H-kb 24 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cpuhp/3 25 root rt 0 0 0 0 S 0.0 0.0 0:00.38 migration/3 26 root 20 0 0 0 0 S 0.0 0.0 0:00.02 ksoftirqd/3 28 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/3:0H-kb 29 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cpuhp/4 30 root rt 0 0 0 0 S 0.0 0.0 0:00.42 migration/4 31 root 20 0 0 0 0 S 0.0 0.0 0:00.02 ksoftirqd/4 33 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/4:0H-kb 34 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cpuhp/5 35 root rt 0 0 0 0 S 0.0 0.0 0:00.36 migration/5 36 root 20 0 0 0 0 S 0.0 0.0 0:00.02 ksoftirqd/5 38 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/5:0H-kb 39 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cpuhp/6 40 root rt 0 0 0 0 S 0.0 0.0 0:00.42 migration/6 41 root 20 0 0 0 0 S 0.0 0.0 0:00.26 ksoftirqd/6 43 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/6:0H-kb 44 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cpuhp/7 45 root rt 0 0 0 0 S 0.0 0.0 0:00.36 migration/7 46 root 20 0 0 0 0 S 0.0 0.0 0:00.01 ksoftirqd/7 48 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/7:0H-kb 49 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cpuhp/8 50 root rt 0 0 0 0 S 0.0 0.0 0:00.43 migration/8 51 root 20 0 0 0 0 S 0.0 0.0 0:00.03 ksoftirqd/8 53 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/8:0H-kb 54 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cpuhp/9 55 root rt 0 0 0 0 S 0.0 0.0 0:00.53 migration/9 56 root 20 0 0 0 0 S 0.0 0.0 0:00.02 ksoftirqd/9 58 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/9:0H-kb 59 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cpuhp/10 60 root rt 0 0 0 0 S 0.0 0.0 0:00.42 migration/10 61 root 20 0 0 0 0 S 0.0 0.0 0:00.02 ksoftirqd/10 63 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/10:0H-k 64 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cpuhp/11 65 root rt 0 0 0 0 S 0.0 0.0 0:00.37 migration/11 66 root 20 0 0 0 0 S 0.0 0.0 0:00.02 ksoftirqd/11 68 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/11:0H-k
14.关闭计算机以及重启计算机
shutdown
shutdown 指令(命令)用于关闭计算机
shutdown -r 指令(命令)用于重启计算机
也可以使用reboot 指令(命令)来重启计算机