大网数据广告活动
服务器运维问答

how to exclude folders by date with find?

· 52CE 我爱测

This is "myfolder": tree -a 'myfolder' myfolder ├── 20220902 │ ├── filefoo │ └── filebar ├── 20221001 │ ├── filefoo │ └── filebar └── 20221015 ├── filefoo ├── filebar └── filexyz etc... my command: find $folder/$(date +"%Y%m"*) -…

问题原文

原帖链接 · acgbox · CC BY-SA 4.0

This is "myfolder":

tree -a 'myfolder'
myfolder
├── 20220902
│   ├── filefoo
│   └── filebar
├── 20221001
│   ├── filefoo
│   └── filebar
└── 20221015
    ├── filefoo
    ├── filebar
    └── filexyz
  etc...

my command:

find $folder/$(date +"%Y%m"*) -type f | xargs -I {} awk '/^total:/{sub(".*/", "", FILENAME); print FILENAME" "$NF}' {})

Problem: i need exclude weekends. How do I do it?

PD: I know that in bash/awk it is

%u The weekday as a decimal number (1–7). Monday is day one.

thanks

Update Solved!

I found the answer in stackoverflow HERE

已采纳解答

原帖链接 · jabbson · CC BY-SA 4.0

To filter out the weekends, you could format the name of the folder to a date format %u, which signifies the day of the week (by number).

Check out this example:

FOLDER_DATE=$(date -d '20221014' +%u)   #your folder name would go here

if [[ "$FOLDER_DATE" -eq 6 || "$FOLDER_DATE" -eq 7 ]]
then 
  echo "Weekend"
else 
  echo "Not Weekend"
fi

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2022-10-16)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。