Copying the files based on modification date in linux

后端 未结 5 395
小蘑菇
小蘑菇 2021-02-02 11:13

It may be a duplicate question but i could not find the solution for this i want to copy a last 3 months files from one directory to another directory but i could find only to l

5条回答
  •  被撕碎了的回忆
    2021-02-02 11:21

    I guess I would first store the list of files temporarily and use a loop.

    find . -mtime -90 -ls >/tmp/copy.todo.txt
    

    You can read the list, if it is not too big, with

    for f in `cat /tmp/copy.todo.txt`;
    do echo $f;
    done
    

    Note: the quotes around cat... are backquotes, often in upper left corner of keyboard

    You can then replace the echo command with a copy command:

    for f in `cat /tmp/copy.todo.txt`;
    do cp $f /some/directory/
    done
    

提交回复
热议问题