Shell Tricks That Make Life Easier (and Save Your Sanity)
10 hours ago
- #productivity
- #shell-shortcuts
- #terminal-tricks
- Standard terminal shortcuts like CTRL + W, CTRL + U, and CTRL + K can save time by deleting words or lines instantly.
- Use CTRL + A and CTRL + E to jump to the beginning or end of a line, and ALT + B or ALT + F to move by words.
- The 'reset' command can fix a terminal corrupted by binary output.
- CTRL + C cancels the current command, while CTRL + D sends an EOF signal or logs you out.
- CTRL + L clears the terminal screen without interrupting your current command.
- Use 'cd -' to toggle between the current and previous directories, or 'pushd' and 'popd' for directory stacks.
- '> file.txt' truncates a file without changing permissions or interrupting processes.
- $_ refers to the last argument of the previous command, useful for reusing paths.
- In scripts, 'set -e' exits on error, and 'set -u' treats unset variables as errors.
- CTRL + R searches command history incrementally.
- 'sudo !!' reruns the last command with elevated privileges.
- CTRL + X followed by CTRL + E opens the current command in a text editor for complex edits.
- ESC + . inserts the last argument of the previous command at the cursor.
- Brace expansion (e.g., 'cp file{,.bak}') simplifies backups and renames.
- Process substitution (e.g., 'diff <(sort file1) <(sort file2)') treats command output as files.
- Globstar ('**') recursively matches files in subdirectories.
- CTRL + Z suspends a process, 'bg' resumes it in the background, and 'disown' detaches it from the shell.
- 'command |& tee file.log' captures both stdout and stderr, displaying and logging output.