命令總結(jié)之用戶組和權(quán)限管理篇
- 更新時間2017年06月11
-由于資料過多可能會分很多篇章
useradd
- 創(chuàng)建用戶
- useradd有時候是反過來的adduser
[root@localhost ~]# useradd tank #添加用戶
[root@localhost ~]# useradd -r zhangy #添加系統(tǒng)用戶
[root@localhost ~]# useradd -d /home/zhangying zhangying #添加用戶,并且指定逗物,home目錄
[root@localhost ~]# useradd -g mytest -d /home/hao hao #添加用戶,指定組,并且設(shè)定home目錄
[root@localhost ~]# useradd -e 04/05/13 fxxk #添加用戶,并給用戶設(shè)置有效期
需要說明的是,設(shè)定ID值時盡量要大于500沛励,以免沖突甩挫。因?yàn)長inux安裝后會建立一些特別用戶贴硫,一般0到499之間的值留給bin、mail這樣的系統(tǒng)賬號伊者。
[root@localhost ~]# useradd caojh -u 544
新創(chuàng)建一個oracle用戶英遭,這初始屬于oinstall組,且同時讓他也屬于dba組亦渗。
[root@localhost ~]# useradd oracle -g oinstall -G dba
無法登錄挖诸,且其用戶目錄至/var/ftp/service
[root@localhost ~]# useradd zcx -d /var/ftp/service -s /sbin/nologin
創(chuàng)建一個新用戶 webmaster,不創(chuàng)建用戶自家目錄法精,指定登錄目錄 /www多律,同時加入 apache 附加組中
[root@localhost ~]# useradd -d /www -M -G apache webmaster
[root@localhost ~]# useradd –g sales jack –G company,employees # -g:加入主要組、-G:加入次要組
userdel|deluser
- 刪除用戶
[root@localhost ~]#userdel fxxk #刪除用戶
[root@localhost ~]#userdel -r hao #刪除用戶搂蜓,并且刪除用戶home目錄
usermod|usermod
- 修 改 使 用 者 帳 號
[root@Blackghost ~] usermod -d /home/bak/ zhangying #更改用戶home目錄
[root@Blackghost ~] usermod -e 05/06/13 zhangying #給用戶加個有效期
1狼荞、將 newuser2 添加到組 staff 中
[root@localhost ~]# usermod -G staff newuser2
2、修改 newuser 的用戶名為 newuser1
[root@localhost ~]# usermod -l newuser1 newuser
3帮碰、鎖定賬號 newuser1
[root@localhost ~]# usermod -L newuser1
4相味、解除對 newuser1 的鎖定
[root@localhost ~]# usermod -U newuser1
groupadd|addgroup
- groupadd - 建 立 新 群 組
添加一個用戶組
[root@localhost ~]# groupadd mytest
添加一個用戶組,并指定GID
[root@localhost ~]# groupadd -g 444 test
添加組groupadd -g GID 組名
[root@localhost ~]# groupadd -g 3000 nsd1702
[root@localhost ~]# grep 'nsd1702' /etc/group
groupdel
- 刪除群組
[root@localhost ~]# groupdel test #刪除組test
groupmod
- 修 改 群 組
[root@localhost ~]#groupmod test -n test2 #將test組名換成test2
[root@localhost ~]#groupmod -g 1111 test2 #將test2的gid換成1111
passwd
- 修改用戶密碼
[root@localhost ~]#passwd zhangying #給zhangying修改密碼
[root@localhost ~]#passwd -l test # 鎖定用戶test不能更改密碼;
Locking password for user test.
passwd: Success
[root@localhost ~]#passwd -d test #清除test用戶密碼收毫;
Removing password for user test.
passwd: Success
[root@localhost ~]#passwd -S tank #要顯示用戶密碼的狀態(tài)信息
tank LK 2015-07-25 0 99999 7 -1
[root@localhost ~]#passwd -e test #使test用戶的密碼過期攻走,這將強(qiáng)制用戶在下次登錄時更改密碼
Expiring password for user test.
passwd: 操作成功
[root@localhost ~]#passwd -u test #解鎖用戶密碼
Unlocking password for user test.
passwd:Success
在 passwd 命令中使用 -i 選項(xiàng)用于設(shè)系統(tǒng)用戶的非活動時間殷勘。當(dāng)用戶(我使用的是test用戶)密碼過期后,用戶再經(jīng)過 ‘n‘ 天后(在我的情況下是10天)沒有更改其密碼昔搂,用戶將不能登錄玲销。
[root@localhost ~]#passwd -i 10 test
調(diào)整用戶密碼老化數(shù)據(jù)test。
passwd: 操作成功
-n 選項(xiàng)為指定密碼最小有效期摘符,用戶在此期限內(nèi)不可更改密碼
[root@localhost ~]#passwd -n 90 test
調(diào)整用戶密碼老化數(shù)據(jù)test贤斜。
passwd: 操作成功
‘-w’ 選項(xiàng)在 passwd 命令中用于設(shè)置用戶的警告期限。這意味著逛裤,n天之后瘩绒,密碼將過期
[root@localhost ~]#passwd -w 20 test
調(diào)整用戶密碼老化數(shù)據(jù)test。
passwd: 操作成功
加密機(jī)制:
加密:明文–> 密文
解密:密文–> 明文
單向加密:哈希算法(散列算法)带族,原文不同锁荔,密文必不同
相同算法定長輸出,獲得密文不可逆推出原始數(shù)據(jù)
雪崩效應(yīng):初始條件的微小改變蝙砌,引起結(jié)果的巨大改變
md5: message digest, 128bits
sha1: secure hash algorithm, 160bits
sha224: 224bits
sha256: 256bits
sha384: 384bits
sha512: 512bits
更改加密算法authconfig–passalgo=sha256 –update
即使沒密碼相同阳堕,密文也不相同,加的有隨機(jī)數(shù)(salt)择克。
openssl passwd -1 “salt” :salt一樣恬总,算法一樣 產(chǎn)生的密文也一樣。
authconfig -passalgo256 –update 定義加密算法 或者更改/etc/login.defs文件
getent shadow 用戶名 查看口令密文
默認(rèn)空口令不予許登錄肚邢,壹堰!是鎖定,不允許登錄的意思
usermod -u 用戶名 解鎖的意思 在無口令情況下骡湖,高版本的只能解單!的 <馈!不能解
usermod -L 用戶名 鎖住
root的用戶可以切換到鎖定的賬號 但是普通用戶切換時要讀passwd文件所以切換不了
chage 用戶名 改密碼有效期等
gpasswd
-gpasswd命令
-功能:管理組
-用法:gpasswd[-a user][-d user][-A user,...][-M user,...][-r][-R]groupname
參數(shù):
-a:添加用戶到組
-d:從組刪除用戶
-A:指定管理員
-M:指定組成員和-A的用途差不多
-r:刪除密碼
-R:限制用戶登入組勺鸦,只有組中的成員才可以用newgrp加入該組
[root@localhost ~]# gpasswd -A peter test2 #將peter設(shè)為test2組管理員
[root@localhost ~]# gpasswd -a peter test2 #將用戶peter加入到test2組
[root@localhost ~]# gpasswd -d peter test2 #將用戶peter從test2組中移出
getent
- 用來察看系統(tǒng)的數(shù)據(jù)庫中的相關(guān)記錄
- 用法: getent [選項(xiàng)...] 數(shù)據(jù)庫 [鍵 ...]
[root@localhost ~]#getent hosts baidu.com #從hosts庫中得到baidu.com的IP信息
180.149.132.47 baidu.com
220.181.57.217 baidu.com
123.125.114.144 baidu.com
[root@localhost ~]#getent passwd tank #從passwd庫中得到賬號tank信息
tank:x:502:502::/home/tank:/bin/bash
su
- 切換用戶
[root@localhost ~]# su zhangying #切換用戶并巍,原用戶環(huán)境變量
[root@localhost ~]# su - zhangying #切換用戶目木,新用戶環(huán)境變量
[root@localhost ~]# su -c ls root #切換用戶執(zhí)行命令换途,執(zhí)行后返回原用戶
su命令和su -命令最大的本質(zhì)區(qū)別就是:前者只是切換了root身份,但Shell環(huán)境仍然是普通用戶的Shell刽射;而后者連用戶和Shell環(huán)境一起切換成root身份了军拟。
[root@localhost ~]# su #切換到root
[root@localhost ~]# su - #切換到root
newgrp
- 功能說明:登入另一個群組
[root@localhost ~]# newgrp www #登錄到www群組
id
- 用法:id [選項(xiàng)]... [用戶名]
- 顯示指定用戶或當(dāng)前用戶(當(dāng)未指定用戶時)的用戶與組信息
[root@localhost ~]# id #顯示當(dāng)前用戶的信息
uid=0(root) gid=0(root) 組=0(root)
[root@localhost ~]# id zhangy #顯示zhangy的信息
uid=999(zhangy) gid=999(zhangy) 組=999(zhangy)
chage
密碼失效是通過此命令來管理的。
參數(shù)意思:
-m 密碼可更改的最小天數(shù)誓禁。為零時代表任何時候都可以更改密碼懈息。
-M 密碼保持有效的最大天數(shù)。
-W 用戶密碼到期前摹恰,提前收到警告信息的天數(shù)辫继。
-E 帳號到期的日期怒见。過了這天,此帳號將不可用姑宽。
-d 上一次更改的日期
-I 停滯時期遣耍。如果一個密碼已過期這些天,那么此帳號將不可用炮车。
-l 例出當(dāng)前的設(shè)置舵变。由非特權(quán)用戶來確定他們的密碼或帳號何時過期
[root@localhost ~]# chage -l zhangy #查看用戶密碼設(shè)定情況
最近一次密碼修改時間 : 4月 27, 2013
密碼過期時間 : 從不
密碼失效時間 : 從不
帳戶過期時間 : 從不
兩次改變密碼之間相距的最小天數(shù) :-1
兩次改變密碼之間相距的最大天數(shù) :-1
在密碼過期之前警告的天數(shù) :-1
[root@localhost ~]# chage -M 90 zhangy #密碼有效期90天
[root@localhost ~]# chage -d 0 zhangy #強(qiáng)制用戶登陸時修改口令
[root@localhost ~]# chage -d 0 -m 0 -M 90 -W 15 zhangy #強(qiáng)制用戶下次登陸時修改密碼,并且設(shè)置密碼最低有效期0和最高有限期90瘦穆,提前15天發(fā)警報提示
[root@localhost ~]# chage -E '2014-09-30' test # test這個賬號的有效期是2014-09-30
chfn
chfn - 改 變 你 的 finger 訊 息
[root@localhost ~]#hfn
正在改變 root 的用戶信息
請輸入新值纪隙,或直接敲回車鍵以使用默認(rèn)值
全名 [root]: zhangy
房間號碼 []: 8888
工作電話 []: 1234567
家庭電話 []: 7654321
其它 []: no
[root@localhost ~]# chfn -f tank
finger
- 用戶信息查找程序
[root@localhost ~]# finger munin #查看munin用戶信息
Login: munin Name: Munin user
Directory: /var/lib/munin Shell: /sbin/nologin
Never logged in.
No mail.
No Plan.
[root@localhost ~]#finger -l #顯示當(dāng)前登錄用戶信息
[root@localhost ~]#finger -m root@192.168.1.13 #顯示遠(yuǎn)程用戶信息
chsh
- 用于 改變 用戶的 登錄 shell. 如果 沒有在 命令行上 指定 shell, chsh 能夠 做出 提示.
[root@localhost ~]# chsh #必變當(dāng)前用戶的shell
Changing shell for root.
New shell [/bin/bash]: /bin/csh #輸入新的shell地址
Shell changed.
[root@localhost ~]# chsh -s /bin/csh #改變當(dāng)前用戶shell,設(shè)置為 /bin/csh
Changing shell for root.
Shell not changed.
pwconv
- 命令用來開啟用戶的投影密碼
[root@localhost ~]# cat /etc/passwd | grep test
[root@localhost ~]# test:x:3001:3001::/home/test:/bin/sh
此時可以發(fā)現(xiàn)密碼段是x
[root@localhost ~]# cat /etc/shadow | grep test
[root@localhost ~]# test:nYOEWamm$bz07nlv/.RgJufb3FAqJJeULfwybzgxmrWqbk7O4vI0KsT6N.ujrh6dDIUcAJdfjksyuyAFDPIngZeD3cgcf.0:15022:0:99999:7:::
## pwunconv
- pwunconv命令與pwconv功能相反,用來關(guān)閉用戶的投影密碼扛或。它會把密碼從shadow文件內(nèi)绵咱,重回存到passwd文件里
[root@localhost ~]# pwunconv #關(guān)閉影子密碼
[root@localhost ~]# cat /etc/passwd | grep test #發(fā)現(xiàn)密碼已經(jīng)在passwd文件中了
test:nYOEWamm$bz07nlv/.RgJufb3FAqJJeULfwybzgxmrWqbk7O4vI0KsT6N.ujrh6dDIUcAJdfjksyuyAFDPIngZeD3cgcf.0:3001:3001::/home/test:/bin/sh
[root@localhost ~]# ls /etc/shadow #查看影子文件,提示沒有這個文件或目錄
ls: cannot access /etc/shadow: No such file or directory
## pwck
- pwck命令用來驗(yàn)證系統(tǒng)認(rèn)證文件/etc/passwd和/etc/shadow的內(nèi)容和格式的完整性
用法:pwck [-q] [-r] [-s] [passwd [shadow]]
[root@localhost ld.so.conf.d]# pwck /etc/passwd
user 'adm': directory '/var/adm' does not exist
user 'uucp': directory '/var/spool/uucp' does not exist
user 'gopher': directory '/var/gopher' does not exist
user 'ftp': directory '/var/ftp' does not exist
user 'avahi-autoipd': directory '/var/lib/avahi-autoipd' does not exist
user 'pulse': directory '/var/run/pulse' does not exist
user 'saslauth': directory '/var/empty/saslauth' does not exist
pwck:無改變
## chown
>用法:chown [選項(xiàng)]... [所有者][:[組]] 文件...
或:chown [選項(xiàng)]... --reference=參考文件 文件...
更改每個文件的所有者和/或所屬組熙兔。
[root@localhost ~]# chown zhangy:zhangy nginx.conf #將nginx.conf所屬用戶和組改為zhangy,zhangy
[root@localhost ~]# ls -al |grep nginx.conf
-rw-r--r-- 1 zhangy zhangy 0 5月 3 15:21 nginx.conf
[root@localhost ~]# chown -R zhangy:zhangy www #將www目錄麸拄,所屬用戶和組改為zhangy,zhangy
[root@localhost ~]# ls -al |grep ww
drwxr-xr-x 2 zhangy zhangy 4096 5月 3 15:20 www
[root@localhost ~]# chown root nginx.conf #將nginx.conf,所屬用戶改為root
[root@localhost ~]# ls -al |grep nginx.conf
-rw-r--r-- 1 root zhangy 0 5月 3 15:21 nginx.conf
[root@localhost database]# ll
總用量 4592
-rw-r--r-- 1 root root 2466 7月 23 18:02 1.html
-rw-r--r--. 1 tank tank 4099771 5月 28 14:42 28toplearning.sql
-rw-r--r--. 1 tank tank 596069 5月 29 00:07 toplearning.tar.gz
[root@localhost database]# chown .tank 1.html #只改變組
[root@localhost database]# ll
總用量 4592
-rw-r--r-- 1 root tank 2466 7月 23 18:02 1.html #組已改變
-rw-r--r--. 1 tank tank 4099771 5月 28 14:42 28toplearning.sql
-rw-r--r--. 1 tank tank 596069 5月 29 00:07 toplearning.tar.gz
## chmod
>相關(guān)命令:chattr,chown,chacl
用法:chmod [選項(xiàng)]... 模式[,模式]... 文件...
或:chmod [選項(xiàng)]... 八進(jìn)制模式 文件...
或:chmod [選項(xiàng)]... --reference=參考文件 文件...
將每個文件的模式更改為指定值黔姜。
-c, --changes 類似 --verbose拢切,但只在有更改時才顯示結(jié)果
--no-preserve-root 不特殊對待根目錄(默認(rèn))
--preserve-root 禁止對根目錄進(jìn)行遞歸操作
-f, --silent, --quiet 去除大部份的錯誤信息
-v, --verbose 為處理的所有文件顯示診斷信息
--reference=參考文件 使用指定參考文件的模式,而非自行指定權(quán)限模式
-R, --recursive 以遞歸方式更改所有的文件及子目錄
--help 顯示此幫助信息并退出
--version 顯示版本信息并退出
每種 MODE 都應(yīng)屬于這類形式"[ugoa]*(-+=)+"秆吵。
操作對像
u 文件屬主權(quán)限
g 同組用戶權(quán)限
o 其它用戶權(quán)限
a 所有用戶(包括以上三種)
權(quán)限設(shè)定
- 增加權(quán)限
- 取消權(quán)限
= 唯一設(shè)定權(quán)限
權(quán)限類別
r 讀權(quán)限
w 寫權(quán)限
x 執(zhí)行權(quán)限
X 表示只有當(dāng)該檔案是個子目錄或者該檔案已經(jīng)被設(shè)定過為可執(zhí)行淮椰。
s 文件屬主和組id
l 給文件加鎖,使其它用戶無法訪問
r-->4
w-->2
x-->1
[root@localhost ~]# chmod ugo+r nginx_bak.conf #所有人皆可讀取
[root@localhost ~]# chmod a+r nginx_bak.conf #所有人皆可讀取
[root@localhost ~]# chmod ug+w,o-w nginx_bak.conf #設(shè)為該檔案擁有者纳寂,與其所屬同一個群體者可寫入主穗,但其他以外的人則不可寫入
[root@localhost ~]# chmod u+x nginx_bak.conf #創(chuàng)建者擁有執(zhí)行權(quán)限
[root@localhost ~]# chmod -R a+r ./www/ #將www下的所有檔案與子目錄皆設(shè)為任何人可讀取
[root@localhost ~]# chmod a-x nginx_bak.conf #收回所有用戶的對nginx_bak.conf的執(zhí)行權(quán)限
[root@localhost ~]# chmod 777 nginx_bak.conf #所有人可讀,寫毙芜,執(zhí)行
[root@localhost ~]#chmod a+s test.ppt #chmod g+s 忽媒,為某個文件設(shè)置替代組標(biāo)識
[root@localhost ~]#ls -al |grep test.ppt
-rwSr-Sr--. 1 tank tank 2320384 11月 18 19:29 test.ppt
第一個S指示用戶替代標(biāo)識(suid)已經(jīng)被設(shè)置。
第二個S指示替代組標(biāo)識(sgid)已經(jīng)被設(shè)置腋粥。
這樣晦雨,每一個運(yùn)行該程序的用戶將給予和程序擁有者同樣有效的用戶標(biāo)識,和用戶所屬組同樣有效的組標(biāo)識隘冲。
[root@localhost ~]# chmod +x test #所有用戶加執(zhí)行權(quán)限
## wc
- wc命令的功能為統(tǒng)計指定文件中的字節(jié)數(shù)闹瞧、單詞數(shù)、行數(shù), 并將統(tǒng)計結(jié)果顯示輸出
>參數(shù)
-c, --bytes打印字節(jié)數(shù)
-m, --chars 打印字符數(shù)
-l, --lines 打印行數(shù)
-L, --max-line-length 打印最長行的長度
-w, --words 打印單詞數(shù)
[root@localhost ~]# cat /etc/passwd |wc -l #查看passwd文件有多少行
38
[root@localhost ~]# echo "aaa bbb ccc" |wc -w #查看輸出有多少個單詞
3
[root@localhost ~]# echo "12344" |wc -m #查看輸出有多少個字符
6
## sort
>用法:sort [選項(xiàng)]... [文件]...
或:sort [選項(xiàng)]... --files0-from=F
串聯(lián)排序所有指定文件并將結(jié)果寫到標(biāo)準(zhǔn)輸出展辞。
[root@www ~]# cat /etc/passwd | sort #sort 是默認(rèn)以第一個數(shù)據(jù)來排序奥邮,而且默認(rèn)是以字符串形式來排序,所以由字母 a 開始升序排序。
[root@www ~]# cat /etc/passwd | sort -t ':' -k 3 #/etc/passwd 內(nèi)容是以 : 來分隔的,我想以第三欄來排序洽腺,該如何
[root@www ~]# cat /etc/passwd | sort -t ':' -k 3n #用數(shù)字排序脚粟,默認(rèn)是以字符串來排序的
[root@www ~]# cat /etc/passwd | sort -t ':' -k 3nr #倒序排列,默認(rèn)是升序排序
[root@www ~]# ccat /etc/passwd | sort -t':' -k 6.2,6.4 -k 1r #對/etc/passwd,先以第六個域的第2個字符到第4個字符進(jìn)行正向排序蘸朋,再基于第一個域進(jìn)行反向排序
[root@www ~]# cat /etc/passwd | sort -t':' -k 7 -u #查看/etc/passwd有多少個shell:對/etc/passwd的第七個域進(jìn)行排序珊楼,然后去重
## uniq
>用法:uniq [選項(xiàng)]... [文件]
從輸入文件或者標(biāo)準(zhǔn)輸入中篩選相鄰的匹配行并寫入到輸出文件或標(biāo)準(zhǔn)輸出
[root@localhost ~]# cat uniqtest #測試文件
this is a test
this is a test
this is a test
i am tank
i love tank
i love tank
this is a test
whom have a try
WhoM have a try
you have a try
i want to abroad
those are good men
we are good men
[root@localhost ~]# uniq -c uniqtest #uniq的一個特性,檢查重復(fù)行的時候度液,只會檢查相鄰的行厕宗。重復(fù)數(shù)據(jù),肯定有很多不是相鄰在一起的
3 this is a test
1 i am tank
2 i love tank
1 this is a test #和第一行是重復(fù)的
1 whom have a try
1 WhoM have a try
1 you? have a try
1 i want to abroad
1 those are good men
1 we are good men
[root@localhost ~]# sort uniqtest |uniq -c #這樣就可以解決上個例子中提到的問題
1 WhoM have a try
1 i am tank
2 i love tank
1 i want to abroad
4 this is a test
1 those are good men
1 we are good men
1 whom have a try
1 you have a try
[root@localhost ~]# uniq -d -c uniqtest #uniq -d 只顯示重復(fù)的行
3 this is a test
2 i love tank
[root@localhost ~]# uniq -D uniqtest #uniq -D 只顯示重復(fù)的行堕担,并且把重復(fù)幾行都顯示出來已慢。他不能和-c一起使用
this is a test
this is a test
this is a test
i love tank
i love tank
[root@localhost ~]# uniq -f 1 -c uniqtest #在這里those只有一行,顯示的卻是重復(fù)了霹购,這是因?yàn)椋?f 1 忽略了第一列佑惠,檢查重復(fù)從第二字段開始的。
3 this is a test
1 i am tank
2 i love tank
1 this is a test
2 whom have a try
1 you have a try
1 i want to abroad
2 those are good men #只有一行齐疙,顯示二行
[root@localhost ~]# uniq -i -c uniqtest #檢查的時候膜楷,不區(qū)分大小寫
3 this is a test
1 i am tank
2 i love tank
1 this is a test
2 whom have a try #一個大寫,一個小寫
1 you have a try
1 i want to abroad
1 those are good men
1 we are good men
[root@localhost ~]# uniq -s 4 -c uniqtest #檢查的時候贞奋,不考慮前4個字符赌厅,這樣whom have a try 就和 you have a try 就一樣了。
3 this is a test
1 i am tank
2 i love tank
1 this is a test
3 whom have a try #根上一個例子有什么不同
1 i want to abroad
1 those are good men
1 we are good men
[root@localhost ~]# uniq -u uniqtest #去重復(fù)的項(xiàng)轿塔,然后全部顯示出來
i am tank
this is a test
whom have a try
WhoM have a try
you have a try
want to abroad
those are good men
we are good men
[root@localhost ~]# uniq -w 2 -c uniqtest #對每行第2個字符以后的內(nèi)容不作檢查特愿,所以i am tank 根 i love tank就一樣了。
3 this is a test
3 i am tank
1 this is a test
1 whom have a try
1 WhoM have a try
1 you have a try
1 i want to abroad
1 those are good men
1 we are good men
[root@localhost ~]# grep -oE '[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}' /var/log/nginx/access.log |sort |uniq -c #查看nginx訪問IP數(shù)
1 101.200.78.64
2 103.41.52.94
1 106.185.47.161
2 113.240.250.155
260 13.0.782.215
2 185.130.5.231
26 192.168.10.16
6 192.168.10.17
148 192.168.10.2
189 192.168.10.202
270 192.168.10.222
25 192.168.10.235
291 192.168.10.3
12 192.168.10.5
2 23.251.63.45
20 7.0.11.0
## diff
- diff 比較兩個文件的內(nèi)容 (源文件 和 目標(biāo)文件)
- . 文件名可以是 - 由標(biāo)準(zhǔn)輸入設(shè)備讀入的文本. 作為特別的情況是,
- diff - - 比較一份標(biāo)準(zhǔn)輸入的它自己的拷貝
- 如果 源文件 是一個目錄和 目標(biāo)文件 不是(目錄)
- diff 會比較在 源文件
- (目錄) 里的文件的中和 目標(biāo)文件同名的(文件)
- 反過來也一樣. 非目錄文件不能是
[root@localhost ~]# diff test1.rb test.rb #比較二個文件的不同
1c1,6
< puts "hekkk"
require "mysql"
dbc=Mysql.real_connect('localhost','root','','test')
query_parse=dbc.query('select * from user')
while row=query_parse.fetch_row do
puts "#{row[0]},#{row[1]}"
end
[root@localhost ~]# diff myweb/ html/ #比較二個文件夾的不同
Only in html/: a.php
Only in html/: phpmyadmin
[root@localhost ~]# diff -r myweb/ html/ #遞歸比較二個文件夾的不同
Only in html/: a.php
Only in html/: phpmyadmin
[root@localhost ~]# diff -ruN test.rb test1.rb #補(bǔ)定文件的內(nèi)容
--- test.rb 2013-01-31 21:24:57.000000000 +0800
+++ test1.rb 2013-01-31 21:10:08.000000000 +0800
@@ -1,6 +1 @@
-require "mysql"
-dbc=Mysql.real_connect('localhost','root','','test')
-query_parse=dbc.query('select * from user')
-while row=query_parse.fetch_row do
- puts "#{row[0]},#{row[1]}"
-end
+puts "hekkk"
[root@localhost ~]# diff -ruN test.rb test1.rb > test.diff #產(chǎn)生補(bǔ)定文件
## stat
- 用法:stat [選項(xiàng)]... 文件...
- 顯示文件或文件系統(tǒng)的狀態(tài)
[root@localhost ~]# stat abc.ph
文件:"abc.ph"
大泄寸浴:0 塊:0 IO 塊:4096 普通空文件
設(shè)備:801h/2049d Inode:1200314 硬鏈接:1
權(quán)限:(0644/-rw-r--r--) Uid:( 0/ root) Gid:( 0/ root)
最近訪問:2013-05-14 13:24:30.830729223 +0800
最近更改:2013-05-14 13:24:30.830729223 +0800
最近改動:2013-05-14 13:24:30.830729223 +0800
創(chuàng)建時間:-
[root@localhost ~]# stat -c %a pass.sh #顯示pass.sh文件的數(shù)字權(quán)限
644