< BACK
Bash tips, tricks and code snippets
- Bash function to pretty-print JSON
- Bash oneliner to block script kiddies
- Bash tip: Remove leading zeros from a variable
- Command line logging history
- Convert file from iso-8859-1 to utf8
- Convert string between lowercase and uppercase
- Copy a whole directory preserving permissions
- Copying an array in Bash
- Create a
netcat
http server in a few lines of code - Date conversion to and from epoch
- Depth limited recursive
grep
search - Display weather from terminal
- Generate a simple
.txt
sitemap - Get lastmod of file in epoch seconds using
stat
- Increment a variable
- Inserting text at the beginning of a file
- MUTEX locking a script to prevent parallel or multiple execution
- Making a compressed disk image using dd and pv to indicate progress
- Output (echo) to stderr rather than stdout
- Output whitepace as control characters
- Padding strings left or right
- Read a string into an array in Bash
- Read one per line output into an array
- Read output of command into an array
- Redirection permission problems when using
sudo
- Running a script as another user
- Test if a directory is empty
- Testing whether a glob has any matches
- Uppercase a variable’s first character
- Use
sed
to insert lines before or after a match