linux中的命令

來源:互聯網
上載者:User

標籤:常用linux命令

1:cat -s:壓縮空白行;移除空白行 cat test.txt| tr ‘\n‘ ‘‘;

   cat -T:將定位字元顯示為^I;

   cat -n:顯示行號

2:find :

    -name :根據檔案名稱或Regex匹配;find . \( -name "*.txt" -o -name "*.py" \) -print

    -path:根據路徑匹配;

    -maxdepath和-mindepath基於目錄深度搜尋;

    -type f(d\c\l等)檔案類型;find . -type f -print

    -perm:檔案許可權;find . -perm 644 -print

    -size:檔案大小(k\m\g\b\c等)find . -size +2k -print

    -user:檔案的屬主;find . -user root -print

    -prune:排除 find . \( -path ./old -prune \) -o \( -name "*.txt" -print \)

3:檔案的校正(sha1sum和md5sum格式一致)

    在同一目錄中通過 md5sum file >file.md5得到md5校正檔案;然後md5sum -c file.md5比較是否一致;根據file.md5中的內容自動比較源檔案md5,不需要和源檔案同名。    

    遞迴計算校正和:    find /etc/ -type f  -print0 | xargs -0 md5sum >>dir.md5 

4:sort :    

    -n:按數字排序

    -r:按逆序排序

    -M:按月份排序

    -k:按第幾列排序

    -z:以\0作為終止符和xargs -0相符

    -C:是否排序

5:uniq:消除重複行,檔案必須先排序過

    -c:統計各行出現的次數

    -d:找出重複的行

    -z:產生\0為終止符和xargs -0相相容

    如:uniq -z file.txt | xargs -0 rm 

6: 臨時檔案名稱的產生:$$當前進程號。如: file-$$.txt

7: 分割檔案:

    dd if=/dev/zero of=/tmp/date.txt count=10M bs=10

    split -b 1m date.txt -d -a 4 (file)以1M每個檔案大小分割檔案,並以尾碼定長為4。(首碼為file,預設為)

8:根據副檔名匹配:

    ${var%.*}從右至左匹配,匹配結果刪除。如var=simple.jpg;則結果為var=simple。

    ${var#*.}從左至右匹配,匹配結果刪除。如var=simple.jpg;則結果為var=jpg。

    ${var%%.*}和${var##*.}為貪婪匹配;使用更多。


       








本文出自 “營運、資料庫” 部落格,請務必保留此出處http://startxx.blog.51cto.com/9565498/1572673

linux中的命令

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.