[英]How to strip leading "./" in unix "find"?
find . -type f -print
打印出來
./file1
./file2
./file3
任何讓它打印的方法
file1
file2
file3
?
僅查找當前目錄下的常規文件,並打印不帶“ ./
”前綴的文件:
find -type f -printf '%P\n'
來自 man find, -printf
格式的描述:
%P 文件名和命令行參數的名稱,在該文件名下被刪除。
使用 sed
find . | sed "s|^\./||"
如果它們僅在當前目錄中
find * -type f -print
那是你要的嗎?
它可以更短
find * -type f
由於-printf
選項在 OSX find
上不可用,這是一個適用於 OSX find 的命令,以防萬一有人不想使用brew
等安裝gnu find
:
find . -type f -execdir printf '%s\n' {} +
剝離 ./ 的另一種方法
find * -type d -maxdepth 0
對於當前目錄中的文件:
find . -maxdepth 1 -type f | xargs basename -a
-maxdepth 1 -> basically this means don't look in subdirectories, just current dir
-type f -> find only regular files (including hidden ones)
basename -> strip everything in front of actual file name (remove directory part)
-a -> 'basename' tool with '-a' option will accept more than one file (batch mode)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.