Linux - DesktopThis forum is for the discussion of all Linux Software used in a desktop context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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..
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".
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.
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
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?
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 ....
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.
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.
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.)
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/
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.