命令行學習筆記(進程和權限相關)

  • 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> -- 創(chuàng)建用戶
  • 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> -- 創(chuàng)建組
  • 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 -- 實時顯示系統(tǒng)中各個進程的資源使用情況

效果如下:

?  ~ 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 

相關資料:

  1. 29個你必須知道的Linux命令: http://www.imooc.com/article/1285
  2. 常用命令行介紹: https://github.com/iamcoach/console/blob/master/COMMANDS.md
  3. 常用命令行cheet sheet: https://bbs.excellence-girls.org/topic/167
  4. 書籍《鳥哥的Linux私房菜》: https://book.douban.com/subject/4889838/
  5. Ubuntu各種技巧:http://wiki.ubuntu.org.cn/UbuntuSkills
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容