LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-13-2011, 04:30 PM   #1
ajhart
LQ Newbie
 
Registered: Dec 2008
Posts: 4

Rep: Reputation: 0
Question Find directory older than x and mv directory with sub files command


Hi guy's, I'm quite new to linux but I have configured a simple ftp server and it's working great. I have a FTP-Shared folder with upload and download subfolders. Under upload's and download's I have identical category subfolders like mp3's, movies, software etc. in both. As the guy's upload, I would like to create a line crontab where I can move all the content under /FTP-Shared/upload/mp3/* older than 14 day's to FTP-Shared/downloads/mp3/ recursively (Like in cp command), but the timestamp must be searched on the first directory and not sub files example: /mp3/Club Dance/CD1/Hallo world.mp3

This is how far I got:
[root@clients ~]# /usr/bin/find /FTP_Shared/upload/Mp3s/ -depth -mindepth 1 -mtime +14 -type d -exec mv -f {} /FTP_Shared/download/Mp3s/ \;

This command moves the directory and files, but it is not recursively

Any ideas would be great!!
Thanks in advance
 
Old 07-13-2011, 05:35 PM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
If you manually type the command part:
Code:
# substitute the appropriate source directory, of course
mv -f {} /FTP_Shared/download/Mp3s/
what happens that you think is deficient? mving a directory by definition also moves all of its subdirectories; no recursion required. You would need only to iterate over all found directories that meet the time criteria, and the find command should do that.

--- rod.
 
Old 07-14-2011, 12:16 AM   #3
ajhart
LQ Newbie
 
Registered: Dec 2008
Posts: 4

Original Poster
Rep: Reputation: 0
If I use the mv command manually, it works. It is only when I use the find command where it finds all the files and folders timestamp and moves them accordingly. It does not move the like in the manual command (recursion). Could I maybe use the grep command to find the 1st directory and the get the timestamp of that and then try to move it with all subdirectory’s and files?

Regards
 
Old 07-14-2011, 08:44 AM   #4
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Okay, maybe what is happening is that find is reporting the found directories in a depth-first order, so the lower directories are being moved first. To diagnose, insert the 'echo' command in front of 'mv', so you can see what is happening:
Code:
/usr/bin/find /FTP_Shared/upload/Mp3s/ -depth -mindepth 1 -mtime +14 -type d -exec echo mv -f {} /FTP_Shared/download/Mp3s/ \;
This is generally good practice when developing such scripts, to make sure you've got everything right before you start actually affecting the filesystem. Actually, now that I see your find command includes the -depth option, I think this is the problem. Remove that, and use breadth-first recursion.

--- rod.
 
Old 07-15-2011, 05:24 AM   #5
ajhart
LQ Newbie
 
Registered: Dec 2008
Posts: 4

Original Poster
Rep: Reputation: 0
Thanks for the advice, I'll have a look into that.
 
  


Reply



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] How to find files under the current directory? thomas2004ch Linux - Newbie 2 10-05-2010 05:19 AM
find the files in a directory ust Linux - Newbie 11 12-03-2008 12:24 AM
'find' command changes directory access time prollocks Programming 3 10-05-2007 11:57 AM
Listing files in a directory without ls and find? szahri Linux - Newbie 11 03-23-2007 03:12 AM
How to find the date for all the files in a directory Uday123 AIX 6 02-23-2006 08:26 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:03 PM.

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
Open Source Consulting | Domain Registration