命令行学习笔记(进程和权限相关)
2016-12-08 本文已影响28人
TW安洋
- chown root file -- 修改 file 所属用户为 root
- chgrp root file -- 修改 file 所属组为 root
效果如下:
➜ anyang ls -l
total 12
-rw-r--r-- 1 anyang anyang 78 12月 7 21:57 file1
drwxr-xr-x 3 anyang anyang 4096 12月 7 09:47 learngit
-rw-r--r-- 1 anyang anyang 0 12月 8 10:24 newfile
drwxr-xr-x 2 anyang anyang 4096 12月 8 10:24 test
➜ anyang sudo chown root file1
[sudo] password for anyang:
➜ anyang ls -l
total 12
-rw-r--r-- 1 root anyang 78 12月 7 21:57 file1
drwxr-xr-x 3 anyang anyang 4096 12月 7 09:47 learngit
-rw-r--r-- 1 anyang anyang 0 12月 8 10:24 newfile
drwxr-xr-x 2 anyang anyang 4096 12月 8 10:24 test
➜ anyang sudo chgrp root file1
➜ anyang ls -l
total 12
-rw-r--r-- 1 root root 78 12月 7 21:57 file1
drwxr-xr-x 3 anyang anyang 4096 12月 7 09:47 learngit
-rw-r--r-- 1 anyang anyang 0 12月 8 10:24 newfile
drwxr-xr-x 2 anyang anyang 4096 12月 8 10:24 test
/etc/passwd 文件包含所有用户信息
- useradd <username> -- 创建用户
- userdel <username> -- 删除用户(不包括用户家目录等)
- userdel -r <username> -- 删除用户(包括用户家目录等)
效果如下:
➜ anyang tail /etc/passwd
kernoops:x:116:65534:Kernel Oops Tracking Daemon,,,:/:/bin/false
speech-dispatcher:x:117:29:Speech Dispatcher,,,:/var/run/speech-dispatcher:/bin/false
nm-openvpn:x:118:124:NetworkManager OpenVPN,,,:/var/lib/openvpn/chroot:/bin/false
clickpkg:x:119:125::/nonexistent:/bin/false
avahi:x:120:126:Avahi mDNS daemon,,,:/var/run/avahi-daemon:/bin/false
pulse:x:121:127:PulseAudio daemon,,,:/var/run/pulse:/bin/false
colord:x:122:130:colord colour management daemon,,,:/var/lib/colord:/bin/false
saned:x:123:131::/var/lib/saned:/bin/false
hplip:x:124:7:HPLIP system user,,,:/var/run/hplip:/bin/false
anyang:x:1000:1000:anyang,,,:/home/anyang:/bin/zsh
➜ anyang sudo useradd test
➜ anyang tail /etc/passwd
speech-dispatcher:x:117:29:Speech Dispatcher,,,:/var/run/speech-dispatcher:/bin/false
nm-openvpn:x:118:124:NetworkManager OpenVPN,,,:/var/lib/openvpn/chroot:/bin/false
clickpkg:x:119:125::/nonexistent:/bin/false
avahi:x:120:126:Avahi mDNS daemon,,,:/var/run/avahi-daemon:/bin/false
pulse:x:121:127:PulseAudio daemon,,,:/var/run/pulse:/bin/false
colord:x:122:130:colord colour management daemon,,,:/var/lib/colord:/bin/false
saned:x:123:131::/var/lib/saned:/bin/false
hplip:x:124:7:HPLIP system user,,,:/var/run/hplip:/bin/false
anyang:x:1000:1000:anyang,,,:/home/anyang:/bin/zsh
test:x:1001:1001::/home/test:
➜ anyang sudo userdel test
➜ anyang tail /etc/passwd
kernoops:x:116:65534:Kernel Oops Tracking Daemon,,,:/:/bin/false
speech-dispatcher:x:117:29:Speech Dispatcher,,,:/var/run/speech-dispatcher:/bin/false
nm-openvpn:x:118:124:NetworkManager OpenVPN,,,:/var/lib/openvpn/chroot:/bin/false
clickpkg:x:119:125::/nonexistent:/bin/false
avahi:x:120:126:Avahi mDNS daemon,,,:/var/run/avahi-daemon:/bin/false
pulse:x:121:127:PulseAudio daemon,,,:/var/run/pulse:/bin/false
colord:x:122:130:colord colour management daemon,,,:/var/lib/colord:/bin/false
saned:x:123:131::/var/lib/saned:/bin/false
hplip:x:124:7:HPLIP system user,,,:/var/run/hplip:/bin/false
anyang:x:1000:1000:anyang,,,:/home/anyang:/bin/zsh
/etc/group 文件包含所有组信息
- groupadd <groupname> -- 创建组
- groupdel <groupname> -- 删除组
效果如下:
➜ ~ tail /etc/group
clickpkg:x:125:
avahi:x:126:
pulse:x:127:
pulse-access:x:128:
scanner:x:129:saned
colord:x:130:
saned:x:131:
anyang:x:1000:
sambashare:x:132:anyang
test:x:1001:
➜ ~ sudo groupadd newgroup
[sudo] password for anyang:
➜ ~ tail /etc/group
avahi:x:126:
pulse:x:127:
pulse-access:x:128:
scanner:x:129:saned
colord:x:130:
saned:x:131:
anyang:x:1000:
sambashare:x:132:anyang
test:x:1001:
newgroup:x:1002:
➜ ~ sudo groupdel newgroup
➜ ~ tail /etc/group
clickpkg:x:125:
avahi:x:126:
pulse:x:127:
pulse-access:x:128:
scanner:x:129:saned
colord:x:130:
saned:x:131:
anyang:x:1000:
sambashare:x:132:anyang
test:x:1001:
- passwd <username> -- 修改用户密码
- passwd -d <username> -- 删除用户密码
效果如下:
➜ ~ sudo passwd test
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
➜ ~ sudo passwd -d test
passwd: password expiry information changed.
- ps -- 显示当前活跃的进程
- ps aux -- 显示所有进程,包含用户信息
- kill pid -- 杀死进程
- killall proc -- 杀死名为proc的所有进程
- bg -- 后台运行程序
- fg -- 前台运行程序
- top -- 实时显示系统中各个进程的资源使用情况
效果如下:
➜ ~ ps
PID TTY TIME CMD
3055 pts/2 00:00:01 zsh
19149 pts/2 00:00:00 ps
➜ ~ ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.1 137464 7324 ? Ss 09:39 0:01 /sbin/init spla
root 2 0.0 0.0 0 0 ? S 09:39 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? S 09:39 0:00 [ksoftirqd/0]
root 5 0.0 0.0 0 0 ? S< 09:39 0:00 [kworker/0:0H]
root 7 0.0 0.0 0 0 ? S 09:39 0:14 [rcu_sched]
root 8 0.0 0.0 0 0 ? S 09:39 0:00 [rcu_bh]
root 9 0.0 0.0 0 0 ? S 09:39 0:00 [migration/0]
root 10 0.0 0.0 0 0 ? S< 09:39 0:00 [lru-add-drain]
root 11 0.0 0.0 0 0 ? S 09:39 0:00 [watchdog/0]
root 12 0.0 0.0 0 0 ? S 09:39 0:00 [cpuhp/0]
root 13 0.0 0.0 0 0 ? S 09:39 0:00 [cpuhp/1]
root 14 0.0 0.0 0 0 ? S 09:39 0:00 [watchdog/1]
➜ ~ top
top - 18:22:05 up 8:42, 1 user, load average: 1.20, 0.66, 0.57
Tasks: 234 total, 2 running, 232 sleeping, 0 stopped, 0 zombie
%Cpu(s): 16.5 us, 2.3 sy, 0.0 ni, 81.1 id, 0.1 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 3936712 total, 1250168 free, 1266432 used, 1420112 buff/cache
KiB Swap: 4084732 total, 4084732 free, 0 used. 2276276 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
3006 anyang 20 0 1292192 149316 66144 R 44.9 3.8 188:36.37 plugin-con+
2918 anyang 20 0 1785212 547400 152040 S 18.9 13.9 43:26.11 firefox
977 root 20 0 249384 67896 35808 S 6.3 1.7 5:17.01 Xorg
1847 anyang 20 0 1291444 116428 70200 S 4.3 3.0 2:15.12 compiz
1939 anyang 9 -11 704468 11204 8260 S 2.0 0.3 10:13.63 pulseaudio
7 root 20 0 0 0 0 S 0.3 0.0 0:15.11 rcu_sched
464 root -51 0 0 0 0 S 0.3 0.0 0:34.56 irq/35-iwl+
1607 anyang 20 0 40476 2036 1404 S 0.3 0.1 0:19.73 upstart-db+
3047 anyang 20 0 759188 41952 32264 S 0.3 1.1 0:13.89 gnome-term+
19134 root 20 0 0 0 0 S 0.3 0.0 0:00.09 kworker/u1+
19323 anyang 20 0 49204 4008 3268 R 0.3 0.1 0:00.05 top
1 root 20 0 137464 7324 5124 S 0.0 0.2 0:01.91 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd
3 root 20 0 0 0 0 S 0.0 0.0 0:00.03 ksoftirqd/0
5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:+
8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh
9 root rt 0 0 0 0 S 0.0 0.0 0:00.01 migration/0
相关资料:
- 29个你必须知道的Linux命令: http://www.imooc.com/article/1285
- 常用命令行介绍: https://github.com/iamcoach/console/blob/master/COMMANDS.md
- 常用命令行cheet sheet: https://bbs.excellence-girls.org/topic/167
- 书籍《鸟哥的Linux私房菜》: https://book.douban.com/subject/4889838/
- Ubuntu各种技巧:http://wiki.ubuntu.org.cn/UbuntuSkills