Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have several files in a directory like:


To run another code, I need to have a text file with the names of the files but I need to split in 50 files per text file, like: File1.txt :


File2.txt :


any idea?? I was trying like:

ls -1 | xargs -n 50 >> File1.txt

but I don't know who to select each "item" in the xargs command. Thanks!!

share|improve this question
up vote 3 down vote accepted
ls -1 | split --lines=10

puts the files in the same directory. This can be avoided by

ls -1 | (cd /where/ever; split --lines=10)

or for a different file name:

ls -1 | split --lines=10 /dev/stdin /path/to/splitfile.
share|improve this answer
THANKS!!! and how can I change the name of the text files? – Alejandro Apr 4 '14 at 22:45
@Alejandro I added that but that information was already in Graeme's answer. – Hauke Laging Apr 4 '14 at 23:12

Try this (uses GNU split which is default on most Linux distros):

ls |
  sed "s:^:$(pwd)/:" |
  split -dl 50 --additional-suffix=.txt - /path/to/dest/File
share|improve this answer
I got this error: split: unrecognized option `--additional-suffix=.txt' – Alejandro Apr 4 '14 at 22:53
@Alejandro If it is not supported, just remove that option. The effect will just be that the files don't have the .txt extension. – Graeme Apr 4 '14 at 22:55
The -d may not be supported on some systems also, this gives numbered files instead of aa, ab, etc. The rest is POSIX though. – Graeme Apr 4 '14 at 22:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.