Zum Inhalt

bash cheatsheet

History

Last run commands

Traverse the history in ~/.bash_history

Up

or if you forget sudo, reference the last command using !!:

sudo !!

Search last commands

Ctrl+R will toggle inverse search in your history.

Arguments of last successfull command

We ran:

cat log-edabadfdads-xasdsf.text 
but the log is too big. So we want to tail it. You can write tail 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:

for item in "1 2 3 4"; do

you can hit Ctrl+X+E to open a buffer in your editor (echo $EDITOR). Complete the code with

for item in "1 2 3 4"; do
   echo $item
done
Quit the editor with saving and the content will run.

Go to the home directory

Change to the home directory of $USER.

cd ~
cd $HOME

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:

less +F /var/log/syslog
  • 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:

tail -n 100 /var/log/syslog

Savers

Reset the terminal when behaving wierd

reset wil reset the terminal, which can be used instead of closing the terminal.


Letztes Update: December 15, 2022
Erstellt: December 15, 2022