Hi All,
I am trying to delete Files from a directory using the below command
find $/test/abc/xyz -mtime +30 -exec rm -f {} \;
The above command is deleting the files more than 30 days.
The problem is there are some subdirectories in xyz,
when i execute the above command its trying to delete the direcotires as well,
however its not having permission to do so, its giving an error saying
"No permission to delete the direcotry", So i am saved.
Is there a way i can exculde touching the directories and just delete the files.
Thanks in advance
If I read your question correctly, you have files in the subdirectories that you do want to be deleted, but don't want to try to remove the directories themselves. If that is correct then try:
which will only result in a true evaluation if the file is a regular file.
If you don't want to remove files in any directory below the current directory you'll need to add other options to the find.
Regardless, before running commands which remove things, it's always good form to test it with a harmless command:
Shows you what the command would do and if you are sure that the command will only delete the things you want removed, then you can remove the echo and execute the command. This practice has saved my butt many times from having to recover files from backup because I fat fingered something in the command.
If the number of directories is small, you can hard code them with the prune option which will skip processing the directories and their contents. This example does not do anything with files in the foo or bar directories:
If you have more than a couple, you may be better off using the -group or -user flags to control which files are deleted. Check out the manual page for find -- it has useful examples and lists all of your options.
Is there a way via some bash script or just cmd to find duplicate directories?
i have main folders:
TEST1
TEST2
In folder TEST1 is some amount of same folders as in folder TEST2
can be this done? i tried fdupe but it only search for dupe files not whle dirs
thx! (8 Replies)
Hello,
I'm trying to figure out how best to approach this script, and I have very little experience, so I could use all the help I can get. :wall:
I regularly need to delete files from many directories.
A file with the same name may exist any number of times in different subdirectories.... (3 Replies)
Hello All,
My shell script runs everyday to update certain database. Everytime the script runs it creates a directory, with "current date". These directories contain log and data files:
HOME_DIR/database_name/20120417/*
HOME_DIR/database_name/20120416/*... (6 Replies)
Hi,
I have a requirement like,
I need to create the directory with date and time stap (i.e YYYYMMDDHMS) every day end need to delete the old directories which is 12 months old. I have tested with following script
cd /export/home/sbeeravo/; find . -type d -mtime +365 -exec rm -rf {} \;
... (2 Replies)
Hi
I have 10 directories.I want to delete all the dicrectories except the three recent directories based on timestamp.I am new to BASH can u help me? (1 Reply)
hi im so sorry i do not have time im doing an urgent cleanup.
I have to check on directories for example:
/export/home/itbr
/export/home/bscsmig
there are more but i have the list. how do i write a ksh script in for loop to check those directories and delete display a message if it was... (1 Reply)
I have a script that deletes obselete users from /etc/passwd then moves their home directories to another location. After 30 days, I need to delete the home directories that were moved to the new location. I would appreciate any ideas on how to delete the directories after the 30 days? (2 Replies)
Hello,
I need a hand with a script im trying to make. I have a directory
/usr/db/mail with a bunch of subdirectories such as
/usr/db/mail/domain1.com
/usr/db/mail/domain2.com etc. etc.
all of these directories in turn have sub directories of their own. What I need to do is search all of... (1 Reply)