Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find all files from today recursively and copy them

Tags:

bash

shell

pdf

I want to find all *.pdf files recursively in directory /dir

In that dir there are specific files such as /dir/1/2.pdf [modified today], /dir/2/3.pdf [modified today], /dir/4/4.pdf [from yesterday]

IN that case I only want files that were modified today so: 2.pdf and 3.pdf

I also want to move those files to directory called /pdf/

I found that I can find all files in current directory modified today with:

find -maxdepth 1 -type f -mtime -1

How can I find files from today in subdirectories and move them to /pdf/ dir?

Thanks!!! Adam

like image 491
Adam Lesniak Avatar asked Dec 29 '25 20:12

Adam Lesniak


1 Answers

Remove -maxdepth 1 from your find command to find files in subdirectories and use -exec to move those to the target directory:

find /dir -type f -mtime -1 -exec mv {} /pdf \;
like image 183
devnull Avatar answered Jan 01 '26 12:01

devnull



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!