Argument List Too Long Message in Linux
Posted by: kent in linux, tags: linux tip howto delete filesSo, you’ve filled up a directory with so many files that executing a rm -f * tells you Argument list too long. Now what? You can run this to remove the files in a directory too full to use rm -f *…
# Don't forget to execute this in the right directory!
cd /the-right-directory
# Let's preview what will get deleted just to be sure
find . -maxdepth 1 -name "*" -type f -exec echo {} \;
# OK, let's do thisfind . -maxdepth 1 -name "*" -type f -exec rm -v {} \;
What is this last find doing? The dot after find says to do this in the current directory, the -maxdepth 1 parameter says not to recurse into subdirectories, the -name "*" parameter says to match any file, the -type f parameter says to do this only on files, and the -exec xyz \; says to execute xyz for each file where xyz is a rm -v command with {} being the name of the current file.
Important: This is doing a permanent wildcard delete in a directory. Double check you understand what you are doing before you execute this command.
Bookmark at:StumbleUpon | Digg | Del.icio.us | Dzone | Newsvine | Spurl | Simpy | Furl | Reddit | Yahoo! MyWeb
Entries (RSS)
I had the same issue a few mounths ago, this is what I came up with as a quick fix:
#!/bin/bash
locate “avant-window-navigator awn-manager > files.txt”
rm -Rv `files.txt`
./awn.sh
locate can be replaced with any other way to gather a large list of files.
You can also try this :
ll | xargs rm -drv
Much simpler
and also :
find . -maxdepth 1 -name “*” -type f -delete
All nice tips. Thanks.