bash cheatsheet
History
Last run commands
Traverse the history in ~/.bash_history
Up
or if you forget sudo
, reference the last command using !!
:
Search last commands
Ctrl+R will toggle inverse search in your history.
Arguments of last successfull command
We ran:
but the log is too big. So we want to tail it. You can writetail
and hit Alt+. to get the last argument.
Signals
Exit a program
Ctrl+C will normally exit any shell program.
Exit Codes
Exit code of last run command
echo $?
will show the exit code of the last run command.
Clipboard
Paste from clipboard
Ctrl+Shift+V pastes clipboard content to the terminal.
Shell tricks
- Ctrl+K cuts characters right to the cursor
- Ctrl+U cuts characters left to the cursor
- Ctrl+Y bring back last cut characters
Open buffer
When starting a line like a loop:
you can hit Ctrl+X+E to open a buffer in your editor (echo $EDITOR
). Complete the code with
Navigating directories
Go to the home directory
Change to the home directory of $USER
.
Go back to last directory
cd -
will go back to the last directory
Inspecting files
End of file
Display the end of a logfile following new incoming data:
- Hit Ctrl+C to detach from the end of the file to scroll up.
- Hit Shift+F to glue to the end.
Display last 100 lines of a file with tail
:
Savers
Reset the terminal when behaving wierd
reset
wil reset the terminal, which can be used instead of closing the terminal.
References
Letztes Update:
March 25, 2023
Erstellt: December 15, 2022
Erstellt: December 15, 2022