bashoneliners.com

Welcome to bashoneliners.com, a curated collection of practical and well-explained Bash one-liners, snippets, tips and tricks. We aim to make each published one-liner to be of high quality: useful, easy to read, follows best practices, with clear, detailed, accurate explanation. These one-liners should help you automate tasks, troubleshoot problems, whether it be in system administration, file management, networking or programming.

Run multiple commands chained with && and || using a single sudo

sudo -s <<< 'apt update -y && apt upgrade -y'

October 27, 2019secure-debian

Delete all untagged Docker images

docker images -f dangling=true -q | xargs --no-run-if-empty docker rmi

June 15, 2018penguincoder

Extensive "cleanup" operations following "sudo yum upgrade"

sudo yum upgrade && for pkg in $(package-cleanup --orphans -q); do repoquery $(rpm -q $pkg --queryformat="%{NAME}") | grep -q ".*" && echo $pkg; done | xargs sudo yum -y remove && for pkg in $(package-cleanup --leaves --all -q); do repoquery --groupmember $pkg | grep -q "@" || echo $pkg; done

April 16, 2014openiduser143

Show the 10 largest open files

lsof / | awk '$7 > 1048576 { print $7 / 1048576 "MB", $9, $1 }' | sort -nu | tail

February 28, 2014cellojoe

Expire a user's password immediately

chage -d 0 USERNAME

April 23, 2012bashoneliners

List open files

lsof -n

March 2, 2012bashoneliners

Get the available space on a partition as a single numeric value

df /path/to/dir | sed -ne 2p | awk '{print $4}'

October 2, 2011bashoneliners

Change the label of a USB drive in Linux without a gui

sudo mlabel -i /dev/sdd1 ::NewLabel

August 5, 2011bashoneliners