How to loop through multiple folder and subfolders and remove file name start with abc.txt and 14 days old

后端 未结 1 1691
孤独总比滥情好
孤独总比滥情好 2021-01-29 06:25

I have folder and subfolder. I need to loop through each folder and subfolder and remove or move the file names which start with abc.txt and 14 days old to temporary folder. My

相关标签:
1条回答
  • 2021-01-29 06:58

    You want to find files: -type f
    that start with abc.txt: -name "abc.txt*"
    that are 14 days old: -mtime +14
    and move them to a dir.: -exec mv {} /tmp \;
    and to see what moved: -print

    So the final command is:

    find . -type f -name "abc.txt*" -mtime +14 -exec mv {} /tmp \; -print

    Adjust the directory as required.

    Note that mtime is the modification time. So it is 14 days old since the last modification was done to it.

    Note 2: the {} in the -exec is replaced by each filename found.

    Note 3: \; indicates the termination of the command inside the -exec

    Note 4: find will recurse into sub-directories anyway. No need to list the directories and loop on them again.

    0 讨论(0)
提交回复
热议问题