如果我有以下情況:
ls|sort -n
我將如何按排序檔案的順序觸摸所有這些檔案?就像是:
ls|sort -n|touch
什么是正確的語法?請注意,我需要按照它們被排序的確切順序對檔案進行排序——因為我試圖以最少的元資料讀取為 FAT 閱讀器對這些檔案進行排序。
uj5u.com熱心網友回復:
ls -1tr | while read file; do touch "$file"; sleep 1; done
如果您想保留從一個檔案到下一個檔案的修改時間距離,請改為呼叫它:
upmodstamps() {
oldest_elapsed=$(( $(date %s) - $(stat -c %Y "`ls -1tr|head -1`") ))
for file in *; do
oldstamp=$(stat -c %Y "$file")
newstamp=$(( $oldstamp $oldest_elapsed ))
newstamp_fmt=$(date --date=@${newstamp} '%Y%m%d%H%M.%S')
touch -t ${newstamp_fmt} "$file"
done
}
注意:date使用假定 GNU
uj5u.com熱心網友回復:
你可以使用這個命令
(ls|sort -n >> list.txt )
touch $(cat list.txt)
或者
touch $(ls /path/to/dir | sort -n)
或者,如果您想復制檔案而不是創建空檔案,請使用此命令
cp list.txt ./DirectoryWhereYouWantToCopy
uj5u.com熱心網友回復:
像這樣試試
touch $(ls | sort -n)
uj5u.com熱心網友回復:
可以給幾個檔案名嗎?
如果你有數字為 1file, 10file, 11file .. 20file 的檔案名,那么你需要使用--general-numeric-sort
ls | sort --general-numeric-sort --output=../workingDirectory/sortedFiles.txt
cat sortedFiles.txt
1file
10file
11file
12file
20file
并將 sortedFile.txt 移動到您的作業目錄或您想要的任何位置。
touch $(cat ../workingDirectory/sortedFiles.txt)
這將創建具有完全相同名稱的空檔案
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/410601.html
標籤:
