Create multiple files and name them from command line

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?

3 Answers

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/%

0

For simple way to do it try.

touch $(cat filename.txt)
#!/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.

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like