1

I need to run something like

mkdir /var/log/apache2/www/custom-name/ 

The problem is if some of directories in path are missing. Shell does not create missing directories but throws me an error. Is it possible to make missing directories in the path without testing if it exists?

Čamo
  • 3,863
  • 13
  • 62
  • 114
  • 2
    Unix.SE: [How to create nested directory in a single command?](https://unix.stackexchange.com/questions/84191/how-to-create-nested-directory-in-a-single-command) – John Kugelman Jan 14 '21 at 00:14
  • 2
    Does this answer your question? [mkdir's “-p” option](https://stackoverflow.com/questions/22737933/mkdirs-p-option) – John Kugelman Jan 14 '21 at 00:17

1 Answers1

2

If I understood the question, yes, it is.

In your case, instead of specifying

mkdir /var/log/apache2/www/custom-name/ 

write

mkdir -p /var/log/apache2/www/custom-name/ 

The -p flag enables the creation of parent directories. It should run without any error. (Reference 1 and 2)

nunohpinheiro
  • 2,169
  • 13
  • 14
  • Yes it works but what if I need also to set up chown for the path directories? Parent directories have current user as owner. I dont want to use chown -R cause there could be more directories. Is it possible to use chown onlz for directories in path? – Čamo Jan 14 '21 at 00:24