74H1R
74H1R

Reputation: 3514

How to move files to another directory which are created today in Shell?

I have following script

find . -mtime 0 -type f -exec ls -ltr {} \; | grep "$(date +%d|sed 's,^0,,g') ..:.." | while read fname; do
   echo "$fname"
done

And I am able to print file detail. How can I move test1.txt test2.txt files to another directory?

Output:

[nca@ldc039 failure]$ . ../../scripts/retryFailedFiles.sh 
-rwxrwxr-x. 1 nca nca 0 Feb 29 16:16 ./test1.txt
-rwxrwxr-x. 1 nca nca 0 Feb 29 16:16 ./test2.txt 

Upvotes: 0

Views: 1493

Answers (1)

Ali ISSA
Ali ISSA

Reputation: 408

# You can use the option -1tr instead -ltr :
find . -mtime 0 -type f -exec ls -1tr {} \; | while read fname; do
echo "$fname" 
mv $fname newfolder
done

# Or, by using the following commande :
find . -mtime 0 -type f -exec mv {} newfolder \;

Upvotes: 2

Related Questions