Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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 need to create 300 blank files and put them in a folder on my server then name them from a list in a txt file, I have SSH access, so is it possible to do this using command line?

share|improve this question

migrated from Nov 29 '12 at 14:05

This question came from our site for professional and enthusiast programmers.

up vote 1 down vote accepted

You can use xargs for this:

xargs -a file_list.txt touch

This supplies each line of the text file as the parameter to touch. There's no point in creating the files first, might as well just create the outright with the correct name from your text file.

If you wish to output to an arbitrary directory, eg PATH then try:

cat file_list.txt | xargs -I % touch PATH/%

share|improve this answer

For simple way to do it try.

touch $(cat filename.txt)
share|improve this answer

while read filename; do
  touch $filename
done < filename.txt

This will iterate over each line of filename.txt and create empty file with name in the current line.

share|improve this answer
how would I specify the folder to create the files? – user1860410 Nov 28 '12 at 16:57
@user1860410: change the touch $filename to touch PATH/$filename where PATH is an abolute or relative path to the folder. – RedGrittyBrick Nov 29 '12 at 14:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .