Ubuntu操作系统常用命令总结
1 Ubuntu概述
根据百度百科的定义,Ubuntu作为Linux发行版中的后起之秀,它在当前的服务器和桌面操作系统中,都有大量的应用。由于Ubuntu 是开放源代码的自由软件,我们可以登录Ubuntu 的官方网址免费下载该软件的安装包。Ubuntu几乎包含了所有常用的应用软件,比如文字处理、电子邮件、软件开发工具和Web服务等。用户下载、使用、分享Ubuntu系统,以及获得技术支持与服务,无需支付任何许可费用。
新版 Ubuntu 已开始对树莓派进行了全面的优化, 4GB 或 8GB 内存版本的树莓派将获得 Ubuntu 桌面的完整支持。换句话说,Ubuntu 除了在服务器、个人PC电脑、笔记本、虚拟机上安装以外,还可以在树莓派上安装运行 Ubuntu。目前Ubuntu正在为物联网倾力打造操作系统Ubuntu Core。从智能家居到智能无人机,机器人,工业系统,Ubuntu是嵌入式Linux的新标准,具备庞大的开发者社区和可靠的安全更新。
2 Ubuntu常用命令
下面将给出Ubuntu常用的命令总结,如果想查看当前操作系统的CPU架构,则可以用如下的命令:
root@jack-pc:~# uname -m
x86_64
查看CPU相关信息,用如下命令:
root@jack-pc:~# cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 158
model name : Intel(R) Core(TM) i5-7400 CPU @ 3.00GHz
stepping : 9
cpu MHz : 2999.998
cache size : 6144 KB
physical id : 0
siblings : 1
core id : 0
cpu cores : 1
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 22
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca
bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf
bogomips : 5999.99
clflush size : 64
cache_alignment : 64
address sizes : 39 bits physical, 48 bits virtual
power management:
查看Ubuntu操作系统的版本信息,用如下命令:
root@jack-pc:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.6 LTS
Release: 18.04
Codename: bionic
查看PCI设备清单,用如下命令:
root@jack-pc:~# lspci
00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02)
00:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II]
00:01.1 IDE interface: Intel Corporation 82371AB/EB/MB PIIX4 IDE (rev 01)
00:02.0 VGA compatible controller: VMware SVGA II Adapter
00:03.0 Ethernet controller: Intel Corporation 82540EM Gigabit Ethernet Controller (rev 02)
00:04.0 System peripheral: InnoTek Systemberatung GmbH VirtualBox Guest Service
00:05.0 Multimedia audio controller: Intel Corporation 82801AA AC'97 Audio Controller (rev 01)
00:06.0 USB controller: Apple Inc. KeyLargo/Intrepid USB
00:07.0 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 08)
00:0d.0 SATA controller: Intel Corporation 82801HM/HEM (ICH8M/ICH8M-E) SATA Controller [AHCI mode] (rev 02)
查看USB设备清单,用如下命令:
root@jack-pc:~# lsusb
Bus 001 Device 002: ID 80ee:0021 VirtualBox USB Tablet
Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
查看网络设备(网络接口卡)情况,可以支持如下的命令:
root@jack-pc:~# ifconfig
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.2.15 netmask 255.255.255.0 broadcast 10.0.2.255
inet6 fe80::2e0c:6b72:6f50:4018 prefixlen 64 scopeid 0x20<link>
ether 08:00:27:92:8d:5a txqueuelen 1000 (Ethernet)
RX packets 29149 bytes 36610848 (36.6 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 6144 bytes 489962 (489.9 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 365 bytes 34821 (34.8 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 365 bytes 34821 (34.8 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
此命令也可以配置网卡的IP地址,命令如下 :
ifconfig enp0s3 192.168.1.1 netmask 255.255.255.0
如果需要查看当前操作系统是否可以连接另外一台计算机或设备,则可以执行如下命令验证:
root@jack-pc:~# ping www.baidu.com
PING www.baidu.com (36.152.44.95) 56(84) bytes of data.
64 bytes from 36.152.44.95 (36.152.44.95): icmp_seq=1 ttl=56 time=12.8 ms
64 bytes from 36.152.44.95 (36.152.44.95): icmp_seq=2 ttl=56 time=12.6 ms
64 bytes from 36.152.44.95 (36.152.44.95): icmp_seq=3 ttl=56 time=12.0 ms
64 bytes from 36.152.44.95 (36.152.44.95): icmp_seq=4 ttl=56 time=13.3 ms
^Z
[1]+ Stopped ping www.baidu.com
如果需要查看某个命令是否存在或者查看某个可执行文件的位置,可以执行如下命令:
root@jack-pc:~# which pwd
/bin/pwd
root@jack-pc:~# which python3
/usr/bin/python3
若找不到该命令或该执行文件,则返回为空,即无任何结果。如果需要查看当前用户登录的情况,可以用如下命令:
root@jack-pc:~# who
jack :0 2021-11-24 19:02 (:0)
如果需要查看最近用户登录的情况,可以用如下命令:
root@jack-pc:~# last
jack :0 :0 Wed Nov 24 19:02 still logged in
reboot system boot 5.4.0-90-generic Wed Nov 24 19:02 still running
jack :0 :0 Mon Nov 15 21:52 - 21:59 (00:07)
reboot system boot 5.4.0-90-generic Mon Nov 15 21:51 - 22:00 (00:08)
jack :0 :0 Mon Nov 15 21:26 - 21:46 (00:20)
reboot system boot 5.4.0-90-generic Mon Nov 15 21:26 - 21:47 (00:20)
jack :0 :0 Mon Nov 15 21:19 - 21:25 (00:06)
reboot system boot 5.4.0-90-generic Mon Nov 15 21:19 - 21:25 (00:06)
jack :0 :0 Mon Nov 15 20:56 - 21:08 (00:12)
reboot system boot 5.4.0-90-generic Mon Nov 15 20:56 - 21:08 (00:12)
jack :0 :0 Sat Nov 13 19:46 - down (01:45)
reboot system boot 5.4.0-90-generic Sat Nov 13 19:46 - 21:31 (01:45)
jack :0 :0 Sat Nov 13 14:37 - crash (05:08)
如果需要查看系统中的各个用户的登录情况,可以用如下命令:
root@jack-pc:~# lastlog
Username Port From Latest
root **Never logged in**
daemon **Never logged in**
bin **Never logged in**
sys **Never logged in**
sync **Never logged in**
games **Never logged in**
man **Never logged in**
如果需要分析用户登录的行为情况,则需要查看/var/log/auth.log文件,用如下命令打印:
root@jack-pc:~# cat /var/log/auth.log
Nov 24 19:15:22 jack-pc su[6385]: Successful su for root by jack
Nov 24 19:15:22 jack-pc su[6385]: + /dev/pts/0 jack:root
Nov 24 19:15:22 jack-pc su[6385]: pam_unix(su:session): session opened for user root by (uid=1000)
Nov 24 19:15:22 jack-pc systemd: pam_unix(systemd-user:session): session opened for user root by (uid=0)
Nov 24 19:15:22 jack-pc systemd-logind[512]: New session 2 of user root.
Nov 24 19:17:01 jack-pc CRON[6432]: pam_unix(cron:session): session opened for user root by (uid=0)
Nov 24 19:17:01 jack-pc CRON[6432]: pam_unix(cron:session): session closed for user root
Nov 24 20:17:01 jack-pc CRON[6528]: pam_unix(cron:session): session opened for user root by (uid=0)
Nov 24 20:17:01 jack-pc CRON[6528]: pam_unix(cron:session): session closed for user root
Nov 24 20:51:13 jack-pc gdm-password]: gkr-pam: unlocked login keyring
Nov 24 21:00:35 jack-pc pkexec: pam_unix(polkit-1:session): session opened for user root by (uid=1000)
Nov 24 21:00:35 jack-pc pkexec[7063]: jack: Executing command [USER=root] [TTY=unknown] [CWD=/home/jack]
[COMMAND=/usr/lib/update-notifier/package-system-locked]
如果需要查看用户的操作记录,则可以查看 /home/{username}/.bash_history,命令如下查看用户jack的操作记录:
root@jack-pc:~# cat /home/jack/.bash_history
su root
sudo passwd root
su root
python --version
python3 --version
python3 --version
python3.7
python3 --version
$LD_LIBRARY_PATH
$PATH
python3
python3.7
python3 --version
export PATH=/usr/local/python3.7.5/bin:$PATH
python3 --version
export LD_LIBRARY_PATH=/usr/local/python3.7.5/lib:$LD_LIBRARY_PATH
export PATH=/usr/local/python3.7.5/bin:$PATH
如果需要创建一个软链接,即类似于快捷方式,则可以执行如下命令:
ln -s /home/mysoft/src_dir /usr/local/dest_dir
如果需要查找文件,则可以用如下命令:
find / -name "*.txt"
find . –name "[a-z]*[0-9].log"
find /home -name "*.txt"
#在当前目录查找此目录下所有文件内包含的指定关键字"abc"
find . -type f -print -exec grep abc {} \;
如果需要修改目录或者文件的权限,则可以用如下的命令:
chmod 777 demo.py
chmod +x demo.py
Ubuntu中,使用 chmod 更改文件的权限,使用 chown 来更改文件的归属,用法如下所示:
chown user:group demo.py
如果需要对文件或目录进行解压、压缩等操作,则可以用如下命令:
tar zxvf demo.tar.gz
tar zcvf demo.tar.gz demo
其中的tar的参数如下:-c建立新的压缩文件;-x从压缩的文件中提取文件;-z支持gzip解压文件;-j支持bzip2解压文件;-z支持compress解压文件;-v显示操作过程;-f指定压缩文件。
如果想查看某个文件或目录空间的大小,则可以用如下命令:
root@jack-pc:~# du -h /usr/share/gdb
12K /usr/share/gdb/system-gdbinit
12K /usr/share/gdb/python/gdb/printer
24K /usr/share/gdb/python/gdb/function
100K /usr/share/gdb/python/gdb/command
216K /usr/share/gdb/python/gdb
220K /usr/share/gdb/python
12K /usr/share/gdb/auto-load/usr/lib/x86_64-linux-gnu
52K /usr/share/gdb/auto-load/usr/lib/jvm/java-11-openjdk-amd64/jre/lib/server
56K /usr/share/gdb/auto-load/usr/lib/jvm/java-11-openjdk-amd64/jre/lib
60K /usr/share/gdb/auto-load/usr/lib/jvm/java-11-openjdk-amd64/jre
64K /usr/share/gdb/auto-load/usr/lib/jvm/java-11-openjdk-amd64
68K /usr/share/gdb/auto-load/usr/lib/jvm
84K /usr/share/gdb/auto-load/usr/lib
8.0K /usr/share/gdb/auto-load/usr/aarch64-linux-gnu/lib
12K /usr/share/gdb/auto-load/usr/aarch64-linux-gnu
100K /usr/share/gdb/auto-load/usr
28K /usr/share/gdb/auto-load/lib/x86_64-linux-gnu
32K /usr/share/gdb/auto-load/lib
144K /usr/share/gdb/auto-load
276K /usr/share/gdb/syscalls
656K /usr/share/gdb
如果需要查看系统中空闲的、已用的物理内存及swap内存情况,可以用如下命令查看:(-m 以MB为单位显示)
root@jack-pc:~# free -m
total used free shared buff/cache available
Mem: 3936 925 800 15 2210 2715
Swap: 2047 0 2047
如果需要查看各进程的CPU和内存使用排序情况,可以用如下命令:
root@jack-pc:~# top
top - 21:53:58 up 2:51, 1 user, load average: 0.16, 0.09, 0.03
Tasks: 189 total, 2 running, 149 sleeping, 4 stopped, 0 zombie
%Cpu(s): 12.9 us, 2.4 sy, 0.0 ni, 84.7 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 4030860 total, 819176 free, 947452 used, 2264232 buff/cache
KiB Swap: 2097148 total, 2097148 free, 0 used. 2780180 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1632 jack 20 0 3045872 278784 108680 S 6.3 6.9 0:54.07 gnome-shell
1432 jack 20 0 404148 76800 43392 S 5.3 1.9 0:24.55 Xorg
2045 jack 20 0 825732 43012 32136 S 3.0 1.1 0:13.71 gnome-terminal-
1574 jack 20 0 188324 2844 2488 S 0.3 0.1 0:25.57 VBoxClient
1674 jack 20 0 356288 22564 17784 S 0.3 0.6 0:00.16 ibus-x11
1774 jack 20 0 504844 23828 18480 S 0.3 0.6 0:00.21 gsd-xsettings
1809 jack 20 0 805316 25056 19680 S 0.3 0.6 0:00.23 gsd-media-keys
1 root 20 0 160108 9292 6544 S 0.0 0.2 0:04.89 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 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
如果需要查看系统中所有进程,可以用如下命令:
root@jack-pc:~# ps -ef | grep python
如果需要杀掉进程,则可以执行如下命令:
kill -9 PID
Ubuntu中的命令还有很多,下次再继续总结分享。
- 点赞
- 收藏
- 关注作者
评论(0)