About Linux FAQ

Browse More FAQs:

Linux / UNIX : Argument list too long error in shell and solution

Posted by Vivek Gite [Last updated: May 4, 2007]

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

Subscribe to our free e-mail newsletter or RSS feed to get all updates. You can Email this page to a friend.

Related Other Helpful FAQs:

Discussion on This FAQ

  1. vinod Says:

    How to find out who all user modified which files

  2. vinod Says:

    how to allow telnet or ssh login from a specified ip to freebsd server and other to be denied

  3. vinod Says:

    steps of Maintainence of a freebsd server and what all pre precaution need to be taken

  4. Deepak Says:

    What about for recursive copy??

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Copyright © 2006-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.