How to create directories from a text file

GNU/Linux

I have a list of directories in a text file as shown below.

gnu linux/debian
gnu linux/ubuntu
cms
commands
editors/vim
editors/geany
games
nosql
unix

Q. Can I create directories from the previous text file?

A. Yes, you can use the xargs command.

$ xargs-I {} mkdir-p "{}" < dirs.txt

The above command will create the following structure of directory in the current directory.

.
├── cms
├── commands
├── dirs.txt
├── editors
│ ├── geany
│ └── vim
├── games
├── gnu linux
│ ├── debian
│ └── ubuntu
├── nosql
└── unix

Further reading

  • man xargs



Leave a Comment

Your email address will not be published. Required fields are marked *