LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices


Reply
  Search this Thread
Old 08-24-2008, 11:59 AM   #1
visitnag
Member
 
Registered: Mar 2008
Posts: 147

Rep: Reputation: 15
move files of a particular directory


Friends..

I am working on RHEL4es server. I have so many subdirectories under a main directory. within that subdirectories there is a directory called print(usr/martin/data/print, usr/daniel/print) under each subdirectory. Now my problem is these print directory files pile up as the users generate the print files regularly. I want to move the print files regularly to some other directory once in a week or the system should move the print directory files which are week days old to some specified directory. Can anybody give me an idea. Thanks in advance..
 
Old 08-24-2008, 02:23 PM   #2
PatrickNew
Senior Member
 
Registered: Jan 2006
Location: Charleston, SC, USA
Distribution: Debian, Gentoo, Ubuntu, RHEL
Posts: 1,148
Blog Entries: 1

Rep: Reputation: 48
How about
Code:
find /path/to/main/dir/ -path '*/print/*' -t f -delete
That searches through /path/to/main/dir/ recursively, looking for anything that is a file and whose path contains a directory named "print", then deletes that file. The '-t f' says "only delete files, not directories".
 
Old 08-24-2008, 04:30 PM   #3
lwasserm
Member
 
Registered: Mar 2008
Location: Baltimore Md
Distribution: ubuntu
Posts: 184

Rep: Reputation: 41
As PatrickNew suggest you can use the find command to locate the files. find has an "exec" option that can run a command for each file found, man find for details, the syntax can be somewhat confusing.

If your question was about scheduling the file moves rather than how to locate and move them, check out cron, or anacron for a system that is not always on. Another option might be put the age test and move commands in each users .profile or shell rc file, so that the file ages would be checked and moved when that particular user logs in. bash and other shells also have a file read and executed at logout ( .bash_logout for bash) which could be used.
 
Old 08-25-2008, 08:57 PM   #4
visitnag
Member
 
Registered: Mar 2008
Posts: 147

Original Poster
Rep: Reputation: 15
Thank you both for quick reply. I recently took charge as an sys.administrator(RHEL4es). I am well versed with the linux commands but new to configure the crons...profiles... I want to move files from print directory which are say 3days old to some other directory(automatically or i run the shell every third day). Kindly give me detailed (step by step) guidance, including how to include it in the cron.

Example:

i hav files called fl1,fl3 created 3days back in /usr/pro/actuary/data/print, and /usr/pro/maker/print respectively
I want to mv these files to /usr1/printbkp
 
Old 08-25-2008, 09:46 PM   #5
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
Please don't duplicate your posts. I'll repeat my question from your other post:

Do you want the files moved to /usr1/printbkp to also be contained in a sub-directory tree similar to their source directory? Or do you just want all files moved to the directory /usr1/printbkp?
 
Old 08-26-2008, 07:23 PM   #6
visitnag
Member
 
Registered: Mar 2008
Posts: 147

Original Poster
Rep: Reputation: 15
Yes.

I repeat again. I want to move 3days older files of all 'print' directories of any subdirectory under /usr/pro/ directory to /usr1/printbkp.

Because there are so many print (sub)directories for each user under /usr/pro/

like
/usr/pro/mike/print
/usr/pro/john/print

and even like
/usr/pro/martin/data/print


Thank you.

Last edited by visitnag; 08-26-2008 at 07:25 PM.
 
Old 08-26-2008, 07:36 PM   #7
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
I'm sure you understand you cannot respond to a question such as "Do you want A or B" with the answer "Yes". :-)

This moves all files older than 3 days into your specified directory:

Code:
find . -type f -wholename '*/print/*'  -prune -mtime +3 -exec echo mv '{}' /usr1/printbkp \;
Remove the echo when you are ready to run the program for real.
 
Old 08-26-2008, 08:20 PM   #8
visitnag
Member
 
Registered: Mar 2008
Posts: 147

Original Poster
Rep: Reputation: 15
sorry. I didnot understand your query of A and B. I want to move only print directory files not all the sub-directory files. But you gave me the correct answer. I have taken charge of linux administration recently, and 80% of my /usr/pro/ directory is occupied with garbage files mainly in print directories. I will be thankful to you. Kindly bear with me. If you dont mind could you please explain me the terms used in the find command which you gave ....

-type
-f
-wholename
-prune -mtime +3
-exec

Thank you.
from India.
 
Old 08-26-2008, 09:45 PM   #9
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
I had asked you which of two possibilities you wanted. You replied "Yes", which didn't tell me which possibility you wanted.

man find


will explain the terms. Please look there first, and I'll help explain the parts in man find are not clear to you.
 
Old 08-30-2008, 08:05 PM   #10
visitnag
Member
 
Registered: Mar 2008
Posts: 147

Original Poster
Rep: Reputation: 15
Mr. C
Thank you for your reply. When i typed the command and run it. It giving error. I could not find anything about -wholename in the find man pages(please dont lough at me, i hav already told you i am new to sys.admn). Please give me a command which i can run as it is.

I want one command this should search from my /usr/mike/ directory and find all the print directories down the /usr/mike/ directory and move the 3days older files to /usr1/printflbkp/ directory.

Is it possible to restore the moved files to again respective directories?, if i need. Kindly clarify me.

Tahnk you alot.
 
Old 08-30-2008, 08:19 PM   #11
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
It is possible your version of find is older, and does not have the --wholename option. I'm not sure in which version this was implemented. Which version of find do you have in RHEL 4?

Code:
find --version
GNU find version 4.2.33
Built using GNU gnulib version 8e128ebf42e16c8631f971a68f188c30962818be
Features enabled: D_TYPE O_NOFOLLOW(enabled) LEAF_OPTIMISATION
The --wholename is defined as:

Quote:
-wholename pattern
File name matches shell pattern pattern. The metacharacters do
not treat `/' or `.' specially; so, for example,
find . -wholename './sr*sc'
will print an entry for a directory called './src/misc' (if one
exists). To ignore a whole directory tree, use -prune rather
than checking every file in the tree. For example, to skip the
directory `src/emacs' and all files and directories under it,
and print the names of the other files found, do something like
this:
find . -wholename './src/emacs' -prune -o -print
I believe there is another option --path that you can use instead of --wholename. If not, please check your man page for find predicates that do pathname matching. I'd prefer not trying to guess which options your find supports.
 
Old 09-06-2008, 01:01 PM   #12
visitnag
Member
 
Registered: Mar 2008
Posts: 147

Original Poster
Rep: Reputation: 15
my find version is 4.1.2 and i am using RHEL 4 ES. Please give me required command which cleans all my print directory files (one more thing i tell you forgot these print directory folders contain some sub folders also, that folder 3days older files also to be moved to a specified directory.)

Thanking you.

nag
 
Old 09-13-2008, 03:29 PM   #13
visitnag
Member
 
Registered: Mar 2008
Posts: 147

Original Poster
Rep: Reputation: 15
Hello Mr C,

I am a layman in this field.
my find version is 4.1.2 and i am using RHEL 4 ES. Please give me required command which cleans all my print directory files (one more thing i forgot to tell you that these print directory folders contain some sub folders also, that folder 3days older files also to be moved to a specified directory.)

like /usr/mike/print/223/
/usr/mike/print/334/
/usr2/procter/print/


Thanking you.

nag

PS: do help me!

Last edited by visitnag; 09-13-2008 at 03:30 PM.
 
Old 09-13-2008, 05:11 PM   #14
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
Layman or expert, all are required to read man pages.

Did you check for -path in your version's man page? As I said in post 11, I'm not going to try to guess what predicates your version of find supports.

Regarding your sudden realization that the print directories might also contain sub-directories, we can move the entire directory with its contained files to the new location. But this will create a problem if later a same-named sub-directory is created. For example, if we mv /usr/mike/print/223 and its files to the backup directory, and then later another /usr/mike/print/223 directory is created, the mv in the find command will fail. So unless you are certain that the sub-directories names are never re-used, the find I gave above won't work. I hope you can see how important it is to be CLEAR about your own requirements!

As you've not pursued this question in a very speedy manner, I'll await your responses before spending more time providing alternative solutions.

Last edited by Mr. C.; 09-13-2008 at 05:12 PM.
 
Old 09-15-2008, 12:27 PM   #15
visitnag
Member
 
Registered: Mar 2008
Posts: 147

Original Poster
Rep: Reputation: 15
my find version is 4.1.2

Last edited by visitnag; 09-15-2008 at 12:34 PM.
 
  


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
Move directory of files siva19185 Linux - Newbie 3 07-02-2008 02:59 AM
Need to create a script to move files from one directory to another mustang05 Solaris / OpenSolaris 4 06-16-2006 10:25 AM
loop move files up one directory level Melsync Programming 8 12-19-2005 10:51 PM
how to write a script to move files from one directory to another myeire Linux - Newbie 7 02-25-2005 10:01 AM
Does anyone know how to move files to a particular directory using shell scripting RowanB Programming 3 11-11-2004 01:46 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 05:50 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