Create empty files from a list on file

Hello Guys.

Please I would like to create empty files from a list

In file1 will be the followin values, so i will like to create for each name a empty file.
file1

2191off-r0.sps
2192off-r0.sps
2193off-r0.sps
2194off-r0.sps
2195off-r0.sps

So I need to get 5 empty files.

Thanks for your help :b:

use touch command

To extend on raj's suggestion, try a while read loop:

while read file; do
  touch "$file"
done < file1

Hi Scrutinizer...
(Longhand using OSX 10.7.5, default bash terminal.)

What is wrong with this method:-

Last login: Sat Nov 16 15:01:56 on ttys000
AMIGA:barrywalker~> echo "2191off-r0.sps
> 2192off-r0.sps
> 2193off-r0.sps
> 2194off-r0.sps
> 2195off-r0.sps" > /tmp/file
AMIGA:barrywalker~> while read filenames; do > /tmp/$filenames; done < /tmp/file
AMIGA:barrywalker~> ls -l /tmp/219*
-rw-r--r--  1 barrywalker  wheel  0 16 Nov 15:03 /tmp/2191off-r0.sps
-rw-r--r--  1 barrywalker  wheel  0 16 Nov 15:03 /tmp/2192off-r0.sps
-rw-r--r--  1 barrywalker  wheel  0 16 Nov 15:03 /tmp/2193off-r0.sps
-rw-r--r--  1 barrywalker  wheel  0 16 Nov 15:03 /tmp/2194off-r0.sps
-rw-r--r--  1 barrywalker  wheel  0 16 Nov 15:03 /tmp/2195off-r0.sps
AMIGA:barrywalker~> _

Surely this would be quicker as the touch command is not being executed...
Or am I missing something?

1 Like

Nothing, you are right, using > would be more efficient than using touch .

1 Like

Thanks to all for you:b:r help

What about

touch $(< file)
-rw-r--r-- 1 c c    0 Nov 16 19:49 2191off-r0.sps
-rw-r--r-- 1 c c    0 Nov 16 19:49 2192off-r0.sps
-rw-r--r-- 1 c c    0 Nov 16 19:49 2193off-r0.sps
-rw-r--r-- 1 c c    0 Nov 16 19:49 2194off-r0.sps
-rw-r--r-- 1 c c    0 Nov 16 19:49 2195off-r0.sps

, as touch may have many parameters (up to LINE_MAX?)...

That would work as long as there are not too many files and line length limitations would not be exceeded. Also this would not work with files with spaces for example because of field splitting.

1 Like