SmelayaPanda
SmelayaPanda

Reputation: 159

MacOS Command Line - Create folder with files at once

Is it possible to write a command that will create a new directory with name passed as argument 'MyFolder' (for example) and will create four files with the same name (as part):

  1. MyFolder.js
  2. MyFolder.css
  3. MyFolder.test.js
  4. README.md

(using mkdir / touch / echo ...)

Main problem - one line command

Upvotes: 1

Views: 584

Answers (2)

Gordon Davisson
Gordon Davisson

Reputation: 125788

Try this:

populate_dir() { mkdir "$1"; touch "$1/$1".{js,css,test.js} "$1/README.md"; }
populate_dir MyFolder

Upvotes: 1

Samuel
Samuel

Reputation: 3801

This one-liner function should do the work:

$ function mkdir_and_files() { mkdir "${1}"; touch ${1}/${1}.js; touch ${1}/${1}.css; touch ${1}/${1}.test.js; touch ${1}/README.md; }; mkdir_and_files "MyFolder" ;

$ ls -latrh MyFolder/
total 0
drwxrwxrwt  15 root           wheel   480B Aug 19 18:58 ..
-rw-r--r--   1 user  wheel     0B Aug 19 18:58 MyFolder.js
-rw-r--r--   1 user  wheel     0B Aug 19 18:58 MyFolder.css
-rw-r--r--   1 user  wheel     0B Aug 19 18:58 MyFolder.test.js
-rw-r--r--   1 user  wheel     0B Aug 19 18:58 README.md
drwxr-xr-x   6 user  wheel   192B Aug 19 18:58 .

Upvotes: 1

Related Questions