Q. I’m new to Linux. We have a backup server and most our developer sftp or ftp and upload files to our server. I just need backup of last 4 weeks. So if I try to list or remove directory I get an error cannot remove directory.
So my question is why am I getting an "Argument list too long" error message when executing some commands in the shell?
A. Each command under Linux/UNIX accepts a parameter commonly known as command arguments (or args).
For example, the command cd /etc is considered as 1 command line arguments, namely, /etc. Some command can accept more than 2 argument and act on supplied args. For example cp command:
$ cp /etc/file1 /etc/file2 /etc/file3 /mnt/pen
cp command has total 4 command line arguments. The shell can hold a maximum of 131072 bytes for command line arguments. If you try to pass more than that number you will greeted with an error that read as follows:
Argument list too long
Remember each character requires one byte of storage.
How do I get rid of this problem while using rm / ls or any other shell command?
The best way to deal with this problem is to use wild cards. For example, just list a directory starting with a character:
$ ls a*
or
$ rm a*
You can also use for loop to deal with group of files:
for fileset in a b c d e f g h i j k l m n o p q r s t v w x z do /bin/rm $fileset* done
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop













{ 9 comments… read them below or add one }
How to find out who all user modified which files
how to allow telnet or ssh login from a specified ip to freebsd server and other to be denied
steps of Maintainence of a freebsd server and what all pre precaution need to be taken
What about for recursive copy??
just use:
ls|xargs rm
cheers
tom
Tom you genious! Gone through all the complex methods that didn’t work, and you use the most simple way. Thank you.
-bash: /bin/mv: Argument list too long
I am Getting th eavove error message while moving file from one dir to other.please help me to solve this problem.I hv root permission too.
How about this:
find . | xargs rm
It will wipe out just about anything.
ViVEk GITe, not agree with you. The wilcards in any shell enviroments are replaced before execute the comand line. For example:
$ touch a1 a2 a3 a4 a5 a6
$ ls a*
a1 a2 a3 a4 a5 a6
Will work fine, because the ‘a*’ is replaced before executing the ls command but the parameters list is not long enough. But, creating for example a extend list of files (10000 empty files), the ‘ls’ command will show you how the parameters list is too long even when you write ‘a*’ as the only parameter!!
See:
$ i=1
$ while [ $i -le 10000 ]; do
> touch a$i
> i=$((i+1))
> done
$ ls | wc -l
10000
$ ls a*
ksh: /usr/bin/ls: 0403-027 The parameter list is too long.
That is because the wilcard is replaced before executing ls + arguments command.
In that case I agree with Tom solution… ;)