Master the Terminal and Command Line: Bash Cheat sheet

What you need to use the terminal everyday

Aimed Guendouz
3 min readJun 21, 2023

Using terminal to do tasks can be more powerful than using a graphical interface and it can be faster and easier.

Basic bash command

Bash is the default shell in many Linux distro and Unix system like Mac OS.

This is a list of the top commands i use for my tasks

This is a long list, so look only for commands that you need

piping

Sometimes, you want to use the output of a command as the input for other command, and this is called piping

For example if i have a file named animal.txt and i want to print its content but it’s a large file, you can pip the output of cat to the command less like this, so it print few lines and when you enter it add some few other lines too:

cat animals.txt | less

Another example, if you are in a directory that has a lot of files and you want to search for file containing the string “dog”, you just run:

ls | grep "dog"

Output redirection

Sometimes, you need to save the output of a command to a file, this is called output redirection

echo dog > animals.txt #create or rewrite the file dir.txt to the string "dog"
echo dog >> animals.txt #create or append to the file dir.txt the string "dog"

Terminal shortcut

Terminal shortcut can be customized but most of terminal come with default shortcut.

Navigation Shortcuts:

  • Ctrl + A: Move the cursor to the beginning of the line.
  • Ctrl + E: Move the cursor to the end of the line.
  • Ctrl + B or Left Arrow: Move the cursor back one character.
  • Ctrl + F or Right Arrow: Move the cursor forward one character.
  • Ctrl + P or Up Arrow: Retrieve the previous command from history.
  • Ctrl + N or Down Arrow: Retrieve the next command from history.

Text Manipulation Shortcuts:

  • Ctrl + D: Delete the character at the current cursor position.
  • Ctrl + K: Delete the text from the current cursor position to the end of the line.
  • Ctrl + U: Delete the text from the current cursor position to the beginning of the line.
  • Ctrl + W: Delete the word preceding the current cursor position.
  • Ctrl + Y: Paste (yank) the previously deleted text.

Command History Shortcuts:

  • Ctrl + R: Search backward through the command history for a specific command.
  • Ctrl + G: Escape from the history search mode initiated by Ctrl + R.
  • !!: Repeat the last command.
  • !xyz: Execute the most recent command starting with "xyz" from the command history.

Terminal Control Shortcuts:

  • Ctrl + L: Clear the terminal screen.
  • Ctrl + C: Interrupt (cancel) the currently running command.
  • Ctrl + Z: Suspend (pause) the currently running command and put it in the background.
  • Ctrl + D: Exit the current shell or close the terminal session.

Learn more about Linux in our website: https://linuxtutor.github.io/

I hope you like this article. If you have any questions or suggestions, don’t hesitate to post a comment!

--

--