LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Moving 2 months of old files from a folder to another folder. (https://www.linuxquestions.org/questions/linux-server-73/moving-2-months-of-old-files-from-a-folder-to-another-folder-4175416080/)

Iyyappan 07-11-2012 04:06 AM

Moving 2 months of old files from a folder to another folder.
 
I need to move huge list of files from april to june to a folder. I need to move without touching July files. Need some help on this. I have used find command.

find . -type f -m time +60 -exec mv /old/files {} \;

kindly correct if I am wrong.

jv2112 07-11-2012 04:28 AM

:twocents:

To confirm --- Files created in the month of June was placed by error in the month of April folder as well as July files ? :scratch:

If so this should get it done for you.

Addjust the periods relative to when you run it as well as the directory paths to what your system reflects.


Code:


find /april -type f -and -mtime +11 -and -mtime -41 -exec mv -v {} July/ \;


Iyyappan 07-11-2012 04:31 AM

Actually all the april, may, june files are placed in a single folder. There are many folders as well. Only way to distinguish April, May, June files is used date right.. Its a mix of all the months from april - july 11. I need to move all the files except july files to a new folder. Also we need to specify the target location after mv right


find /home/user/Downloads/ -type f -mtime +60 -exec mv /mnt/test {} \; Is this correct.. to move last 60 days of files to /mnt/test... Or would it be simple to move files from april to june alone. What i meant is instead of specifying last 60 days, is there an option to spcecify files from june n april alone

Iyyappan 07-11-2012 05:04 AM

ls -l | grep -i jul provides me an ouput. I want to move all the listed files to a folder. How can i do it .

pixellany 07-11-2012 06:55 AM

Code:

ls -l | grep -i jul | awk '{print $6}' > filelist
while read filename; do
    mv $filename <whereever>
done < filelist

replace <whereever> with the destination path

Iyyappan 07-13-2012 12:56 AM

I used the below command and it worked


ls -ltr | egrep -v '^d'| /bin/grep Jun | /bin/awk '{ print $9 }' |/bin/cut -d: -f1,2 | xargs -t -I {} mv {} old_files4

Reuti 07-13-2012 04:45 AM

Quote:

Originally Posted by Iyyappan (Post 4726697)
I used the below command and it worked


ls -ltr | egrep -v '^d'| /bin/grep Jun | /bin/awk '{ print $9 }' |/bin/cut -d: -f1,2 | xargs -t -I {} mv {} old_files4

Well, the time format might change due to the setting of locale so that it’s no longer $9 and piping looks lengthy. This can still be put into one find command I think. What problem did you face with the find command? And what does the cut command – splitting the file name at a colon, so that it’s no longer a valid filename?


All times are GMT -5. The time now is 11:16 AM.