Bash / Shell
Strings
Extract a substring
output=""
output=""
Replace the first match of $substring with $replacement
output=""
Replace all the matches of $substring with $replacement
output=""
Remove shortest match of $substring from front of $input
output=""
Remove longest match of $substring from front of $input
output=""
Remove shortest match of $substring from back of $input
output=""
Remove longest match of $substring from back of $input
output=""
Remove leading white space (left trim)
output=""
Remove trailing white space (right trim)
output=""
Files
Check if a regular file exists
File test operators
| Expression | What does it check? |
|---|---|
-e | If file exists |
-f | If file exists and is a regular file |
-d | If file exists and is a directory |
-r | If file exists and is readable |
-w | If file exists and is writable |
-x | If file exists and is executable |
-s | If file exists and its size is greater than zero |
Remove filename extension
output=""
Logging
Merge and log stdout and stderr in a file:
|
Unbuffered version:
|
Kill process not responding to Ctrl+C
- Press Ctrl+Z. This suspends the process and puts it in the background. You can restore it with
fg. - Run
kill -9 %1. Replace 1 with the number displayed previously (e.g. 2 for[2]+).