A collection of handy shell commands

A collection of shell commands I use to get things done in a snap (or close to)

find . -mindepth 2 -maxdepth 2 -type f -execdir mv -i -v {} .. \;

This command basically moves all files two directories deep up one level. Handy if a WordPress media library structure has changed and you have a lot of files to reorganise. The -i flag prompts you for confirmation where a file would be overwritten.

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

This command will find and delete all directories (along with anything in them) two directories below the current.

aws s3 sync s3://my-bucket-name . --profile my-profile-name

This command will sync an entire Amazon S3 bucket to the current directory on your local using the AWS CLI tool kit. The --profile flag allows you to specify AWS credentials saved to your ~/.aws/credentials file under a particular profile name.

du -ah /some/dir | sort -n -r | head -n 100

This command will list the largest 100 files and directories within the specified directory tree along with their file size.

du -cks -- * | sort -rn | head

This command will find and list the top 10 files and directories using the most disk space.