Shell-3-檔案之名,

來源:互聯網
上載者:User

Shell-3-檔案之名,
1.產生任意大小的檔案

[root@localhost tmp]# dd if=/dev/zero of=junk.data bs=1M count=1

記錄了1+0 的讀入

記錄了1+0 的寫出

1048576位元組(1.0 MB)已複製,0.00219263 秒,478 MB/秒

if代表輸入檔案,of代表輸出檔案,bs大小,count表示塊數

 

[root@localhost tmp]# dd if=/dev/zero of=junk.data bs=1M count=2

 

記錄了2+0 的讀入

記錄了2+0 的寫出

2097152位元組(2.1 MB)已複製,0.00375177 秒,559 MB/秒

 

 

 

單元大小

代碼

位元組(1B)

c

字(2B)

w

塊(512B)

b

KB(1024B)

k

MB(1024kb)

M

吉位元組(1024MB)

G


2.文字檔的交集與差集(comm)

交集:列印出兩個檔案所共有的行。

求差:列印出指定檔案所包含的且互不相同的那些行。

差集:列印出包含在檔案A中,但不包含在其他指定檔案中的那些行。

 

[root@localhost tmp]# cat A.txtappleorangegoldsilversteeliron[root@localhost tmp]# cat B.txtorangegoldcookiescarrot[root@localhost tmp]# sort A.txt -o A.txt ;sort B.txt -o B.txt [root@localhost tmp]# comm A.txt B.txt     apple    carrot    cookies        goldiron        orangesilversteel為了列印交集,刪除第1,2列:[root@localhost tmp]# comm A.txt B.txt -1 -2goldorange

 

 

3.建立不可修改的檔案
chattr +i filechattr -i file[root@localhost tmp]# for name in {1..100}.txt> do > touch $name> done

 

4.使用迴環檔案

(1)建立一個1G大小的檔案

[root@cai tmp]# dd if=/dev/zero of=looback.img bs=1G count=1

(2)用mkfs命令將1G檔案格式化成ext4檔案系統

[root@cai tmp]# mkfs.ext4 looback.img 

(3)使用下列命令檢查檔案系統

file loobackuo.img

(4)現在可以掛載環迴文件

[root@cai tmp]# mkdir /mnt/looback[root@cai tmp]# mount -o loop looback.img /mnt/looback/

(5)使用下面方法卸載(umount)

umount /mnt/looback

 

5.尋找檔案差異並進行修補(diff)
[root@cai tmp]# cat 1.txt this is a test11122334455[root@cai tmp]# cat 2.txt this is a test21144335555[root@cai tmp]# diff 1.txt 2.txt 1c1< this is a test1---> this is a test23,4d2< 22< 335a4,5> 33> 55[root@cai tmp]# diff -u 1.txt 2.txt --- 1.txt    2017-06-11 14:51:18.763717808 +0800+++ 2.txt    2017-06-11 14:51:47.477782113 +0800@@ -1,6 +1,6 @@-this is a test1+this is a test2 11-22-33 44+33+55 55

(2)用下列命令來修補

diff -u 1.txt 2.txt >3.txtpatch -p1 1.txt <3.txt[root@cai tmp]# cat 1.txt(和2.txt一模一樣) this is a test21144335555

(3)下列命令撤銷做出的修改

patch -p1 1.txt <version.patch

 

6.只列出目錄的各種辦法

(1)ls -d */

(2)ls -F |grep “/$”

(3)ls -l |grep “^d”

(4)find . -type d -maxdepth 1

 

7.統計檔案的行數、單詞數和字元數

wc命令(word count單詞統計)

(1)統計行數

wc -l file

(2)統計單詞數

wc -w file

(3)統計字元數

wc -c file

(4)當wc不使用任何參數時,分別列印出行數,單詞數,字元數。

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.