命令行學習筆記(進程和權(quán)限相關(guān))

  • 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 

相關(guān)資料:

  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
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市括尸,隨后出現(xiàn)的幾起案子秘噪,更是在濱河造成了極大的恐慌狮荔,老刑警劉巖丝蹭,帶你破解...
    沈念sama閱讀 217,734評論 6 505
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件渤昌,死亡現(xiàn)場離奇詭異恒傻,居然都是意外死亡,警方通過查閱死者的電腦和手機畏纲,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,931評論 3 394
  • 文/潘曉璐 我一進店門扇住,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人盗胀,你說我怎么就攤上這事艘蹋。” “怎么了票灰?”我有些...
    開封第一講書人閱讀 164,133評論 0 354
  • 文/不壞的土叔 我叫張陵女阀,是天一觀的道長。 經(jīng)常有香客問我屑迂,道長浸策,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,532評論 1 293
  • 正文 為了忘掉前任惹盼,我火速辦了婚禮庸汗,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘手报。我一直安慰自己蚯舱,他們只是感情好,可當我...
    茶點故事閱讀 67,585評論 6 392
  • 文/花漫 我一把揭開白布掩蛤。 她就那樣靜靜地躺著枉昏,像睡著了一般。 火紅的嫁衣襯著肌膚如雪揍鸟。 梳的紋絲不亂的頭發(fā)上兄裂,一...
    開封第一講書人閱讀 51,462評論 1 302
  • 那天,我揣著相機與錄音蜈亩,去河邊找鬼懦窘。 笑死前翎,一個胖子當著我的面吹牛稚配,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播港华,決...
    沈念sama閱讀 40,262評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼道川,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起冒萄,我...
    開封第一講書人閱讀 39,153評論 0 276
  • 序言:老撾萬榮一對情侶失蹤臊岸,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后尊流,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體帅戒,經(jīng)...
    沈念sama閱讀 45,587評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,792評論 3 336
  • 正文 我和宋清朗相戀三年崖技,在試婚紗的時候發(fā)現(xiàn)自己被綠了逻住。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,919評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡迎献,死狀恐怖瞎访,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情吁恍,我是刑警寧澤扒秸,帶...
    沈念sama閱讀 35,635評論 5 345
  • 正文 年R本政府宣布,位于F島的核電站冀瓦,受9級特大地震影響伴奥,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜咕幻,卻給世界環(huán)境...
    茶點故事閱讀 41,237評論 3 329
  • 文/蒙蒙 一渔伯、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧肄程,春花似錦锣吼、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,855評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至拓提,卻和暖如春读恃,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背代态。 一陣腳步聲響...
    開封第一講書人閱讀 32,983評論 1 269
  • 我被黑心中介騙來泰國打工寺惫, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人蹦疑。 一個月前我還...
    沈念sama閱讀 48,048評論 3 370
  • 正文 我出身青樓西雀,卻偏偏與公主長得像,于是被迫代替她去往敵國和親歉摧。 傳聞我的和親對象是個殘疾皇子艇肴,可洞房花燭夜當晚...
    茶點故事閱讀 44,864評論 2 354

推薦閱讀更多精彩內(nèi)容