Introduction:
Navigating the maze of Linux commands can be overwhelming, but don't worry! We've got some useful tips and tricks to help simplify your daily tasks, ensuring everything runs smoothly. With these insights, you'll find managing operations much easier.
1. Clearing terminal:
Hit Ctrl + L to clear the terminal screen instead of writing out clear each time.
2. Tab auto complete cmds:
Many people know that you can use tab completion for navigating folders and files, but it can also be handy for commands.
3. Alias:
Alias is a brief command we can establish (some come pre-configured by default).
Of course. Please provide the text you'd like me to rewrite.
alias u="sudo apt update"
alias i='sudo apt install"
Now press 'i' to install a package, or 'u' to refresh the repository cache.
Note: To make aliases permanent, include them in your .bashrc file.
Open .bashrc using any text editor, then insert the lines at the very end. Afterward, save the file, close the editor, and refresh bash by executing "source .bashrc".
Actually, there are a number of pre-defined aliases available—for instance, ll serves as an alias for ls -la, among others. To see the full list, simply type alias without any additional parameters.
To delete an alias you've set up via cmd, use the command unalias.
4. Navigate the commands:
Imagine you’ve typed out an extensive command but then realize you missed adding something at the beginning or near the start of it.
Rather than scrolling through everything manually, simply press Ctrl A to select all the text. In a similar manner, Ctrl E will take you to the end of the line, while Ctrl U erases the entire command text (an alternative to holding down the backspace key).
5. cd ~ vs cd — :
The command `cd` on its own or `cd ~` will take you to your home directory, no matter where you currently are.
`cd -` will switch you back to the last directory you were in.
6. pushd and popd:
When you type "pushd /path/
", it changes your working directory to "/path/
" and stores your previous directory on the directory stack. Later, by using popd
, it takes the top entry off the stack and navigates you back to that directory.
7. hostnamectl:
Change hostname for easy identification of machine.
hostnamctl set-hostname <name>
It's possible to use your domain name as the hostname as well.
8. Get Public IP:
Get public ip using ifconfig.me
curl ifconfig.me
9. Re run the previous command:
Like with point 3, you don’t always have to return to the beginning (You can use those shortcuts to make changes in the middle or near the end).
We have the option to run the last command again by using !! alongside any omitted commands.
$ systemctl stop httpd
$ sudo !!
10. Re run the previous command arg:
Imagine you just ran ls on a directory, only to realize you actually wanted to switch to that directory instead.
$ commad <args>
$ 2nd command !$
11. background and foreground task:
When you’re working on a file and find the need to perform additional tasks in the terminal, simply press `Ctrl+Z` to pause your current activity. After completing your other tasks, you can get back to editing by using `fg`. This approach is versatile and can be used with a wide range of applications, not just editors.
12. Manpage and help:
You don't have to memorize every flag for a command. Simply use 'man' to see them all, or 'help'.
man wc
help cd
13. Ctrl Q:
Pressed Ctrl S to save your changes? In the terminal, this key combination will actually freeze your session. To unfreeze it, simply press Ctrl Q.
14. Font Management
To make the terminal font size bigger, press Ctrl and the + button. To make it smaller, use Ctrl and the — button.