shell檔案操作相關命令

2021-06-16 08:38:30 字數 734 閱讀 4519

1, 在/opt目錄 下新建乙個資料夾,名字叫new_folder,並且把/etc/init.d中的所有檔案拷貝到這個資料夾中。

sudo cp –r /etc/init.d /opt/new_folder

2, 把new_foleder分別壓縮為new_folder.tar.gz和new_foleder.tar.bz2檔案

sudo tar –jcvf new_folder.tar.bz2new_folder/

sudo tar –zcvf new_folder.tar.gz new_folder/

3, 將new_folder.tar.gz解壓到主目錄(可以使用-c這個選項)

sudo tar –zxvf new_folder.tar.gz –c ~/

4, 使用find命令,在/var目錄下找到所有以 .deb(注意這裡有個點)為結尾的檔案

find /var –name *.deb

5, 使用find命令,在/dev目錄下找到字元裝置檔案

find /dev –type 『c』

6, 使用grep命令,在/etc/passwd搜尋字串「syslog」,並在終端上顯示該字元在第幾行

grep 「syslog」 /etc/passwd -n

7, 使用grep命令,在/usr/include 目錄搜尋字串「ifndef」,並在終端上顯示該字元在那個檔案中和第幾行

grep 「ifndef」 /usr/include –f -n

檔案相關操作命令

touch 檔案 mkdir 資料夾 2 檔案刪除 rm 刪除的檔案很難恢復 rm 檔名 刪除檔案會有提示 rm f 檔名 強制刪除檔案不提示 rm r 目錄 資料夾 刪除資料夾會有提示 rm rf 目錄 資料夾 刪除資料夾不提示 3 檔案複製 cp copy cp 要複製的檔案的路徑 想要生成的檔...

shell常用檔案操作命令

echo date y m d true financials.logtail n 1 financials.log 賦值給變數 finc flag tail n 1 financials.log sed n 1p financials.log cut d f1 第一行第一列 賦值給變數 finc ...

hdfs檔案操作shell命令

usage hadoop fs generic options cat ignorecrc checksum chgrp r group path.chmod r mode octalmode path.chown r owner group path.copyfromlocal f p l cop...