Portal Home > Knowledgebase > Articles Database > i need help


i need help




Posted by Elmokadim, 01-03-2010, 11:09 AM
hello I have Folder contains more than 500,000 file I use it to delete these zip files "rm -rf *.zip" but i need something else to delete the files date I want delete all the files in 2008 plz help me

Posted by VIPoint, 01-03-2010, 11:14 AM
Do you mean that you want to delete the files that were created/last modified in year 2008?

Posted by Elmokadim, 01-03-2010, 11:16 AM
yes i need delete all file created/last modified in year 2008

Posted by VIPoint, 01-03-2010, 11:33 AM
find /var/log -mtime +60 -type f -exec rm -rf {} \; This command will do a search in /var/log for all files that were last modified 60 or more days ago and executes a recursive forced (-rf) remove (rm). The "{}" (curly braces) is the place holder for exec to use where it will put the name of the file, and the "\;" tells exec that's the end of the statement. Also, as a test you can replace the "rm -rf" with "ls -la" to get a list of all the files that would be removed. And, if you want to remove files with specific names or extensions use the "-name" argument. I am not sure about how to check about year.. Maybe you can replace 60 with number of days from today 2010 to 2008 i.e 368 so the command will now become find /var/log -mtime +368 -type f -exec rm -rf {} \; but I recommend to run this command first find /var/log -mtime +60 -type f -exec ls -al {} \; verify the result and then run the rm command. Also change the /var/log with your specified directory.

Posted by activelobby4u, 01-04-2010, 02:47 AM
If you need to delete the zip files and if you are getting the eror " too many arguments" , you can delete it in batches using regex rm -rf [a-k]*.zip - will delete all zip files starting a through k. If you need to search files from 2008, simply do this ls -al | awk '{print $3,$6}' | grep 2008 | awk '{print $1}'|xargs rm -rf

Posted by Elmokadim, 01-04-2010, 08:09 AM
i need delete all file in folder "/home/user/memo/" not delete all file in my server

Posted by VIPoint, 01-04-2010, 08:44 AM
ok Try this $ cd /home/user/memo/ $ ls >> /tmp/test $ for i in `cat /tmp/test`;do rm -rf $i; done

Posted by Elmokadim, 01-04-2010, 09:02 AM
i need all Command I do not know what exactly is this Command i need delete all file created/last modified in year 2008 in folder "/home/user/memo/" not delete all file in my server Please write the Command implementation so I will also tell me

Posted by VIPoint, 01-04-2010, 09:12 AM
ok Try this $ cd /home/user/memo/ /* Change directory and your CWD will be /home/user/memo */ $ ls >> /tmp/test /* This command will write all the files present in /home/user/memo to /tmp/test file $ for i in `cat /tmp/test`;do rm -rf $i; done /* This is a for loop. The variable i will take value from /tmp/test and it will delete the file using rm -rf " */ Only the files in /home/user/memo will be deleted. If you want me to do it then please send me a Pm and I will do it for you.

Posted by Elmokadim, 01-04-2010, 09:16 AM
i need delete all file created/last modified in year 2008 in folder not all file

Posted by VIPoint, 01-04-2010, 09:24 AM
find /home/user/memo/ -mtime +60 -type f -exec rm -rf {} \; This command will do a search in /home/user/memo/ for all files that were last modified 60 or more days ago and executes a recursive forced (-rf) remove (rm). The "{}" (curly braces) is the place holder for exec to use where it will put the name of the file, and the "\;" tells exec that's the end of the statement. Also, as a test you can replace the "rm -rf" with "ls -la" to get a list of all the files that would be removed. And, if you want to remove files with specific names or extensions use the "-name" argument. I am not sure about how to check about year.. Maybe you can replace 60 with number of days from today 2010 to 2008 i.e 368 so the command will now become find /home/user/memo/ -mtime +368 -type f -exec rm -rf {} \; but I recommend to run this command first find /home/user/memo/ -mtime +60 -type f -exec ls -al {} \; verify the result and then run the rm command.



Was this answer helpful?

Add to Favourites Add to Favourites    Print this Article Print this Article

Also Read
Apache Maximum Request (Views: 634)