I need to add one file to about 7 different directories. I'm using Fedora 24... I know I need to use the touch command but what parameters will I need?
Asked
Active
Viewed 74 times
1
-
2`touch {dir1,dir2,...,dir7}/file` – muru Nov 28 '16 at 16:24
-
Although the command works the same in Ubuntu, keep in mind this site is called AskUbuntu so you shouldn't use the word `Fedora` in your question. – WinEunuuchs2Unix Nov 28 '16 at 16:30
-
@muru just post it as answer, why leave it as comment ? – Sergiy Kolodyazhnyy Nov 28 '16 at 16:55
-
Cody, just out of curiosity, why did you come Ubuntu site if you are using Fedora ? – Sergiy Kolodyazhnyy Nov 28 '16 at 16:56
-
1Possible duplicate of [How to copy a file to multiple folders using the command line?](http://askubuntu.com/questions/432795/how-to-copy-a-file-to-multiple-folders-using-the-command-line) – Sergiy Kolodyazhnyy Nov 28 '16 at 16:58
2 Answers
3
Use brace expansion in bash:
touch {dir1,dir2,dir3,dir4,dir5,dir6,dir7}/file
If the directories are named after a pattern, you might even be able to generate that. For example, if the directories were actually named like on the command above:
touch dir{1..7}/file
muru
- 193,181
- 53
- 473
- 722
2
If directories are different use this:
touch {d1,d2,d3,d4,d5,d6,d7}/file_name
Or you can use this one:
touch dir{1..7}/file_name
This command creates file in dir1, dir2, ... dir7 respectively.
muru
- 193,181
- 53
- 473
- 722
Maksim Garkavenkov
- 51
- 3