S
S
Sergey Burduzha2020-08-18 08:29:58
bash
Sergey Burduzha, 2020-08-18 08:29:58

How to create multiple files in the same directory with touch in bash terminal?

There is an app-search directory.
I need to create app-search.js and app-search.scss files inside.
I registered the command touch app-search/{app-search.js, app-search.scss}
But, 2 files with curly braces were created.

And is it possible to register a command in the terminal to create a directory and the necessary files in it?

Thanks in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
H
Hanneman, 2020-08-18
@serii81

Actually, your original method also works, just remove the spaces.
touch app-search/{app-search.js,app-search.scss}
You can do it like this, for example:

touch app-search/app-search.js, app-search/app-search.scss

Or like this:
cd /path/to/app-search; touch app-search.js, app-search.scss

Well, in other ways - for example, a list of files in a file and go through a loop:
Place the following text in a static file (for example, /tmp/list):
/path/to/app-search/app-search.js
/path/to/app-search/app-search.scss

Create a file, for example touch_my_files.sh and put the following Grant permissions: Call
for i in `cat /tmp/list`; do touch $i; done;
chmod +x touch_my_files.sh
./touch_my_files.sh

S
SOTVM, 2020-08-18
@sotvm

parentheses are not needed
the path directory must exist
if the path/name contains spaces, then we put it in quotation marks
touch 'path/file 1' 'path/file 2'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question