BASH Directories

From Indie IT Wiki

Delete Only Directories

find . -maxdepth 1 -mindepth 1 -type d -exec rm -rf '{}' \;

Create Multiple

mkdir {01..12}

List Directories By Last Modified Date

ls -t

Of if you want to do it in reverse:

ls -tr

Reproduce Directory Structure Sans Contents

Copy the file structure:

find . -type d -print0 >dirs.txt and 

Reproduce the file structure:

xargs -0 mkdir -p <dirs.txt

This will work for folder structures that have spaces in the names.

Thanks to Stackoverflow.com.

Show Size Of Directories

Sorted by time...

du --time -s */ |sort -k 2

Sorted by size..

du --time -s */ |sort -k 1 -h

Test If A Directory Exists

test -d /path/to/directory

You can use this to make sure a directory exists before copying or moving a file into it.

test -d /mnt/usb/backup && mv /home/website/backup-20140901.zip /mnt/usb/backup/