命令總結(jié)之文件命令篇
- 此命令總結(jié)會(huì)分幾篇
- 文件命令篇
- 系統(tǒng)命令篇
- 組權(quán)限命令篇
- 特殊命令篇
- 更新時(shí)間2017年06月10日
-由于資料過多可能會(huì)分很多篇章
文件命令
cd
- cd 用來切換路徑
[root@localhost ~]# cd /home/ #切換到home目錄
[root@localhost home]# cd - #返回切換到home前的目錄
[root@localhost ~]# cd ../ #切換到上一級(jí)目錄
[root@localhost /]# cd ~ #切換當(dāng)前用戶的home目錄
[root@localhost ~]# cd / # 系統(tǒng)根目錄
[root@localhost ~]# cd # root根目錄
[root@localhost ~]# cd ../../ #返回上上一層目錄
ls
- ls查看目錄或當(dāng)前目錄或文件屬性等詳細(xì)信息
用法:ls [選項(xiàng)]... [文件]...
[root@rudder ~]# ls
bak tank
[root@rudder ~]# ls -l
總用量 8
drwxr-xr-x 2 root root 4096 4月 27 12:34 bak
drwxr-xr-x 4 tnak tnak 4096 4月 28 14:25 tank
[root@localhost ~]# ls /bin #查看bin目錄下的文件
arch dnsdomainname kbd_mode pgawk tar
awk doexec keyctl ping taskset
basename domainname kill ping6 touch
bash dumpkeys link ps tracepath
cat echo ln pwd tracepath6
[root@localhost ~]# ls -d */ #列出當(dāng)前所有目錄
block/ bus/ cpu/ fd/ input/ net/ raw/ snd/
[root@localhost ~]# ll -Z -d /var/www/html/
drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 /var/www/html/
[root@localhost ~]# ll -Z install.log
-rw-r--r--. root root system_u:object_r:admin_home_t:s0 install.log
[root@localhost ~]# df -a #顯示所有文件系統(tǒng)的磁盤使用情況
[root@localhost ~]# ls -l #顯示當(dāng)前目錄內(nèi)容的長列表
總用量 12
-rwxrwxrwx 1 apache apache 4674 8月 23 14:21 app.config.php
-rwxrwxrwx 1 apache apache 442 8月 23 14:26 db.config.php
[root@localhost ~]# ls -lh #不以字節(jié)方式顯示文件大小
總用量 12K
-rwxrwxrwx 1 apache apache 4.6K 8月 23 14:21 app.config.php
-rwxrwxrwx 1 apache apache 442 8月 23 14:26 db.config.php
[root@localhost ~]# ls -ihS #顯示文件大小之后,從大到小排序
264672 app.config.php 264673 db.config.php
[root@localhost ~]# ls -l --block-size=M #使用MB作為單位,文件大小
總用量 1M
-rwxrwxrwx 1 apache apache 1M 8月 23 14:21 app.config.php
-rwxrwxrwx 1 apache apache 1M 8月 23 14:26 db.config.php
[root@localhost ~]# ls -a #顯示隱藏文件
. .. app.config.php db.config.php
[root@localhost ~]# ls -d */ #只列出目錄
admin/ etc/ lib/ resource/ server/ tools/ tpls/
[root@localhost ~]# ls -g #不打印所有者信息
總用量 12
-rwxrwxrwx 1 apache 4674 8月 23 14:21 app.config.php
-rwxrwxrwx 1 apache 442 8月 23 14:26 db.config.php
[root@localhost ~]# ls -lG #不打印組信息
總用量 12
-rwxrwxrwx 1 apache 4674 8月 23 14:21 app.config.php
-rwxrwxrwx 1 apache 442 8月 23 14:26 db.config.php
[root@localhost ~]# ls -n #打印UID和GID
總用量 12
-rwxrwxrwx 1 48 48 4674 8月 23 14:21 app.config.php
-rwxrwxrwx 1 48 48 442 8月 23 14:26 db.config.php
[root@localhost ~]# ls -li #打印每個(gè)文件的索引號(hào)
總用量 12
264672 -rwxrwxrwx 1 apache apache 4674 8月 23 14:21 app.config.php
264673 -rwxrwxrwx 1 apache apache 442 8月 23 14:26 db.config.php
[root@localhost ~]# ls -p #目錄增加 / (斜線)
admin/ etc/ lib/ resource/ server/ tools/ tpls/
[root@localhost ~]# ls -r #按時(shí)間倒排序
db.config.php app.config.php
[root@localhost ~]# ls -R #遞歸列出子目錄
.:
phpass phpthumb
./phpass:
PasswordHash.php
./phpthumb:
GdThumb.inc.php PhpThumb.inc.php README.md ThumbBase.inc.php ThumbLib.php thumb_plugins
./phpthumb/thumb_plugins:
gd_reflection.inc.php
./restfullyii:
components views
[root@localhost ~]# ls -lx #擴(kuò)展名排序
anaconda-ks.cfg Desktop Documents Downloads
initial-setup-ks.cfg Music Pictures Public
Templates Videos
[root@localhost ~]# ls -lt #按修改時(shí)間倒排序
total 8
drwxr-xr-x. 2 root root 6 Jun 10 03:37 Documents
drwxr-xr-x. 2 root root 6 Jun 10 03:37 Music
drwxr-xr-x. 2 root root 6 Jun 10 03:37 Pictures
drwxr-xr-x. 2 root root 6 Jun 10 03:37 Public
drwxr-xr-x. 2 root root 6 Jun 10 03:37 Videos
drwxr-xr-x. 2 root root 6 Jun 10 03:37 Desktop
drwxr-xr-x. 2 root root 6 Jun 10 03:37 Downloads
drwxr-xr-x. 2 root root 6 Jun 10 03:37 Templates
-rw-r--r--. 1 root root 1621 Jun 10 03:24 initial-setup-ks.cfg
-rw-------. 1 root root 1590 Jun 10 01:54 anaconda-ks.cfg
dir
- 用法:dir [選項(xiàng)]... [文件]
[root@localhost ~]#dir
bak tank
[root@localhost ~]# dir -l
總用量 8
drwxr-xr-x 2 root root 4096 4月 27 12:34 bak
drwxr-xr-x 4 tnak tnak 4096 4月 28 14:25 tank
touch
- 用法:touch [選項(xiàng)]... 文件
[root@localhost ~]# touch test.php #將test.php的檔案時(shí)間改為帽衙,當(dāng)前時(shí)間
[root@localhost ~]# touch -c -t 05061803 test.php #將檔案時(shí)間改為,5月6日18點(diǎn)3分
[root@localhost ~]# touch -r abc.php test.php #將test.php檔案改成跟abc.php一樣
[root@localhost ~]# touch -d "2 days ago" test.php #將test.php日期修改為2天以前
cp
用法:cp [選項(xiàng)]... [-T] 源文件 目標(biāo)文件
- 或:cp [選項(xiàng)]... 源文件... 目錄
- 或:cp [選項(xiàng)]... -t 目錄 源文件...
- 將源文件復(fù)制至目標(biāo)文件数尿,或?qū)⒍鄠€(gè)源文件復(fù)制至目標(biāo)目錄
[root@localhost ~]# cp -p test.rb /home/test #將test.rb copy到test目錄赦肃,并且保留原文件的屬性
[root@localhost ~]# cp -r Dir/ /home/test #將Dir目錄copy到test目錄下
[root@localhost ~]#cp -fr Dir/* /home/test #將Dir下面的所有文件強(qiáng)制copy到test目錄下
[root@localhost www]# cp test.rb{,.bak} #備份test.rb适室,并在尾部加上.bak后綴
[root@localhost ~]# cp -u -v file1 file2 #復(fù)制文件勿负,只有源文件較目的文件的修改時(shí)間新時(shí)馏艾,才復(fù)制文件
[root@localhost ~]# cp file1 file2 #將文件file1復(fù)制成文件file2
[root@localhost ~]# cp -i file1 file2 #采用交互方式將文件file1復(fù)制成文件file2
[root@localhost ~]# cp -f file1 file2
#將文件file1復(fù)制成file2,因?yàn)槟康奈募呀?jīng)存在奴愉,所以指定使用強(qiáng)制復(fù)制的模式
[root@localhost ~]# cp -R file1 file2 #將目錄dir1復(fù)制成目錄dir2
[root@localhost ~]# cp -R file1 file2 file3 dir1 dir2
#同時(shí)將文件file1琅摩、file2、file3與目錄dir1復(fù)制到dir2
[root@localhost ~]# cp -p a.txt tmp/ #復(fù)制時(shí)保留文件屬性
[root@localhost ~]# cp -P /var/tmp/a.txt ./temp/ #復(fù)制時(shí)保留文件的目錄結(jié)構(gòu)
[root@localhost ~]# cp -b a.txt tmp/ #復(fù)制時(shí)產(chǎn)生備份文件
[root@localhost ~]# cp -b -V t a.txt /tmp #復(fù)制時(shí)產(chǎn)生備份文件锭硼,尾標(biāo) ~1~格式
[root@localhost ~]# cp -b -S _bak a.txt /tmp #指定備份文件尾標(biāo)
mv
用法:mv [選項(xiàng)]... [-T] 源文件 目標(biāo)文件
或:mv [選項(xiàng)]... 源文件... 目錄
或:mv [選項(xiàng)]... -t 目錄 源文件...
將源文件重命名為目標(biāo)文件房资,或?qū)⒃次募苿?dòng)至指定目錄
[root@localhost ~]# mv abc abc.php #將abc移動(dòng)成abc.php
[root@localhost ~]# mv test.php{,.sh} #將test.php增加后輟
[root@localhost ~]# mv -t ./database 1.sql #將1.sql移動(dòng)到database目錄下
[root@localhost ~]# mv aaa bbb #將目錄或者文件重命名,如果存在bbb目錄,則是將aaa移到bbb目錄下
[root@localhost ~]# su root
Password:
[root@localhost home]# mv home php
[root@localhost home]# ls
flitrue php
rename
rename 用于 對(duì)文件進(jìn)行命名管理账忘,可進(jìn)行批量命名并支持正則表達(dá)式志膀, rename命令存在兩個(gè)版本用法上有所區(qū)別 一個(gè)是 C語言版本支持通配符,另一個(gè)是 Perl版本.支持正則表達(dá)式
[root@localhost ~]# rename 's/\.sh/\.php/' * #將當(dāng)前目錄下.sh后綴的文件鳖擒,變成.php
[root@localhost ~]#rename 's/$/\.bak/' /home/www/*.php #給www目錄下的.php加上bak后綴
[root@localhost ~]# rename 's/^/bak_/' *.bin #給當(dāng)前目錄下的.bin后綴文件加上bak_前綴
[root@localhost ~]# rename 's/\.bin$//' * #批量刪除當(dāng)前目錄下所有文件的.bin 后綴
[root@localhost ~]# rename 's/A-Z/a-z/' * #修改當(dāng)前目錄所有文件名為小寫
mkdir
用法:mkdir [選項(xiàng)]... 目錄...
若指定目錄不存在則創(chuàng)建目錄溉浙。
[root@localhost ~]# mkdir aaa #創(chuàng)建目錄
[root@localhost ~]# mkdir -m a=rw bbb #創(chuàng)建指定屬性的目錄
[root@localhost ~]# mkdir -p 111/abc #創(chuàng)建目錄,父目錄存在蒋荚,建之
[root@localhost ~]# mkdir -v test1 #創(chuàng)建目錄,并顯示詳細(xì)信息
mkdir: 已創(chuàng)建目錄 "test1"
[root@localhost ~]# mkdir -p /ms/{sales,hr,web} #創(chuàng)建一個(gè)名為/ms的目錄戳稽,其中有sales、hr期升、web的子目錄
rmdir
用法:rmdir [選項(xiàng)]... 目錄...
刪除指定的空目錄惊奇。
[root@localhost ~]# rmdir test #刪除test目錄,注意必須是空目錄
[root@localhost ~]# rmdir -p a/b/c #刪除指定目錄及其上級(jí)文件夾
rm
用法:rm [選項(xiàng)]... 文件...
刪除 (unlink) 文件播赁。
[root@localhost ~]# rm test.php #刪除文件需要確認(rèn)
[root@localhost ~]# rm -f test.php #強(qiáng)制刪除文件不確認(rèn)
[root@localhost ~]# rm -rfv ./test #強(qiáng)制刪除當(dāng)前的test目錄颂郎,并顯示刪除的詳細(xì)過程
[root@localhost ~]# rm -rf expect-5.43 #參數(shù)表示遞歸強(qiáng)制刪除非空文件夾
tree
- 顯示目錄樹進(jìn)程 使用以前需要輸入 yum install tree 來下載
[root@localhost ~]# tree -L 2 #-L n 只顯示 n 層目錄 (n 為數(shù)字)
.
├── anaconda-ks.cfg
├── Desktop
├── Documents
├── Downloads
├── initial-setup-ks.cfg
├── Music
├── Pictures
├── Public
├── Templates
└── Videos
[root@localhost ~]# tree -t #-t 用文件和目錄的更改時(shí)間排序
.
├── Desktop
├── Documents
├── Downloads
├── Music
├── Pictures
├── Public
├── Templates
├── Videos
├── initial-setup-ks.cfg
└── anaconda-ks.cfg
[root@localhost ~]# tree -r #-r 以相反次序排列
.
├── Videos
├── Templates
├── Public
├── Pictures
├── Music
├── initial-setup-ks.cfg
├── Downloads
├── Documents
├── Desktop
└── anaconda-ks.cfg
#-F 在執(zhí)行文件,目錄容为,Socket乓序,符號(hào)連接,管道名稱名稱坎背,各自加上"*","/","=","@","|"號(hào)
[root@localhost ~]# tree -F
.
├── anaconda-ks.cfg
├── Desktop/
├── Documents/
├── Downloads/
├── initial-setup-ks.cfg
├── Music/
├── Pictures/
├── Public/
├── Templates/
└── Videos/
[root@localhost ~]# tree -f #在每個(gè)文件或目錄之前替劈,顯示完整的相對(duì)路徑名稱
.
├── ./anaconda-ks.cfg
├── ./Desktop
├── ./Documents
├── ./Downloads
├── ./initial-setup-ks.cfg
├── ./Music
├── ./Pictures
├── ./Public
├── ./Templates
└── ./Videos
[root@localhost ~]# tree -d #只顯示目錄
.
├── Desktop
├── Documents
├── Downloads
├── Music
├── Pictures
├── Public
├── Templates
└── Videos
[root@localhost ~]# tree -a #顯示所有文件和目錄 (由于目錄太長沒有顯示)
touch
用法:touch [選項(xiàng)]... 文件...
將每個(gè)文件的訪問時(shí)間和修改時(shí)間改為當(dāng)前時(shí)間
[root@localhost ~]# touch test.php #將test.php的檔案時(shí)間改為,當(dāng)前時(shí)間得滤,文件不存在建之
[root@localhost ~]# touch -c -t 05061803 test.php #將檔案時(shí)間改為,5月6日18點(diǎn)3分
[root@localhost ~]# touch -r abc.php test.php #將test.php檔案改成跟abc.php一樣
[root@localhost ~]# touch -d "2 days ago" test.php #將test.php日期修改為2天以前
nano
用法: nano [選項(xiàng)] [[+行,列] 文件名]..
[root@localhost ~]# nano test.php #編輯文件
cat
用法:cat [選項(xiàng)] [文件]...
將[文件]或標(biāo)準(zhǔn)輸入組合輸出到標(biāo)準(zhǔn)輸出
[root@localhost ~]# cat test #普通輸出
1111111111
2222222222
3333333333
[root@localhost ~]# cat -n test #開頭顯示行號(hào)
1 1111111111
2
3
4 2222222222
5
6 3333333333
[root@localhost ~]# cat -E test #以$結(jié)束
1111111111$
$
$
2222222222$
$
3333333333$
[root@localhost ~]# cat -s test #超過二個(gè)空行陨献,合并成一個(gè)
1111111111
2222222222
3333333333
[root@localhost ~]# cat -ns test #去空行,加行號(hào)
1 1111111111
2
3 2222222222
4
5 3333333333
[root@localhost ~]# cat x* > google_bak.tar.gz #合并文件
[root@localhost ~]# cat > aa #從鍵盤錄入內(nèi)容到文件懂更,回車是保存眨业,退出Ctrl+z
4234234
234234
^Z
[4]+ Stopped cat > aa
[root@localhost ~]# cat file1 file2 > file #合并二個(gè)文件為一個(gè)
[root@localhost ~]# cat test.tar.gz_?? > test.tar.gz #可以用cat命令將被切割的多個(gè)壓縮包合并成一個(gè)
[root@localhost ~]# tar -xvzf test.tar.gz #再用tar命令解壓
tac
用法:tac [選項(xiàng)]... [文件]...
將每個(gè)指定文件按行倒置并寫到標(biāo)準(zhǔn)輸出。
如果不指定文件沮协,或文件為"-"坛猪,則從標(biāo)準(zhǔn)輸入讀取數(shù)據(jù)
[root@localhost ~]# cat test
1234
abcd
[root@localhost ~]# rev test
4321
dcba
[root@localhost ~]# tac test
abcd
1234
pwd
pwd 顯示當(dāng)前目錄
[root@localhost ~]# pwd #顯示當(dāng)前目錄
/home
[root@localhost ~]# pwd -P #目錄是軟連接,顯示實(shí)際物理地址
/var/spool/mail
[root@localhost ~]# pwd -L #-L顯示皂股,邏輯地址
/var/mail
ln
ln -在文件之間建立連接
[root@localhost ~]# ln -s /home/zhangy/heartbeat ./ #在當(dāng)前目錄下墅茉,建立heartbeat的軟連接
[root@localhost ~]# ln -s /home/zhangy/test ./ #建立目錄的軟件接
[root@localhost ~]# ln /home/zhangy/tee.txt ./ #建立硬連接
[root@localhost ~]# ll ll是ls的別名相當(dāng)于等同于 (ls -l --color=tty)
lrwxrwxrwx 1 root root 22 05-11 11:04 heartbeat -> /home/zhangy/heartbeat #文件軟件接
-rw-r--r-- 2 root root 0 2010-11-24 tee.txt #文件硬連接
lrwxrwxrwx 1 root root 17 05-11 11:04 test -> /home/zhangy/test #目錄軟件接```
nl
nl命令在linux系統(tǒng)中用來計(jì)算文件中行號(hào)。nl 可以將輸出的文件內(nèi)容自動(dòng)的加上行號(hào)呜呐!其默認(rèn)的結(jié)果與 cat -n 有點(diǎn)不太一樣就斤, nl 可以將行號(hào)做比較多的顯示設(shè)計(jì),包括位數(shù)與是否自動(dòng)補(bǔ)齊 0 等等的功能蘑辑。
1.命令格式:
nl [選項(xiàng)]... [文件]...
[root@localhost ~]#nl log2012.log #用 nl 列出 log2012.log 的內(nèi)容
[root@localhost ~]#nl -b a log2012.log #用 nl 列出 log2012.log 的內(nèi)容洋机,空本行也加上行號(hào)
1 2012-01
2 2012-02
3
4
[root@localhost ~]#nl -b a -n rz log2014.log #讓行號(hào)前面自動(dòng)補(bǔ)上0,統(tǒng)一輸出格式
000001 2014-01
000002 2014-02
000003 2014-03
000004 2014-04
000005 2014-05
000006 2014-06
### dd
>dd - 轉(zhuǎn)換和拷貝文件
[root@localhost ~]# dd if=/dev/hdx of=/dev/hdy #將本地的/dev/hdx整盤備份到/dev/hdy
[root@localhost ~]# dd if=/dev/hdx of=/path/to/image #將/dev/hdx全盤數(shù)據(jù)備份到指定路徑的image文件
[root@localhost ~]# dd if=/dev/hdx | gzip >/path/to/image.gz #備份/dev/hdx全盤數(shù)據(jù),并利用gzip工具進(jìn)行壓縮洋魂,保存到指定路徑
[root@localhost ~]# dd if=/path/to/image of=/dev/hdx # 將備份文件恢復(fù)到指定盤
[root@localhost ~]# gzip -dc /path/to/image.gz | dd of=/dev/hdx #將壓縮的備份文件恢復(fù)到指定盤
[root@localhost ~]# dd if=/dev/hdx of=/path/to/image count=1 bs=512 #備份磁盤開始的512Byte大小的MBR信息到指定文件
[root@localhost ~]# dd if=/dev/cdrom of=/root/cd.iso #拷貝光盤數(shù)據(jù)到root文件夾下绷旗,并保存為cd.iso文件
1.將本地的/dev/hdb整盤備份到/dev/hdd
[root@localhost ~]# dd if=/dev/hdb of=/dev/hdd
2.將/dev/hdb全盤數(shù)據(jù)備份到指定路徑的image文件
[root@localhost ~]# dd if=/dev/hdb of=/root/image
3.將備份文件恢復(fù)到指定盤
[root@localhost ~]# dd if=/root/image of=/dev/hdb
4.備份/dev/hdb全盤數(shù)據(jù)喜鼓,并利用gzip工具進(jìn)行壓縮,保存到指定路徑
[root@localhost ~]# dd if=/dev/hdb | gzip > /root/image.gz
5.將壓縮的備份文件恢復(fù)到指定盤
[root@localhost ~]# gzip -dc /root/image.gz | dd of=/dev/hdb
6.備份與恢復(fù)MBR
備份磁盤開始的512個(gè)字節(jié)大小的MBR信息到指定文件:
[root@localhost ~]# dd if=/dev/hda of=/root/image count=1 bs=512
count=1指僅拷貝一個(gè)塊衔肢;bs=512指塊大小為512個(gè)字節(jié)庄岖。
恢復(fù):
[root@localhost ~]# dd if=/root/image of=/dev/had
將備份的MBR信息寫到磁盤開始部分
7.備份軟盤
[root@localhost ~]# dd if=/dev/fd0 of=disk.img count=1 bs=1440k (即塊大小為1.44M)
8.拷貝內(nèi)存內(nèi)容到硬盤
[root@localhost ~]# dd if=/dev/mem of=/root/mem.bin bs=1024 (指定塊大小為1k)
9.拷貝光盤內(nèi)容到指定文件夾,并保存為cd.iso文件
[root@localhost ~]# dd if=/dev/cdrom(hdc) of=/root/cd.iso
10.增加swap分區(qū)文件大小
第一步:創(chuàng)建一個(gè)大小為256M的文件:
[root@localhost ~]# dd if=/dev/zero of=/swapfile bs=1024 count=262144
第二步:把這個(gè)文件變成swap文件:
[root@localhost ~]# mkswap /swapfile
第三步:啟用這個(gè)swap文件:
[root@localhost ~]# swapon /swapfile
第四步:編輯/etc/fstab文件角骤,使在每次開機(jī)時(shí)自動(dòng)加載swap文件:
/swapfile swap swap default 0 0
11.銷毀磁盤數(shù)據(jù)
[root@localhost ~]# dd if=/dev/urandom of=/dev/hda1
注意:利用隨機(jī)的數(shù)據(jù)填充硬盤隅忿,在某些必要的場合可以用來銷毀數(shù)據(jù)。
12.測試硬盤的讀寫速度
[root@localhost ~]# dd if=/dev/zero bs=1024 count=1000000 of=/root/1Gb.file
[root@localhost ~]# dd if=/root/1Gb.file bs=64k | dd of=/dev/null
通過以上兩個(gè)命令輸出的命令執(zhí)行時(shí)間邦尊,可以計(jì)算出硬盤的讀背桐、寫速度。
13.確定硬盤的最佳塊大胁踝帷:
[root@localhost ~]# dd if=/dev/zero bs=1024 count=1000000 of=/root/1Gb.file
[root@localhost ~]# dd if=/dev/zero bs=2048 count=500000 of=/root/1Gb.file
[root@localhost ~]# dd if=/dev/zero bs=4096 count=250000 of=/root/1Gb.file
[root@localhost ~]# dd if=/dev/zero bs=8192 count=125000 of=/root/1Gb.file
通過比較以上命令輸出中所顯示的命令執(zhí)行時(shí)間链峭,即可確定系統(tǒng)最佳的塊大小。
14.修復(fù)硬盤:
[root@localhost ~]# dd if=/dev/sda of=/dev/sda 或dd if=/dev/hda of=/dev/hda
當(dāng)硬盤較長時(shí)間(一年以上)放置不使用后又沾,磁盤上會(huì)產(chǎn)生magnetic flux point熏版,當(dāng)磁頭讀到這些區(qū)域時(shí)會(huì)遇到困難,并可能導(dǎo)致I/O錯(cuò)誤捍掺。
當(dāng)這種情況影響到硬盤的第一個(gè)扇區(qū)時(shí)撼短,可能導(dǎo)致硬盤報(bào)廢。上邊的命令有可能使這些數(shù) 據(jù)起死回生挺勿。并且這個(gè)過程是安全曲横、高效的。
1不瓶、測試磁盤寫能力
[root@localhost ~]# time dd if=/dev/zero of=/test.dbf bs=8k count=300000
因?yàn)?dev/zero是一個(gè)偽設(shè)備禾嫉,它只產(chǎn)生空字符流,對(duì)它不會(huì)產(chǎn)生IO蚊丐,所以熙参,
IO都會(huì)集中在of文件中,of文件只用于寫麦备,所以這個(gè)命令相當(dāng)于測試磁盤的寫能力孽椰。
2、測試磁盤讀能力
[root@localhost ~]# time dd if=/dev/sdb1 of=/dev/null bs=8k
因?yàn)?dev/sdb1是一個(gè)物理分區(qū)凛篙,對(duì)它的讀取會(huì)產(chǎn)生IO黍匾,/dev/null是偽設(shè)備,相當(dāng)于黑洞呛梆,of到該設(shè)備不會(huì)產(chǎn)生IO锐涯,
所以,這個(gè)命令的IO只發(fā)生在/dev/sdb1上填物,也相當(dāng)于測試磁盤的讀能力纹腌。
3霎终、測試同時(shí)讀寫能力
[root@localhost ~]# time dd if=/dev/sdb1 of=/test1.dbf bs=8k
這個(gè)命令下,一個(gè)是物理分區(qū)升薯,一個(gè)是實(shí)際的文件莱褒,對(duì)它們的讀寫都會(huì)產(chǎn)生IO(對(duì)/dev/sdb1是讀,對(duì)/test1.dbf是寫)覆劈,
假設(shè)他們都在一個(gè)磁盤中,這個(gè)命令就相當(dāng)于測試磁盤的同時(shí)讀寫能力
### basename
>用法:basename 名稱 [后綴]
或:basename 選項(xiàng)
去掉前導(dǎo)的目錄部分后打印“名稱”沛励。
如果指定的話责语,還會(huì)去掉尾隨的“后綴”
[root@localhost ~]# basename /etc/php.ini
php.ini
[root@localhost ~]# basename /etc/nginx/
nginx
[root@localhost ~]# bashname include/stdio.h .h
stdio
### dirname
>顯示指定路徑除了文件名之外的路徑前綴
[root@localhost ~]# dirname /home/tank/test.bz2
/home/tank
### head
>用法:head [選項(xiàng)]... [文件]...
將每個(gè)指定文件的頭10 行顯示到標(biāo)準(zhǔn)輸出。
如果指定了多于一個(gè)文件目派,在每一段輸出前會(huì)給出文件名作為文件頭坤候。
如果不指定文件,或者文件為"-"企蹭,則從標(biāo)準(zhǔn)輸入讀取數(shù)據(jù)
[root@localhost ~]#head /etc/passwd #默認(rèn)白筹,顯示開頭前10行
[root@localhost ~]#head -k /etc/passwd #顯示開頭前k行
[root@localhost ~]# head -q -n k file1 file2 file3 #顯示多文件開頭前k行,并且不顯示文件名的文件頭
[root@localhost ~]# head -n -k /etc/passwd #除最后k行外谅摄,顯示剩余全部內(nèi)容徒河。
[root@localhost ~]# head -n 5 /etc/passwd #顯示前5行
[root@localhost ~]# head -n -5 /etc/passwd #顯示從0到倒數(shù)第5行
[root@localhost ~]# head -c 100 /etc/passwd #顯示前100字符
[root@localhost ~]# head -c -100 /etc/passwd #顯示從0到倒數(shù)第100字符
### tail
>tail - 輸出文件的末尾部分
[root@localhost ~]#tail /etc/passwd #默認(rèn),顯示最后10 行送漠。
[root@localhost ~]#tail -n 2 /etc/passwd #顯示最后2行
[root@localhost ~]#tail -q -n k file1 file2 file3 #顯示多文件最后k行顽照,并且不顯示文件名的文件頭
[root@localhost ~]#tail -n +k /etc/passwd #從開頭第k行處開始輸出。
[root@localhost ~]#tail -f /var/log/messages #參數(shù)-f使tail不停地去讀最新的內(nèi)容闽寡,因此有實(shí)時(shí)監(jiān)視的效果代兵,用Ctrl+c來終止
[root@localhost ~]# tail -n+10 file.txt | head -1 #顯示file.txt的第10行
以cat 1.txt 為例
[root@localhost ~]#cat 1.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[root@localhost ~]#tail 1.txt
11
12
13
14
15
16
17
18
19
20
[root@localhost ~]#tail -3 1.txt
18
19
20
[root@localhost ~]#tail -n 3 1.txt
18
19
20
[root@localhost ~]# tail --lines=3 1.txt
18
19
20
[root@localhost ~]# tail -n +14 1.txt
14
15
16
17
18
19
20
### mknod
>用法:mknod [選項(xiàng)]... 名稱 類型 [主設(shè)備號(hào) 次設(shè)備號(hào)]
創(chuàng)建指定類型和名稱的特殊文件
將其中的1,3這樣的數(shù)字記錄下來,這表示主設(shè)備號(hào)和次設(shè)備號(hào)(一般來說主設(shè)備號(hào)用來區(qū)分設(shè)備的種類爷狈;次設(shè)備號(hào)則是為了作唯一性區(qū)分植影,標(biāo)明不同屬性——注意,在unix系統(tǒng)中是把設(shè)備也當(dāng)作文件來對(duì)待的)涎永,在redhat 9下思币,ls加不加-L參數(shù)都無所謂,但是在Solaris下則一定要加上才可以顯示
[root@localhost ~]#ls -lL /dev/null
crw-rw-rw- 1 root root 1, 3 8月 18 21:56 /dev/null
[root@localhost ~]# mknod /dev/hda3 b 3 7 #創(chuàng)建一個(gè)區(qū)塊
[root@localhost ~]# ls -al /dev/hda3 #查看
brw-r--r-- 1 root root 3, 7 8月 21 11:01 /dev/hda3
### rev
>rev 顯示最后一個(gè)字符顯示到第一個(gè)字符
[root@localhost ~]# cat test
1234
abcd
[root@localhost ~]# rev test
4321
dcba
[root@localhost ~]# tac test
abcd
1234
### file
>確定文件類型
[root@localhost ~]# file * #查看當(dāng)前目錄下的所有文件類型
abc.sh: awk script, ASCII text
abc.sh.bz2: bzip2 compressed data, block size = 900k
ar_test: directory
examples.desktop: UTF-8 Unicode text
rec00001abc.sh.bz2: bzip2 compressed data, block size = 900k
test: ASCII text
test.bz2: bzip2 compressed data, block size = 900k
[root@localhost ~]# file abc.sh #查看單個(gè)文件的文件類型
abc.sh: awk script, ASCII text
[root@localhost ~]# file -z test.bz2 #查看壓縮文件的內(nèi)部信息
test.bz2: empty (bzip2 compressed data, block size = 900k)
### find
- find 查找目錄和文件
find 路徑 -命令參數(shù) [輸出形式]
通過名字來查找
[root@localhost ~]# find ~ -name memcached.pid -print #查找home目錄下文件名為memcache.pid的文件
/home/zhangy/memcached/memcached.pid
[root@localhost ~]#find . -name "*.pid" -print #.代表當(dāng)前目錄羡微,查找所有以pid結(jié)尾的文件
./memcached/memcached.pid
./.tencent/qq/95219454.pid
[root@localhost ~]# find ~ -name "[0-9].pid" -print #查找以數(shù)字開頭的所有pid文件支救,在這里要說[0-9]不能匹配23,它跟一般的語言類正則不太一樣拷淘,shell里面的*可以代表一切字符(單個(gè)各墨,多個(gè)都行),如果想匹配2345只能這樣寫[0-9][0-9][0-9][0-9]
/home/zhangy/.tencent/qq/95219454.pid
[root@localhost ~]#find /home/zhangy/.tencent/ -name "[0-9]*.pid" -print #在.tencent文件夾下面找pid文件
/home/zhangy/.tencent/qq/95219454.pid
通過文件權(quán)限來查找
[root@localhost ~]# find ~ -perm 755 -print |more #~代表的是$home目錄启涯,查找權(quán)限為755的文件
/home/zhangy/www/css2/c_textshadow.html
/home/zhangy/www/css2/c_textautospace.html
[root@localhost ~]#find . -perm 700 -name "u_*" -print |more #查找所有以產(chǎn)u_開頭的贬堵,并且權(quán)限為700的文件
./css2/u_length_cm.html
./css2/u_length_px.html
prune來忽略目錄來查找
[root@localhost ~]#find . -name "*.gz" -prune -o ( ! -name aaa ) -print #查找在前目錄中恃轩,不在以aaa結(jié)尾的目錄中的,不以gz結(jié)尾的文件
.
./eaccelerator-0.9.5.3.tar
./fix-crash-in-excerpts.patch
./AddFeed_Widget_WordPress_Plugin.zip
./jQuery china-addthis plugin 1.07.rar
根據(jù)文件類型來查找文件
[root@localhost ~]#find . -type d -print #查找當(dāng)前目錄下面的目錄
.
./ddd
[root@localhost ~]#find . ! -type d -print #找當(dāng)前目錄下面的非目錄文件
./eaccelerator-0.9.5.3.tar
./haproxy-1.3.15.7.tar.gz
./fix-crash-in-excerpts.patch
根據(jù)文件所屬用戶和用戶組來找文件
[root@localhost ~]#find . -nouser -print #查找當(dāng)前目錄中黎做,沒有歸屬的文件
[root@localhost ~]#find /home/zhangy/download -user zhangy -group users -print #查找用戶組為users叉跛,所屬用戶為zhangy的文件
/home/zhangy/download
/home/zhangy/download/eaccelerator-0.9.5.3.tar
/home/zhangy/download/haproxy-1.3.15.7.tar.gz
根文件大小來查找
[root@localhost ~]#find /home/zhangy/download -size +1000000c -print #查找文件大小大于1000000字符的文件,注意+號(hào)表示大于
/home/zhangy/download/eaccelerator-0.9.5.3.tar
/home/zhangy/download/mmseg-0.7.3.tar.gz
[root@localhost ~]#find /home/zhangy/download -size -10 -print #查找文件大小小于10塊的文件蒸殿,注意-號(hào)表示小于筷厘,一塊等于512b
/home/zhangy/download
/home/zhangy/download/fix-crash-in-excerpts.patch
/home/zhangy/download/test.sql.zip
根文件的修改時(shí)間來查找
[root@localhost ~]#find /home/zhangy -mtime -5 -print #5天修改過的文件,- 表示以內(nèi)
/home/zhangy/www/css2/c_textshadow.html
/home/zhangy/www/css2/c_textautospace.html
[root@localhost ~]#find /home/zhangy -mtime +5 -print #查找5天前修改過的文件宏所,+表示以前
/home/zhangy/www/test.php
[root@localhost ~]# find ./ -mmin -5 -print #查找5分鐘以內(nèi)修改過的文件
./cache/index.html
exec解釋
[root@localhost ~]#find . -type f -size +1000000c -exec ls -al {} ; #顯示當(dāng)前目錄下面所有大于1000000的文件酥艳,exec后面執(zhí)行了一個(gè)命令,{}這個(gè)代表文件名
-rw-r--r-- 1 zhangy users 3624960 2009-03-08 ./eaccelerator-0.9.5.3.tar
-rw-r--r-- 1 zhangy users 3091711 12-18 13:48 ./mmseg-0.7.3.tar.gz
-rw-r--r-- 1 zhangy users 1191330 2009-06-26 ./pcre-7.9.tar.gz
匹配
[root@localhost ~]#find ./database/ -name '*.sql' -print #查找以sql結(jié)尾的文件
./database/28toplearning.sql
[root@localhost ~]#find ./database/ -name '.sql' -print #查找文件名包括sql文件
./database/28toplearning.sql
[root@localhost ~]#find ./database/ -name '28*' -print #查找以28開頭的文件
./database/28toplearning.sql
### head
>用法:head [選項(xiàng)]... [文件]...
將每個(gè)指定文件的頭10 行顯示到標(biāo)準(zhǔn)輸出爬骤。
如果指定了多于一個(gè)文件充石,在每一段輸出前會(huì)給出文件名作為文件頭。
如果不指定文件霞玄,或者文件為"-"骤铃,則從標(biāo)準(zhǔn)輸入讀取數(shù)據(jù)
[root@localhost ~]#head /etc/passwd #默認(rèn),顯示開頭前10行
[root@localhost ~]# head -k /etc/passwd #顯示開頭前k行
[root@localhost ~]#head -q -n k file1 file2 file3 #顯示多文件開頭前k行坷剧,并且不顯示文件名的文件頭
[root@localhost ~]#head -n -k /etc/passwd #除最后k行外惰爬,顯示剩余全部內(nèi)容。
[root@localhost ~]# head -n 5 /etc/passwd #顯示前5行
[root@localhost ~]# head -n -5 /etc/passwd #顯示從0到倒數(shù)第5行
[root@localhost ~]# head -c 100 /etc/passwd #顯示前100字符
[root@localhost ~]# head -c -100 /etc/passwd #顯示從0到倒數(shù)第100字符
### locate
>用法: locate [OPTION]... [PATTERN]...
在mlocate數(shù)據(jù)庫中搜索條目
[root@localhost ~]# locate ~/install #查找當(dāng)前目錄下以install開頭的文件
/root/install.log
/root/install.log.syslog
[root@localhost ~]# locate -i ~/install #查找當(dāng)前目錄下以install開頭的文件惫企,不區(qū)分大小寫
/root/install.log
/root/install.log.syslog
[root@localhost ~]# locate -i /etc/fuc #查找/etc目錄下面以fuc開頭的文件补鼻,不區(qū)分大小寫
### less
>less 與more命令類似,但可以通過翻頁鍵查看上下頁的內(nèi)容
-b<緩沖區(qū)大小> 設(shè)置緩沖區(qū)的大小
-e 當(dāng)文件顯示結(jié)束后雅任,自動(dòng)離開
-f 強(qiáng)迫打開特殊文件风范,例如外圍設(shè)備代號(hào)、目錄和二進(jìn)制文件
-g 只標(biāo)志最后搜索的關(guān)鍵詞
-i 忽略搜索時(shí)的大小寫
-m 顯示類似more命令的百分比
-N 顯示每行的行號(hào)
-o<文件名> 將less 輸出的內(nèi)容在指定文件中保存起來
-Q 不使用警告音
-s 顯示連續(xù)空行為一行
-S 行過長時(shí)間將超出部分舍棄
-x<數(shù)字> 將“tab”鍵顯示為規(guī)定的數(shù)字空格
命令內(nèi)部操作
按鍵功能如下:
b 向后翻一頁
d 向后翻半頁
h 顯示幫助界面
Q 退出less 命令
u 向前滾動(dòng)半頁
y 向前滾動(dòng)一行
空格鍵 滾動(dòng)一頁
回車鍵 滾動(dòng)一行
1) 向前搜索
/ : 使用一個(gè)模式進(jìn)行搜索沪么,并定位到下一個(gè)匹配的文本
n : 向前查找下一個(gè)匹配的文本
N : 向后查找前一個(gè)匹配的文本
2) 向后搜索
? : 使用模式進(jìn)行搜索硼婿,并定位到前一個(gè)匹配的文本
n : 向后查找下一個(gè)匹配的文本
N : 向前查找前一個(gè)匹配的文本
2 全屏導(dǎo)航
ctrl + F :向前移動(dòng)一屏
ctrl + B :向后移動(dòng)一屏
ctrl + D :向前移動(dòng)半屏
ctrl + U :向后移動(dòng)半屏
3 單行導(dǎo)航
j : 向前移動(dòng)一行
k : 向后移動(dòng)一行
4 其它導(dǎo)航
G : 移動(dòng)到最后一行
g : 移動(dòng)到第一行
q / ZZ : 退出 less 命令
5 編輯文件
v : 進(jìn)入編輯模式,使用配置的編輯器編輯當(dāng)前文件
6 標(biāo)記導(dǎo)航
當(dāng)使用 less 查看大文件時(shí)禽车,可以在任何一個(gè)位置作標(biāo)記寇漫,可以通過命令導(dǎo)航到標(biāo)有特定標(biāo)記的文本位置。
ma : 使用 a 標(biāo)記文本的當(dāng)前位置
'a : 導(dǎo)航到標(biāo)記 a 處
7 瀏覽多個(gè)文件
方式一殉摔,傳遞多個(gè)參數(shù)給 less州胳,就能瀏覽多個(gè)文件。
less file1 file2
方式二逸月,正在瀏覽一個(gè)文件時(shí)栓撞,使用 :e 打開另一個(gè)文件。
less file1
:e file2
當(dāng)打開多個(gè)文件時(shí),使用如下命令在多個(gè)文件之間切換
:n - 瀏覽下一個(gè)文件
:p - 瀏覽前一個(gè)文件
[root@localhost ~]# less test.php #查看文件
[root@localhost ~]# netstat -tpnl |less #常用方式瓤湘,分頁顯示
### more
more- 在顯示器上閱讀文件的過濾器[[ ]]
總覽 (SYNOPSIS)
more[-dlfpcsu] [-num] [+/ pattern] [+ linenum] [file ...][[ ]]
描述 (DESCRIPTION)
More是 一個(gè) 過濾器, 用于 分頁 顯示 (一次一屏) 文本. 這個(gè) 版本 非常 基本. 用戶 應(yīng)該 知道 less(1) 提供了 more(1) 的 模擬, 并且 做了 增強(qiáng).[[ ]]
選項(xiàng) (OPTION)
下面 介紹 命令行選項(xiàng). 選項(xiàng) 可以 從 環(huán)境變量MORE中獲取 (要 確保 它們 以 短橫線 開頭 (``-)), 但是 命令行選項(xiàng) 能夠 覆蓋 它們.
-num
這個(gè)選項(xiàng)指定屏幕的行數(shù) (以整數(shù)表示).
-d
讓 more 給 用戶 顯示 提示信息 "[Press space to continue, 'q' to quit.]", 當(dāng) 用戶 按下 其他鍵 時(shí), 顯示 "[Press 'h' for instructions.]", 而不是 揚(yáng)聲器 鳴笛.
-l
More 在 通常情況下 把 ^L (form feed) 當(dāng)做 特殊字符, 遇到 這個(gè)字符 就會(huì) 暫停. -l 選項(xiàng) 可以 阻止 這種特性.
-f
使 more 計(jì)數(shù) 邏輯行, 而不是 屏幕行 (就是說, 長行 不會(huì) 斷到 下一行).
-p
不卷屏, 而是 清除 整個(gè)屏幕, 然后 顯示 文本.
-c
不卷屏, 而是 從 每一屏的 頂部 開始 顯示 文本, 每 顯示完 一行, 就 清除 這一行的 剩余部分.
-s
把 重復(fù)的空行 壓縮成 一個(gè) 空行.
-u
防止下劃線.
+/
在 顯示 每個(gè)文件 前, 搜索 +/ 選項(xiàng) 指定的 文本串.
+num
從行號(hào) num 開始顯示.
[[ ]]
命令 (COMMAND)
more的交互命令基于 vi(1). 有些命令 以 一個(gè) 十進(jìn)制數(shù)字 開始, 在 下面的描述 里 稱之為 k. 后面的 描述中, ^X 指 control-X.
h or ?
幫助: 顯示 這些 命令 的 摘要. 你 如果 忘掉 所有 其他的命令, 請(qǐng)記住這個(gè).
SPACE
顯示 接下來的 k 行文本. 缺省值 是 當(dāng)前的屏幕大小.
z
顯示 接下來的 k 行文本. 缺省值 是 當(dāng)前的屏幕大小. 參數(shù) 成為 新的缺省值.
RETURN
顯示 接下來的 k 行文本. 缺省值 是 1. 參數(shù) 成為 新的缺省值.
d or ^D
卷屏 k 行. 缺省值 是 當(dāng)前的 卷屏大小, 初始化為 11. 參數(shù) 成為 新的缺省值.
q 或 Q 或 INTERRUPT
退出.
s
向前跳過 k 行文本. 缺省值 是 1.
f
向前跳過 k 屏文本. 缺省值 是 1.
b or ^B
向后跳回 k 屏文本. 缺省值 是 1.
跳到 上一次 搜索 開始 的 地方.
顯示當(dāng)前行號(hào).
/ pattern
搜索 第 k 個(gè) 符合 正則表達(dá)式的 文本串. 缺省值 是 1.
n
搜索 最后 第 k 個(gè) 符合 正則表達(dá)式的 文本串. 缺省值 是 1.
! or :!
在子 shell 中執(zhí)行 .
v
啟動(dòng) /usr/bin/vi, 指向 當(dāng)前行.
^L
刷新屏幕.
:n
跳到 后面 第 k 個(gè) 文件. 缺省值 是 1.
:p
跳到 前面 第 k 個(gè) 文件. 缺省值 是 1.
:f
顯示 當(dāng)前文件名 和 行號(hào).
.
重復(fù)上次命令.
[[ ]]
環(huán)境 (ENVIRONMENT)
More利用 下面的 環(huán)境變量 (如果 它們 存在):
MORE
這個(gè)變量 設(shè)置 你 喜歡的 more 選項(xiàng).
SHELL
當(dāng)前使用的 shell (一般說來 就是 登錄 shell).
TERM
指定 終端類型, more 用它來 獲取 操作屏幕 所需的 終端特性
[root@localhost ~]#more test.php #查看文件
[root@localhost ~]#netstat -tpnl |more #常用方式瓢颅,分頁顯示
### shred
>用法:shred [選項(xiàng)]... 文件...
多次覆蓋文件,使得即使是昂貴的硬件探測儀器也難以將數(shù)據(jù)復(fù)原弛说。
[root@localhost ~]#shred test.sh #粉碎文件
[root@localhost ~]# shred -u test.sh #粉碎文件挽懦,并刪除
### tar
> tar 命令:用來壓縮和解壓文件。tar本身不具有壓縮功能木人。他是調(diào)用壓縮功能實(shí)現(xiàn)的
[root@localhost ~]# tar -czvf ar_test.tar.gz ar_test #將ar_test文件打包并且壓縮
[root@localhost ~]# tar zxvf ar_test.tar.gz #解壓
[root@localhost ~]# tar -tf ar_test.tar.gz #查看包里面的文件信息
[root@localhost ~]# tar -cf all.tar *.jpg #將當(dāng)前目錄所有.jpg的文件打成一個(gè)名為all.tar的包信柿。-c是表示產(chǎn)生新的包,-f指定包的文件名
[root@localhost ~]# tar -rf all.tar *.gif #將所有.gif的文件增加到all.tar的包里面去醒第。-r是表示增加文件的意思渔嚷。
[root@localhost ~]# tar -uf all.tar logo.gif #更新原來tar包all.tar中l(wèi)ogo.gif文件,-u是表示更新文件的意思
[root@localhost ~]# tar -xf all.tar #解出all.tar包中所有文件淘讥,-x是解開的意思
[root@localhost ~]# tar -cjf all.tar.bz2 *.jpg #壓縮成.bz2的壓縮文件
[root@localhost ~]# tar -xjf all.tar.bz2 #解壓.bz2的文件
[root@localhost ~]# tar -cZf all.tar.Z *.jpg #壓縮成.Z的壓縮文件
[root@localhost ~]# tar -xZf all.tar.Z #解壓.Z的文件
[root@localhost ~]# tar -czvf test.tar.gz test --exclude test/not #不包括test下的not目錄
### xz
>xz命令是壓縮圃伶,解壓縮.xz后綴的文件
用法:
xz [OPTION]... [FILE]...
[root@localhost ~]# xz -z aaa.txt //壓縮堤如,并刪除原文件
[root@localhost ~]# xz -zk aaa.txt //壓縮但不刪除原文件
[root@localhost ~]# xz -d aaa.txt.xz //解壓
### zcat
>zcat 查看壓縮的文件
[root@localhost ~]#tar czvf aaa.tar.gz aaa.txt #壓縮
aaa.txt
[root@localhost ~]#zcat aaa.tar.gz #查看
aaa.txt0000664000076400007650000000001112154736511011733 0ustar zhangyzhangyaaa
bbb
### split
>將指定的文件切割小的文件
[root@localhost ~]#split -d -b 4m google.tar.gz #將文件分割成蒲列,4M的小塊,并用數(shù)字代替字母
[root@localhost ~]#split -l 300 b.txt #分割文件 取文件前300行開始分割
[root@localhost ~]#cat x* > google_bak.tar.gz #合并文件
[root@localhost ~]#split -b 20m RevolutionOS.rmvb RevOS_part_
[root@localhost ~]#ls -lh
-rwx------ 1 hoho hoho 276M 2005-09-09 RevolutionOS.rmvb
-rw-r--r-- 1 root root 20M 03-19 17:59 RevOS_part_aa
-rw-r--r-- 1 root root 20M 03-19 17:59 RevOS_part_ab
.............
-rw-r--r-- 1 root root 20M 03-19 18:00 RevOS_part_am
-rw-r--r-- 1 root root 16M 03-19 18:00 RevOS_part_an
[root@localhost ~]#split -l 200 test.txt test_part #每200行生成一個(gè)文件
### bzcat
[root@localhost ~]# bzcat -9 abc.sh.bz2
BEGIN {
FS="to"
count=0
}
{
printf("%s,%s\n",2)
split(2,parts2,"-")
mystr=sprintf("%4d%2d%2d %4d%2d%2d",parts1[1],parts1[2],parts1[3],parts2[1],parts2[2],parts2[3])
count+=gsub(" ","0",mystr)
print mystr
}
END{
print count/2
}
### bzip2
>bzip2, bunzip2 - 一種塊排序文件壓縮軟件搀罢,v0.9.5
bzcat - 將文件解壓縮至標(biāo)準(zhǔn)輸出
bzip2recover - 恢復(fù)損壞的 bzip2 文件
例,壓縮
[root@localhost ~]# bzip2 -z abc.sh #壓縮
[root@localhost ~]# bzip2 -kv abc.sh #壓縮原文保留
abc.sh: 1.220:1, 6.557 bits/byte, 18.04% saved, 255 in, 209 out.
[root@localhost ~]# bzip2 -9 -c abc.sh >abc.bz2 #壓縮原文保留
例,解壓
[root@localhost ~]# bzip2 -dv abc.sh.bz2
abc.sh.bz2: done
[root@localhost ~]# bzip2 -tv test.bz2 # 模擬解壓
[root@localhost ~]# bzip2 -k test # 生成新文件蝗岖,原文件也保留
[root@localhost ~]# bzip2 -dc test.bz2 # 解壓到標(biāo)準(zhǔn)輸出
### bzcat
[root@localhost ~]# bzcat -9 abc.sh.bz2
BEGIN {
FS="to"
count=0
}
{
printf("%s,%s\n",2)
split(2,parts2,"-")
mystr=sprintf("%4d%2d%2d %4d%2d%2d",parts1[1],parts1[2],parts1[3],parts2[1],parts2[2],parts2[3])
count+=gsub(" ","0",mystr)
print mystr
}
END{
print count/2
}
### cpio
>存取歸檔包中的文件
[root@localhost ~]#ls|cpio -o > /home/zhangy/test.cpio #備份當(dāng)前目錄下的文件
31 blocks
[root@localhost ~]#cpio -i < /home/zhangy/test.cpio #導(dǎo)入以前的備份文件
找出當(dāng)前目錄下的所有文件,然后將它們打包進(jìn)一個(gè)cpio壓縮包文件
[root@localhost ~]# find . -depth | cpio -ocvB > backup.cpio 或 find .-depth-print | cpio -ocvB > backup.cpio
將當(dāng)前目錄下名為inittab文件加入initrd.cpio包中
[root@localhost ~]# find . -name inittab -depth | cpio -ovcB -A -F initrd.cpio
[root@localhost ~]#find . -name inittab -depth | cpio -ovcB -A -O initrd.cpio
[root@localhost ~]#find . -name inittab -depth | cpio -ovcB -A --quiet -O initrd.cpio
[root@localhost ~]# cpio --absolute-filenames -vtc < boot.cpio #不忽略文件列表清單的文件名最前面的“/"
[root@localhost ~]# cpio --no-absolute-filenames -vtc < boot.cpio #默認(rèn)是忽略文件列表清單的文件中最前面的
[root@localhost ~]#cpio --absolute-filenames -icvu < test.cpio #解壓到原始位置榔至,解壓出來的每個(gè)文件的時(shí)間屬性改為當(dāng)前時(shí)間
[root@localhost ~]#cpio --absolute-filenames -icvum < test.cpio #解壓到原始位置抵赢,同時(shí)不改變解壓出來的每個(gè)文件的時(shí)間屬性
[root@localhost ~]#cpio -icvu < test.cpio # 解壓到當(dāng)前目錄下
[root@localhost ~]#cpio -icvdu -r < grub.cpio #在解包c(diǎn)pio時(shí),對(duì)解包出來的文件進(jìn)行交互的更名
[root@localhost ~]#cpio -icvu --to-stdout < grub.cpio #將cpio包中的文件解壓并輸入標(biāo)準(zhǔn)輸出
[root@localhost ~]#find . -depth| cpio -R ruanxi:ruanxi -pL /backup/ #復(fù)制文件并更改文件的屬主與屬組
### uncompress
> 用來解壓.Z文件
-c 輸出結(jié)果到標(biāo)準(zhǔn)輸出
-f 強(qiáng)制執(zhí)行
-v 顯示詳細(xì)的處理信息
-V 版本信息
[root@localhost ~]# uncompress test.Z #解壓test.Z
### chattr
>chattr 修改文件在Linux第二擴(kuò)展文件系統(tǒng)(E2fs)上的特有屬性
[root@localhost ~]# chattr +i nginx.conf #設(shè)置該文件不能進(jìn)行任何形勢的修改
[root@localhost ~]# mv nginx.conf nginx.conf_bak
mv: 無法將"nginx.conf" 移動(dòng)至"nginx.conf_bak": 不允許的操作
[root@localhost ~]# lsattr nginx.conf #查看chattr設(shè)置的權(quán)限
----i--------e- nginx.conf
[root@localhost ~]# chattr -i nginx.conf #取消-i的權(quán)限設(shè)置
[root@localhost ~]# lsattr nginx.conf #查看chattr設(shè)置的權(quán)限
-------------e- nginx.conf
###getfacl
>getfacl 2.2.51 -- 獲取文件訪問控制列表
[root@localhost ~]# getfacl test #查看acl權(quán)限列表
file: test
owner: root
group: root
user::r-x
user:tank:rwx #effective:---
group::r-x #effective:---
mask::---
other::---
[root@localhost ~]# getfacl -c test #查看acl權(quán)限唧取,省略頭信息
user::r-x
user:tank:rwx #effective:---
group::r-x #effective:---
mask::---
other::---
###setfacl
>設(shè)定文件訪問控制列表
[root@localhost ~]# getfacl test
file: test
owner: root
group: root
user::r-x
user:tank:rwx #effective:---
group::r-x #effective:---
mask::---
other::---
[root@localhost ~]# setfacl -m u:zhangy:rw- test #修改文件的acl權(quán)限铅鲤,添加一個(gè)用戶權(quán)限
[root@localhost ~]# getfacl test
file: test
owner: root
group: root
user::r-x
user:zhangy:rw- #多出來一個(gè)用戶
user:tank:rwx
group::r-x
mask::rwx
other::---
[root@localhost ~]# setfacl -m g:zhangying:r-w test #添加一個(gè)組
[root@localhost ~]# getfacl test
file: test
owner: root
group: root
user::r-x
user:zhangy:rw-
user:tank:rwx
group::r-x
group:zhangying:rw-
mask::rwx
other::--