🖥️mkdir

➡️This is a command-line reference manual for commands and command combinations that you don’t use often enough to remember it. This cheatsheet explains the mkdir command with important options and switches using examples.

▁ ▂ ▃ ▄ ꧁ 🔴☠ COMMANDLINE-KUNGFU WITH CHEATSHEETS ☠🔴꧂▅ ▃ ▂ ▁

 #               ███╗   ███╗██╗  ██╗██████╗ ██╗██████╗ 
 #               ████╗ ████║██║ ██╔╝██╔══██╗██║██╔══██╗
 #               ██╔████╔██║█████╔╝ ██║  ██║██║██████╔╝
 #               ██║╚██╔╝██║██╔═██╗ ██║  ██║██║██╔══██╗
 #               ██║ ╚═╝ ██║██║  ██╗██████╔╝██║██║  ██║
 #               ╚═╝     ╚═╝╚═╝  ╚═╝╚═════╝ ╚═╝╚═╝  ╚═╝
                                                      
                                                      
# Create a directory and all its parents
mkdir -p foo/bar/baz

# Create foo/bar and foo/baz directories
mkdir -p foo/{bar,baz}

# Create the foo/bar, foo/baz, foo/baz/zip and foo/baz/zap directories
mkdir -p foo/{bar,baz/{zip,zap}}

#==============================#
# CMD MKDIR 
#==============================##==============================#
mkdir -p foo/bar
# Make directories more than one level deep in one command

mkdir dir && cd $_
# Create a directory and change into it

mkdir -p /var/lib/libvirt/images/vm1archer/mytemplates/libvirt
#

mkdir fun; touch fun/{R,r}{E,e}{A,a}{D,d}{M,m}{E,e};echo hello >fun/rEadME;zip -r fun\.zip fun
# Send those new Windows bash users a gift.

# Running a second command with the same arguments as the previous command, use '!*' to repeat all arguments or '!:2' to use the second argument. '!$' uses the final argument.
cd /home/user/foo
	cd: /home/user/foo: No such file or director	y
mkdir !*
mkdir /home/user/foo

sudo mkdir /mnt/sd{b..e}{1..9} 
# Make a bunch of mount point directories all at once. All combos of sdb1 through sde9 inclusive.

mkdir /usr/local/src/bash/{old,new,dist,bugs}

# Try the following to create the above example of a very complex directory structure in a subfolder of ~/testdir instead of /
mkdir -p ~/testdir/{bin,sbin,home/{jane,will/{work,play},zeb},tmp,lib,usr/{bin,lib},var} 

mkdir -p /home/{a,b}

mkdir -p /home/{a/{a1,a2,a3},b/{b1,b2,b3} 

mkdir -p /tmp/a/b/c && cd $_ 
# $_ is a shell special variable that expands to the last argument given in the prev command. There are other ways too to reference the last arg. The document http://bit.ly/1tgtnM5  explains the differences between $_, !$ and Meta+.

mkdir PNG && find . -maxdepth 1 -name '*.svg' | while IFS=$'\n' read f ; do inkscape "$f" --export-png="PNG/${f%%.svg}.png"; done 
# SVG 2 PNG in CWD. Using Inkscape's command line functionality to convert SVG documents into PNG images. GUI CLI FTW!

mkdir {dir1,dir2}/{sub1,sub2} 
# which makes dir1 and dir2, each containing sub1 and sub2)

mkdir [[folder]] && cd $_
# Create and access directory at the same time

	
# Organise image by portrait and landscape
mkdir "portraits"; mkdir "landscapes"; for f in ./*.jpg; do WIDTH=$(identify -format "%w" "$f")> /dev/null; HEIGHT=$(identify -format "%h" "$f")> /dev/null; if [[ "$HEIGHT" > "$WIDTH" ]]; then mv "$f" portraits/ ; else mv "$f" landscapes/ ; fi; done
# Explanation: 
    # First makes directory for portraits and landscapes
    # Loops through all files in the current directory with the extention .jpg, feel free to change this to .png or .jpeg if neccesary
    #     Gets the width and height for the current image using the identify command
    #     If height > width, move it to Portarits folder, otherwise move it to landscapes
# Limitations: This relies on the identify command which comes with ImageMagick which is available on most systems. This does not check for square images, although it could be easily extended to see if HEIGHT and WIDTH are equal. Square images are currently put with the landscape images.

mkdir -p /path/folder{1..4}
# Create multiple subfolders in one command.

mkdir -p /path/{folder1,folder2,folder3,folder4}
# Create multiple subfolders in one command. Instead of typing separate commands to create various subfolders, we can create multiple subfolders by listing them between brackets and separated by commas. Show Sample Output:

        # /path/folder1
        # /path/folder2
        # /path/folder3
        # /path/folder4

# Move all *mp4 files into their own folder
for file in mp4; 
  do 
        folder=`echo $file | cut -d'-' -f1 | rev | cut -b 2- | rev`;
        mkdir $folder;
        mv -v $file $folder;
  done

#==============================##==============================#
# CMD MKDIR						       #
#==============================##==============================#
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

  █║▌│║█║▌★ KALI ★ PARROT ★ DEBIAN 🔴 PENTESTING ★ HACKING ★ █║▌│║█║▌

              ██╗ ██╗ ██████╗  ██████╗ ██╗  ██╗███████╗██████╗
             ████████╗██╔══██╗██╔═══██╗╚██╗██╔╝██╔════╝██╔══██╗
             ╚██╔═██╔╝██║  ██║██║   ██║ ╚███╔╝ █████╗  ██║  ██║
             ████████╗██║  ██║██║   ██║ ██╔██╗ ██╔══╝  ██║  ██║
             ╚██╔═██╔╝██████╔╝╚██████╔╝██╔╝ ██╗███████╗██████╔╝
              ╚═╝ ╚═╝ ╚═════╝  ╚═════╝ ╚═╝  ╚═╝╚══════╝╚═════╝

               █║▌│║█║▌ WITH COMMANDLINE-KUNGFU POWER █║▌│║█║▌

░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░