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.

Copy or create files with specific permissions and ownership

install -b -m 600 /dev/null NEWFILE

September 25, 2012bashoneliners

Redirect stdout to a file you don't have write permission on

echo hello | sudo tee -a /path/to/file

September 11, 2012bashoneliners

Execute different commands with find depending on file type

find /path/to/dir -type d -exec chmod 0755 '{}' \; -o -type f -exec chmod 0644 '{}' \;

June 17, 2012bashoneliners