Let’s say you want to make a directory tree in Linux a few directories deep. You could do this:greg@greg-laptop:~$ mkdir tstgreg@greg-laptop:~$ cd tstgreg@greg-laptop:~/tst$ mkdir tstdeepergreg@greg-laptop:~/tst$ cd tstdeepergreg@greg-laptop:~/tst/tstdeeper$ mkdir evendeepergreg@greg-laptop:~/tst/tstdeeper$ cd evendeepergreg@greg-laptop:~/tst/tstdeeper/evendeeper$
Or, you could be smart and do this:greg@greg-laptop:~$ mkdir -p tst/tstdeeper/evendeeper
Notice the -p option.
For the record, Windows does this magically — without the need for -p.Just saying.
On the other hand, windows doesn’t let you use ‘?’ or several other characters.
Yet another major security hole in windows exposed!
The other nice thing about -p is that it doesn’t complain if the target exists. This makes it very useful in situations where you want to ensure a directory is there and you don’t want to deal separately with the case where it is vs. the one where it isn’t.
Beware the power of xargs.sed -e ‘s/(.)//1/g’ -e ‘s/^/words/’ /usr/dict/words | xargs mkdir -p