Reputation: 557
I searched the Internet, but maybe I used the wrong keyword, but I couldn't find the syntax to my very simple problem below:
How do I redirect a file as command line arguments to the Linux command "touch"? I want to create a file with "touch abc.txt", but the filename should come from the filename "file.txt" which contains "abc.txt", not manually typed-in.
[root@machine ~]# touch < file.txt
touch: missing file operand
Try `touch --help' for more information.
[root@machine ~]# cat file.txt
abc.txt
Upvotes: 1
Views: 913
Reputation: 54563
Alternatively, if you have multiple filenames stored in a file, you could use xargs
, e.g.,
xargs touch <file.txt
(It would work for just one, but is more flexible than a simple "echo").
Upvotes: 1
Reputation: 59250
Try
$ touch $(< file.txt)
to expand the content of file.txt
and give it as argument to touch
Upvotes: 5