Argument list too long

When you try to do any operation in unix (eg. tar, mv, cp) that involves too many arguments (or filenames), then you might get an “Argument list too long” error.

Here’s a solution:

1. Create a file with all the arguments (or filenames).

ls -1 > filenames.txt

2. Use xargs command to read in the file and pipe it into the unix command you’re executing.

xargs -a filenames.txt mv -t /otherfolder/.

There are several ways around this. You can also write a for loop in a script and some commands let you use a file as arguments.
For example, the tar command can be executed as

tar -cvzf archive.tar.gz --files-from filenames.txt
Advertisements
Tagged

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: