1
2
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?
1
2
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?
1
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/%
2
For simple way to do it try.
touch $(cat filename.txt)
0
#!/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.
how would I specify the folder to create the files? – None – 2012-11-28T16:57:09.800
@user1860410: change the
touch $filename
totouch PATH/$filename
where PATH is an abolute or relative path to the folder. – RedGrittyBrick – 2012-11-29T14:23:10.197