-1

When I try to tar all the file in a folder using fowing command:

tar cvf mailpdfs.tar *.pdf

The shell complains:

ksh: /usr/bin/tar: 0403-027 The parameter list is too long.

How to deal with it? My folder contain 25000 pdf files, each file is 2MB in size, how can I copy them very fast?

  • 1
    Possible duplicate of [Argument list too long error for rm, cp, mv commands](https://stackoverflow.com/q/11289551/608639), [Unix cp argument list too long](https://stackoverflow.com/q/5892339/608639), etc. – jww Oct 17 '19 at 06:47

2 Answers2

1

You can copy/move all the pdf files to a newfolder and then tar the newfolder.

mv *.pdf newfolder

tar cvf mailpdfs.tar newfolder

Referenced from unix.com

1

The tar option -T is what you need

   -T, --files-from=FILE
          get names to extract or create from FILE 

You are blowing the limit for file globbing in ksh, so you can generate the list of files like this

ls | grep '\.pdf$' >files.txt

Then use that file with tar

tar cvf mailpdfs.tar -T files.txt

Finally, you can do away with creating a temporary file to hold the filenames by getting tar to read them from stdin (by giving the -T option the special filename -).

So we end up with this

ls | grep '\.pdf$' | tar cvf mailpdfs.tar -T -
pmqs
  • 3,066
  • 2
  • 13
  • 22
  • [Why *not* parse `ls`?](http://unix.stackexchange.com/questions/128985/why-not-parse-ls) – Cyrus Oct 17 '19 at 16:48
  • In this way, special characters in the file name are no longer a problem: `find . -maxdepth 1 -name "*.pdf" -print0 | tar --null -cf mailpdfs.tar -T -` – Cyrus Oct 17 '19 at 16:48