命令行学习笔记(进程和权限相关)

  • 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 

相关资料:

  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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,457评论 5 459
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,837评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,696评论 0 319
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,183评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,057评论 4 355
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,105评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,520评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,211评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,482评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,574评论 2 309
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,353评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,213评论 3 312
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,576评论 3 298
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,897评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,174评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,489评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,683评论 2 335

推荐阅读更多精彩内容