-1
我試圖循環通過一組文件夾,如果一個(或多個)文件比特定的日期更新,它應該顯示該文件夾和文件(s),就像這樣;很好的方式循環導演和文件
(日期是周齡)
Folder 1
file 1
*Folder 2 (no files matching the date, should not be visible/echo'ed)*
Folder 3
file 1
file 2
Folder 4
file 1
如何實現這一目標?我的示例代碼:
#!/opt/bin/bash
#
# CurrentTvList.sh
# File for generating a current list of stored tvshows on my nas
# Patrick Osterlund
#
#set -x
#trap read debug
# Settings
#
NEWTMPFOLDER="/volume1/tmp/tvtemps/"
NEWTMPFILE="TmpTvlisting.txt"
SIMPLER=$NEWTMPFOLDER$NEWTMPFILE
SMALL=2
MEDIUM=14
LARGE=30
# Clear screen; remove later
clear
#check if dir exists
mkdir -p ${NEWTMPFOLDER}
#check if file exists
if [ -f $SIMPLER ];
then
echo "File: $NEWTMPFILE exists in $NEWTMPFOLDER" $'\n'
FILEDATE=$(date -r $SIMPLER)
#Check if file is newer than the existing one
if [[ $SIMPLER -nt $FILEDATE ]]; then
echo "$SIMPLER is newer than $FILEDATE"
else
echo "file created $FILEDATE is newer than file created; $SIMPLER"
fi
echo "and it was created: $FILEDATE" #$'\n\n'
echo "File was created: " > $SIMPLER
echo $FILEDATE >> $SIMPLER $'\n'
else
echo "File $NEWTMPFILE does not exists in $NEWTMPFOLDER, creating it"
touch $SIMPLER;
fi
# Mostly for checking if all went well:
echo "looking here:" $NEWTMPFOLDER;
echo "file: $NEWTMPFILE"
# Small list
echo "New shows last ${SMALL} days: " $'\n' >> $SIMPLER
find /volume2/Disk2/!Tv-Serier/ -type f -mtime -$SMALL -size +2048 -exec basename {} \; | sed 's/\.[^.]*$//'\
>> $SIMPLER
# Medium list
echo $'\n' "New shows last ${MEDIUM} days: " $'\n' >> $SIMPLER
find /volume2/Disk2/!Tv-Serier/ -type f -mtime -$MEDIUM -size +2048\
-exec basename {} \; | sed 's/\.[^.]*$//' >> $SIMPLER | sort -df
# Not in use right now
# Large list
#echo $'\n' "New shows last ${LARGE} days: " $'\n' >> $SIMPLER
#find /volume2/Disk2/!Tv-Serier/ -type f -mtime -$LARGE -size +2048\
# -exec basename {} \; | sed 's/\.[^.]*$//' >> $SIMPLER | sort -df
newerct在busybox中不起作用,顯然是:/ 但是不,我只想列出較新的文件,舊的文件對此目的不感興趣。 – b0red
這是一種有助於你在你的問題中提及的細節,因爲「[BusyBox中的實用程序通常比全功能的GNU表兄弟選項更少](http://www.busybox.net/about html的)。」同樣,如果您只希望列出較新的文件,您應該提到這一點。 –
對不起,我對這個論壇有點新,將來會試着提供更多信息:/ – b0red