Quickly Create Multiple Directories And Files With Common Terms Using Linux Command Line


Creating multiple files and directories that have common terms or patterns can be done quickly from the Linux command line. For this, the braces {} are useful.

Multiple directories with common terms:

Example: To create directories named DailyReport2020, WeeklyReport2020, QuarterlyReport2020, MonthlyReport2020 and YearlyReport2020, there is no need to use mkdir command separately for each of them.

Instead, put the common term (“Report” or “ly” and “Report” both in this example) outside the braces and include the other non-common terms inside the braces.

So, a single line command can make these multiple directories in one go :

mkdir {Daily,Weekly,Quarterly,Monthly,Yearly}Report2020

using braces for creating multiple directories from Linux command line-1

Or

mkdir {Dai,Week,Quarter,Month,Year}lyReport2020

using braces for creating multiple directories from Linux command line-2

Multiple files with common terms:

Similarly, to create files with common patterns (e.g: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday), the one line command will be :

touch {Mon,Tues,Wednes,Thurs,Fri,Satur,Sun}day.txt

using braces for creating multiple files from Linux command line

This will quickly create these files using braces.

Listing files and directories:

Also, if you’d like to distinguish between files and directories when listing them from the Linux command line, the -F parameter with ls is helpful instead of the plain ls command.

ls -F

Directories will have a slash next to them while the files won’t.

difference between ls and ls -F command for listing files and directories using Linux command line

This can be a timesaver when trying to view the contents of a folder or directory that has a lot of items in it. You can also set it is an alias for ls. Here is how to do that.

A list of files and directories displayed using the ls -F command

All done.


Leave a Comment