November 20, 2024

Debian Command Line Shortcuts That Make Life Easier

mr rockstar

Debian Command Line Shortcuts That Make Life Easier
Cheap Dedicated Server

The Debian command line is a powerful tool for developers, system administrators, and Linux enthusiasts alike. However, navigating it efficiently requires some know-how. Here are some command-line shortcuts and tips to help you save time and boost productivity.


1. Use Autocomplete (Tab)

One of the most useful features of the Debian command line is autocomplete. Pressing Tab will:

  • Complete a partially typed command or file name.
  • List all possible completions if there’s ambiguity.

Example:

 
cd /etc/ap<Tab>

This will either auto-complete /etc/apache2/ or display options starting with ap.


2. Navigate Command History (Arrow Keys)

The Debian shell remembers your previous commands. Use:

  • and to navigate through your command history.
  • Ctrl + R to search through past commands interactively.

Example:

 
(reverse-i-search)`apt': sudo apt update


3. Clear the Screen Quickly

To clear the cluttered terminal screen, use:
 Clear the Screen Quickly   

 
Ctrl + L


4. Cancel Running Commands

If you accidentally start a process you don’t need or want to interrupt, press:
Cancel Running Commands

 
Ctrl + C


5. Reuse Last Command Arguments

Sometimes you need to repeat a command with a slight variation. Instead of retyping arguments, use:

  • !$: Refers to the last argument of the previous command.

Example:
Reuse Last Command Arguments

 
nano /etc/hosts

sudo nano !$


6. Run the Last Command

To rerun the last command, simply type:
Run the Last Command

 
!!

Or:

 
sudo !!

This is especially useful when you forgot to prepend sudo.


7. Jump to the Beginning or End of a Line

When editing a command:

  • Ctrl + A: Moves the cursor to the beginning of the line.
  • Ctrl + E: Moves the cursor to the end of the line.

8. Delete Entire Line

To quickly delete the entire line of a command:
Delete Entire Line

 
Ctrl + U


9. Delete Word by Word

To delete one word at a time:

  • Backward: Ctrl + W
  • Forward: Ctrl + K

10. Use Aliases

Save time by creating aliases for commonly used commands. Edit your ~/.bashrc file and add lines like:

 
alias update="sudo apt update && sudo apt upgrade"

alias ll="ls -lh"

Reload the file:

 
source ~/.bashrc


11. Switch Between Virtual Consoles

Debian supports multiple virtual consoles. You can switch between them with:

 
Ctrl + Alt + F1 to F6


12. Background and Foreground Processes

Run a command in the background:

 
command &

Bring it back to the foreground:

 
fg


13. Use watch to Monitor Output

The watch command repeatedly runs another command at intervals:

 
watch -n 5 'ls -l /path/to/dir'

This refreshes the output every 5 seconds.


14. Quick Directory Navigation

Return to the previous directory:

 
cd -


15. Search Through Files

Use grep to search for text within files:

 
grep -i "search-term" file.txt

Add -r to search recursively in directories:

 
grep -r "search-term" /path/to/dir


16. Use tmux or screen

For long-running tasks, use terminal multiplexers like tmux or screen to keep sessions alive:

 
tmux

Detach and reattach sessions as needed:

 
tmux detach

tmux attach


17. Check System Information

Use the following commands to quickly check system info:

  • CPU info: lscpu
  • Disk usage: df -h
  • Memory usage: free -m

18. Edit Commands with a Text Editor

To edit a long or complex command in your default editor:

 
Ctrl + X + E


19. Use xargs for Parallel Processing

Pass output from one command to another:

 
ls | xargs -n 1 -P 4 echo


20. Combine Commands

Chain commands for efficiency:

  • Run sequentially: command1 && command2
  • Run regardless of success: command1 ; command2
  • Run only if the first fails: command1 || command2

Mastering these shortcuts will make your Debian command-line experience much smoother and more efficient. Start using them today, and you’ll find yourself navigating and managing your system like a pro!

What are your favorite shortcuts? Share them in the comments below!

Debian Command Line Shortcuts (F.A.Q)

 

How can I autocomplete commands or file names?

Press the Tab key while typing a command or file path. If multiple options are available, pressing Tab twice lists all possibilities.

What should I do if a command freezes?

Use Ctrl + C to cancel or stop the running command. If it’s still stuck, use kill to terminate the process.

How can I repeat the last command with sudo?

Use sudo !!. It re-executes the last command with elevated privileges.

 

Can I save custom shortcuts for common commands?

Yes! Add aliases in your ~/.bashrc file. For example:

alias ll="ls -lh"

Save and run source ~/.bashrc to apply the changes.

 

Popular Blog Posts