Home > Back-end >  create multiple folders with files inside with bash scripts
create multiple folders with files inside with bash scripts

Time:11-16

It's possible to create this file structure with one line of code in bash?

├── assets
│   ├── css
│   │   └── index.css
│   ├── js
│   │   └── index.js
│   └── images

CodePudding user response:

mkdir -p assets/{css,js,images}; touch assets/{css/index.css,js/index.js}

CodePudding user response:

Other option with install:

$ tree
.
0 directories, 0 files

$ for i in assets/{{css/index.css,js/index.js},images}; do
  [[ $i == "assets/images" ]] && (install -d "$i"||:) || install -D /dev/null "$i"
done

$ tree
.
└── assets
    ├── css
    │   └── index.css
    ├── images
    └── js
        └── index.js

4 directories, 2 files

one line:

for i in assets/{{css/index.css,js/index.js},images}; do   [[ $i == "assets/images" ]] && (install -d "$i"||:) || install -D /dev/null "$i"; done
  •  Tags:  
  • bash
  • Related