日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

Bash 文件夹操作

發(fā)布時(shí)間:2025/7/14 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Bash 文件夹操作 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
  • mkdir, rm,find都是對tree結(jié)構(gòu)的文件夾進(jìn)行的操作,可以安裝tree用tree命令直接打印出樹的結(jié)構(gòu)
  • 文件夾的操作分為只操作當(dāng)前文件夾的集合數(shù)據(jù)和迭代操作的tree數(shù)據(jù)

Bash迭代當(dāng)前文件夾

ls---list information about the FILES(the current directory by default)[du也統(tǒng)計(jì)文件大小,但是du使用的是tree的數(shù)據(jù)結(jié)構(gòu),ls則是數(shù)組的數(shù)據(jù)結(jié)構(gòu)]

ls -author #羅列文件信息包含作者 ls -c -lt #根據(jù)訪問時(shí)間倒序排列 ls -c #list entries by columns ls -d #list directory entries instead of contents and don't dereference symbolic links ls -l -h # print sizes in human readable format
ls -l ./ceshi/ceshi #羅列第三級文件夾ceshi

?

Bash迭代文件夾樹

tree命令

Bash創(chuàng)建文件夾

mkdir---make directoryes

? ? ?-p---no error if existing,make parent directories as needed(帶著-p參數(shù),會自動判斷只有當(dāng)文件夾不存在的時(shí)候才創(chuàng)建,可以創(chuàng)建多層次目錄)

mkdir newdir #第一次創(chuàng)建不存在的目錄newdir成功 mkdir newdir #第二次創(chuàng)建已經(jīng)存在的newdir失敗 mkdir -p newdir#成功 mkdir -p newdir/firse/second/thired/#可以一次創(chuàng)建多級目錄

? ? mkdir可以創(chuàng)建一個(gè)完整的項(xiàng)目目錄結(jié)構(gòu)

mkdir -p project/{lib/ext,bin,src/doc/{html,info,pdf},demo/stat}#執(zhí)行完成后,當(dāng)前目錄下后出現(xiàn)一個(gè)當(dāng)前結(jié)構(gòu)【原文借鑒】

Bash刪除文件和文件夾

rm---rm removes each specified file.By default ,it does not remove directories.

? -i---prompt before ervry removal

? -r---remove directories and their contents recursively.

rm -i -r project#刪除文件夾project和文件夾下的全部內(nèi)容

Bash查找搜索文件夾

find---find searches the directory tree rooted at each given file name by evaluating the given expression from left to right,according to the rules of percedence,util the outcome is known,at which point find moves on to the next file name.(在目錄樹上搜索結(jié)果)

? -name---Base of file name matches shell pattern pattern.(根據(jù)文件名字匹配搜索)【詳細(xì)用法參考】

find './軟件' -name '*.txt' #查找當(dāng)前目錄下的軟件文件夾下,所有以txt結(jié)尾的文件 find '.' -user harvey#查找屬于用戶harvey的文件 find '.' -mtime -1#一天以內(nèi)修改的文件 find '.' -ctime -1#一天以內(nèi)創(chuàng)建的文件 find '.' -ctime -1 -name '*.txt'#今天創(chuàng)建的文本文件 find . -size +1000000c #查找文件大于1M的文件

Bash統(tǒng)計(jì)文件夾下所有文件的大小

du---summarize disk usage of each FILE,recursively for directories(遞歸的統(tǒng)計(jì)磁盤的使用情況)

-h---print sizes in human readable format(e.g.,1k 234M 2G)

du -h '.' #統(tǒng)計(jì)當(dāng)前文件夾下各文件使用磁盤的情況

Bash移動文件

?mv---Rename SOURCE to DEST or move SOURCE(s) to DIRECTOR.

mv test.txt x.txt #當(dāng)前目錄下的test.txt重命名為x.txt mv x.txt ./ceshi/x.txt #移動x.txt到測試文件夾下

?Bash復(fù)制文件

cp kkkk.txt k1.txt # 在當(dāng)前文件夾下復(fù)制文件 cp kkkk.txt ./ceshi/k2.txt #復(fù)制文件到新的文件夾

?

? ??

?

轉(zhuǎn)載于:https://www.cnblogs.com/zhanghaiyublog/p/3593569.html

總結(jié)

以上是生活随笔為你收集整理的Bash 文件夹操作的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。