Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个目录,其中包含格式为 "run_dd_mm_yy" 的文件夹。这些文件夹包含子文件夹。但我只需要列出过去 7 天的文件夹(上述格式)。你能建议我在 linux 中使用任何命令来解决这个问题吗?
外壳命令
date -d '1 day ago' +'run_%d_%m_%y'
将根据今天的日期为您提供文件夹名称,但几天前
for d in 1 2 3 4 5 6 7; do datestr=`date -d "$d day ago" +'run_%d_%m_%y'`; ls -l $datestr;done
过去 7 天的文件夹的顶级列表
如果您需要在每个文件夹的顶层获取子文件夹,而不是ls -l $datestr使用类似
ls -l $datestr
find $datestr -type d -maxdepth 1 -print