0

Suppose I have 3 directories dir1, dir2, dir3. I want to touch 3 identical files (f1.txt, f2.txt, f3.txt) in each of the directories.

How can I do that with one command?

dir1/
    f1.txt
    f2.txt
    f3.txt

dir2/
    f1.txt
    f2.txt
    f3.txt

dir3/
    f1.txt
    f2.txt
    f3.txt
1
  • Avoid using - as a prefix to Linux filenames Commented Nov 1 at 9:20

2 Answers 2

3

Simply use curly braces around the directories and files when creating the files with touch

touch {dir1,dir2,dir3}/{f1.txt,f2.txt,f3.txt}

Also see this question

touch command create multiple files (different names) under one directory

Sign up to request clarification or add additional context in comments.

Comments

1

I'm not sure I understand your question;

If you just need to create those 9 files in one command, simply use

touch dir1/f1.txt dir1/f2.txt dir1/f3.txt dir2/f1.txt ...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.