Linux命令之目錄和檔案操作

來源:互聯網
上載者:User

標籤:linux

1 pwd:顯示當前工作目錄

[[email protected] ~]# pwd

/root


2 cd:切換當前工作目錄

[[email protected] /]# cd                   #切換到目前使用者的家目錄

[[email protected] ~]# cd ..                #切換到目前的目錄的上一級目錄

[[email protected] /]# cd -                 #返回至前一個目錄


3 ls:顯示目錄和檔案資訊

選項:-a    顯示所有,包括隱藏檔案和目錄

      -d    顯示目錄本身的資訊,而非目錄下的文檔資訊

      -h    人性化顯示容量資訊

      -l    長格式顯示文檔的詳細資料

      -u    顯示檔案或目錄最後被訪問的時間

      -t    以修改時間排序,ls預設以檔案名稱排序的

[[email protected] /]# ls /                #顯示根目錄下檔案和目錄的名稱

[[email protected] /]# ls -a               #顯示所有檔案

[[email protected] /]# ls -ld /root        #顯示root目錄的詳細資料,時間為被修改的時間

[[email protected] /]# ls -lh /root        #人性化顯示容量資訊

[[email protected] ~]# ls -lu install.log  #查看檔案的最後訪問時間

[[email protected] /]# ls -lt              #查看文檔資訊並且以修改時間排序


4 touch:建立檔案或修改檔案時間

[[email protected] ~]# touch a.txt         #建立檔案,如果檔案存在,則更新檔案修改時間為目前時間

[[email protected] ~]# touch -t 201501012330 a.txt    #改變檔案的時間戳記


5 mkdir:建立目錄

選項:-p    建立多級目錄

      -v    顯示建立過程

[[email protected] ~]# mkdir -pv /abc/cd{e,f}        #建立多級目錄,-v顯示過程

mkdir: created directory `/abc‘

mkdir: created directory `/abc/cde‘

mkdir: created directory `/abc/cdf‘


6 cp:複製檔案與目錄

用法:cp [選項] 源 目標

選項:-r    遞迴複製,複製子檔案和子目錄,用於複製目錄時使用

      -a    複製時保留文檔所有屬性(包括許可權、時間等)

[[email protected] /]# cp /root/a.txt /b.txt        #複製檔案並修改名稱

[[email protected] /]# cp -a /etc/passwd /var/tmp   #複製並保留文件屬性


7 rm:刪除檔案或目錄

選項:-f    強行刪除(慎用)

      -i    刪除前提示

      -r    遞迴刪除,刪除目錄及目錄下所有內容

[[email protected] ~]# rm -f a.txt

[[email protected] ~]# rm -fr directory


8 mv:移動或重新命名檔案

[[email protected] ~]# mv a.txt b.txt


9 find:搜尋檔案或目錄

用法:find [路徑] [匹配標準] [運算式選項]

選項:-empty    搜尋空白檔案或目錄

      -group    按組尋找 

      -name     按文檔名稱尋找

      -iname    按文檔名稱尋找並且不區分大小寫

      -mtime    按修改時間尋找

      -size     按容量大小尋找

      -type     按文件類型尋找,檔案(f)、目錄(d)、裝置(b,c)等

      -user     按使用者尋找

      -a        並且

      -o        或

[[email protected] ~]# find b.txt                    #尋找目前的目錄下的檔案

[[email protected] ~]# find /root -name "*.cnf"      #尋找root目錄下以cnf結尾的檔案

[[email protected] ~]# find -iname "b.txt"           #不區分大小寫尋找b.txt

[[email protected] ~]# find / -group zwj             #尋找所屬組為zwj的文檔

[[email protected] ~]# find / -mtime +3              #尋找3天前被修改過的文檔

[[email protected] ~]# find / -mtime -1              #尋找當天被修改過的文檔

[[email protected] ~]# find / -size +100M            #尋找要目錄下大於100M的文檔

[[email protected] ~]# find ./ -type f               #尋找目前的目錄下所有普通檔案

[[email protected] ~]# find / -iname "b.txt" -type f -exec rm -fr {} \;

                 #尋找根目錄下所有的b.txt檔案(不區分大小寫)並且刪除它們

[[email protected] ~]# find ./ -type f -a -size +1k  #尋找目前的目錄下大於1k的普通檔案


10 du:計算檔案或目錄的容量

選項:-h    人性化顯示容量資訊

      -a    查看所有目錄以及檔案的容量資訊

      -s    僅顯示總容量

[[email protected] ~]# du -h /root                     #人性化顯示/root目錄的容量資訊

[[email protected] ~]# du -sh /root                    #顯示/root所佔磁碟空間之和

[[email protected] ~]# du -a /root                     #查看/root目錄下所有檔案和目錄的容量資訊

本文出自 “一萬年太久,只爭朝夕” 部落格,請務必保留此出處http://zengwj1949.blog.51cto.com/10747365/1916262

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.