LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices



Reply
 
Search this Thread
Old 07-11-2012, 05:06 AM   #1
Iyyappan
Member
 
Registered: Dec 2008
Location: Chennai, India
Distribution: CentOS 5, SLES 11
Posts: 231

Rep: Reputation: 4
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.
 
Old 07-11-2012, 05:28 AM   #2
jv2112
Member
 
Registered: Jan 2009
Location: New England
Distribution: Arch Linux
Posts: 719

Rep: Reputation: 103Reputation: 103
Lightbulb



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

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/ \;
 
Old 07-11-2012, 05:31 AM   #3
Iyyappan
Member
 
Registered: Dec 2008
Location: Chennai, India
Distribution: CentOS 5, SLES 11
Posts: 231

Original Poster
Rep: Reputation: 4
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

Last edited by Iyyappan; 07-11-2012 at 05:35 AM.
 
Old 07-11-2012, 06:04 AM   #4
Iyyappan
Member
 
Registered: Dec 2008
Location: Chennai, India
Distribution: CentOS 5, SLES 11
Posts: 231

Original Poster
Rep: Reputation: 4
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 .
 
Old 07-11-2012, 07:55 AM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729
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
 
Old 07-13-2012, 01:56 AM   #6
Iyyappan
Member
 
Registered: Dec 2008
Location: Chennai, India
Distribution: CentOS 5, SLES 11
Posts: 231

Original Poster
Rep: Reputation: 4
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
 
Old 07-13-2012, 05:45 AM   #7
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 13.1
Posts: 1,320

Rep: Reputation: 252Reputation: 252Reputation: 252
Quote:
Originally Posted by Iyyappan View Post
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?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] [APPENDED]Real moving of a folder's content to another folder. MODYSAMA Linux - Newbie 10 02-08-2011 12:30 AM
[SOLVED] How to list folder size, and number of files and folders in folder steven.c.banks Linux - General 3 11-24-2010 07:24 AM
[SOLVED] Moving files from folders and subfolders to a specific folder mrj2 Linux - Newbie 12 08-22-2010 01:40 PM
No access rights to delete or move files after re-install and moving from user folder sonicboy Ubuntu 5 01-18-2010 04:28 AM
Moving certain files recursively preservice folder structure DigiTalk Linux - Newbie 11 09-08-2005 09:04 AM


All times are GMT -5. The time now is 01:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration