Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

migrated from stackoverflow.com Nov 29 '12 at 14:05

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

3 Answers

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
add comment

For simple way to do it try.

touch $(cat filename.txt)
share|improve this answer
add comment
#!/bin/bash

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
add comment

Your Answer

 
discard

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.