//Tips tagged mkdir
Latest tips by RSS
Click here to subscribe
Follow Shell-Fu on Twitter
Click here to follow
Follow Shell-Fu on identi.ca
Click here to follow
Use the -p option to mkdir and make all parent directories along with their children in a single command.
mkdir -p tmp/a/b/c
Save time when making multiple files or directories (or performing any command requiring a list) where the file names only slightly differ.
$ ls
$ touch tst{1,2,3,4,5}.txt
$ ls
tst1.txt tst2.txt tst3.txt tst4.txt tst5.txt
$ mkdir dir{1,2,3}
$ ls
dir1 dir2 dir3 tst1.txt tst2.txt tst3.txt tst4.txt tst5.txtThe following command creates in the /usr/project directory, a copy of the current working directory structure:
find . -type d -print|sed 's@^\.\{0,1\}@/usr/project@' | sed 's/ /\\ /' | xargs mkdir -pSeen on http://www.splitbrain.org/blog/2008-02/27-keeping_your_home_directory_organized
Having one temporary directory for downloads etc can quickly become a mess, so try this tip to organise by date. Put this into your .bashrc
You'll receive a new function 'td' for making temp-dirs under $HOME/temp/ named by date. It is also possible to switch days back with 'td -[n]', i. e. 'td -3' which means '3 days back from now'.
Having one temporary directory for downloads etc can quickly become a mess, so try this tip to organise by date. Put this into your .bashrc
export TD="$HOME/temp/`date +'%Y-%m-%d'`"
td(){
td=$TD
if [ ! -z "$1" ]; then
td="$HOME/temp/`date -d "$1 days" +'%Y-%m-%d'`";
fi
mkdir -p $td; cd $td
unset td
}
You'll receive a new function 'td' for making temp-dirs under $HOME/temp/ named by date. It is also possible to switch days back with 'td -[n]', i. e. 'td -3' which means '3 days back from now'.

