This Blog is intended to collect information of my various Intrests,pen my opinion on the information gathered and not intended to educate any one of the information posted,but are most welcome to share there view on them

Monday, June 20, 2011

How to Delete a Big Number of Files in a Folder

If you’re using temporary files you should notice that after some time it is hard to delete them as their number is growing. If you have many files and try to delete them with a usual command rm -f you should receive something like this:

[root@server html]# rm -f *
-bash: /bin/rm: Argument list too long

OR

In our case (Number of files in the folder is around 1 million ) if we run ls or other command, linux shell prompt hung and we need to start new terminal.

What to do when this occurs? You have to combine several Linux commands in order to empty this folder. Here is the command you should use; I will explain what does it do below.

[root@server html]# ls | grep .| xargs rm

This will do the following: the first command ls outputs the list of files. The output is being sent to grep command so you won’t see it in your console. Grep searches for files with “.” symbol (in the example given I think that all your files have so named extension – filenames contain a dot. So grep will extract all the file names that contain a dot and will throw them to the next function – xargs. xargs accepts these filenames and deletes them one by one. This allows to reduce server load and gives us the possibility to delete multiple files in one folder that are no longer necessary.

Redmi 4

About Me

Hi This is Suresh Kumar Pakalapati . I am a person who is positive about every aspect of life. There are many things I like to do, to see, and to experience. I like to feel the music flowing on my face, I like good books and romantic, action,cartoon movies. I like the land and the nature, And, I like to keep smile on my face. I always wanted to be a great and successful person in the world and I know it is needed More and More education, More work, Success Never come in a short Time.....