These are just a few of the many command line tricks and shortcuts that will save you a lot of time while working in the Linux terminal.
Jump to the beginning of the line: ctrl+a
Jump to the end of the line: ctrl+e
Clear the entire line: ctrl+u
Stop any command: ctrl+c
Jump left one word: esc+b
Jump right one word: esc+f
Exits the terminal session: ctrl+d
Use the Up arrow on your keyboard to scroll through your previous commands
Use tab for autocompletion. After you start typing something, hit tab and it will print suggestions that start with the string you typed.
Vim editor
Exit without saving: ESC then :q!
Save and exit: ESC then :wq
Delete all lines in a file: in command mode (note that Vim starts in “command” mode by default) type “gg” to move the cursor to the first line of the file then type dG to delete all lines in a file
For any command, you can view its manual page using man [command]. This is a great way to learn what a command does.
This command shows your recent command history.
history
Use the following example to get a command from history:
history | grep command
Use the following commands to search the root directory or current directory for a filename or folder. The root directory is the top-level directory that contains all other files and folders. The forward slash (/) represents the root of the filesystem. The dot (.) represents the current directory in the filesystem.
find ‘/’ -name “filename or folder”
find ‘.’ -name “filename or folder”
grep -rnw “.” -e “string”
-r is recursive
-n is line number
-w stands for match the whole word
Display the amount of disk space in human readable format available on the filesystem and exclude directories that we don’t care to see in our output. Open the file in your text editor and declare the alias then make the alias available in your current session by running the source command.
vim ~/.bashrc
alias df=”df -h -x tmpfs -x devtmpfs”
source ~/.bashrc
Go to your home directory
cd ~
You can also just cd to return to your home directory without the tilde
cd
Running multiple commands in one single command only if the previous command was successful with the double-ampersand (&&)
command1 && command2 && command3
To improve your workflow, you can create several “pseudo terminals” from a single terminal with tmux.
For more information on tmux please visit: