命令行學(xué)習(xí)筆記(搜索和壓縮相關(guān))

  • grep pattern file -- 使用正則表達(dá)式搜索文本
  • grep -r pattern dir -- 遞歸使用正則表達(dá)式搜索文本
  • command | grep pattern -- 以 command 輸出為文本進(jìn)行正則表達(dá)式搜索
  • locate file -- 查找文件

效果如下:

?  anyang cat file1     
Hello, anyang!
testhhhhhhhhhhhhh
rrrrrrrrrrrrrrrr
ddddddddddddd
testfsfdsccvv
?  anyang grep test* file1 
testhhhhhhhhhhhhh
testfsfdsccvv
?  anyang grep -r test* .
./test/test1:test is a problem
./test/test3:test is nice
./file1:testhhhhhhhhhhhhh
./file1:testfsfdsccvv
?  anyang cat file1 | grep test*
testhhhhhhhhhhhhh
testfsfdsccvv
?  anyang locate grep
/bin/bzegrep
/bin/bzfgrep
/bin/bzgrep
/bin/egrep
/bin/fgrep
/bin/grep
/bin/zegrep
/bin/zfgrep
/bin/zgrep
/etc/alternatives/lzegrep
/etc/alternatives/lzegrep.1.gz
/etc/alternatives/lzfgrep
  • tar cf file.tar file(s) -- 將 file(s) 打包成名為 file.tar 的文件
  • tar xf file.tar -- 解壓 file.tar 包中的所有文件
  • tar tf file.tar -- 列出 file.tar 包中的所有文件

tar 常用參數(shù)列表:

  • c -- 建立壓縮文件
  • t -- 列出壓縮文件中的所有文件
  • x -- 解壓壓縮文件
  • f -- 指定壓縮包的文件名
  • z -- 有g(shù)zip屬性的
  • j -- 有bz2屬性的
  • w -- 每一步操作都需要確認(rèn)
  • v -- 顯示所有過程

效果如下:

?  test ls
file1  test1  test2  test3
?  test tar cf test.tar test{1..3}
?  test ls
file1  test1  test2  test3  test.tar
?  test mv test.tar ..           
?  test cd ..
?  anyang ls
file1  learngit  test  test.tar
?  anyang tar xf test.tar          
?  anyang ls
file1  learngit  test  test1  test2  test3  test.tar
?  anyang tar tf test.tar
test1
test2
test3
  • gzip file(s) -- 建立壓縮文件,并刪除原來的文件
  • gzip -c file(s) > file.gz -- 建立壓縮文件并保留原來的文件
  • gzip -d file.gz -- 解壓壓縮文件,并刪除原來的壓縮文件,效果同gunzip

效果如下:

?  anyang ls
file1  learngit  test
?  anyang gzip file1 
?  anyang ls
file1.gz  learngit  test
?  anyang touch newfile
?  anyang ls
file1.gz  learngit  newfile  test
?  anyang gzip -c newfile > newfile.gz
?  anyang ls
file1.gz  learngit  newfile  newfile.gz  test
?  anyang gzip -d file1.gz 
?  anyang ls
file1  learngit  newfile  newfile.gz  test

相關(guān)資料:

  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
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容