1.“Previous Selected Excellent Articles Are Here!”
2. Let’s Add Monitoring to Your Spring Boot!
3. Shocked, Spring Boot Actually Consumes So Much Memory!
4. Spring Boot Annotation Collection, One-Click Bookmark!
5. MySQL Limit Performance Poor? Can’t Use It Anymore?
5. Prevent Cache Breakdown? Please Use Bloom Filter!
Source:https://os.51cto.com/art/201607/514821.htm#topx
1
Command Line Daily Shortcuts
The following shortcuts are very useful and can greatly enhance your work efficiency:
CTRL + U – Cut the content before the cursor
CTRL + K – Cut the content to the end of the line
CTRL + Y – Paste
CTRL + E – Move cursor to the end of the line
CTRL + A – Move cursor to the beginning of the line
ALT + F – Jump to the next space
ALT + B – Jump back to the previous space
ALT + Backspace – Delete the previous word
CTRL + W – Cut the next word after the cursor
Shift + Insert – Paste text into the terminal
To make the above content easier to understand, let’s look at the following command.
sudo apt-get install programname
As you can see, there is a spelling error in the command; to execute it normally, you need to replace “intall” with “install”.
Imagine now the cursor is at the end of the line, and we have many ways to backtrack to the word install and replace it.
I can press ALT+B twice, so the cursor will be in the following position (here indicating the cursor position).
sudo apt-get^intall programname
Now you can press the arrow keys twice and insert “s” into install.
If you want to copy text from the browser to the terminal, you can use the shortcut “shift + insert”.
2
SUDO !!
If you don’t know this command yet, you should thank me because if you didn’t know, you would be in pain every time you see “permission denied” after entering a long string of commands.
sudo !!
How to use sudo !!? It’s simple. Imagine you just entered the following command:
apt-get install ranger
You will definitely get “Permission denied,” unless you have logged into an account with sufficient privileges.
sudo !! will run the previous command in sudo form. So the previous command changes to:
sudo apt-get install ranger
If you don’t know what sudo is, click here.
3
Pause and Run Commands in the Background
I once wrote a guide on how to run commands in the background in the terminal.
CTRL + Z – Pause the application
fg – Bring the program back to the foreground
How to use this trick?
Imagine you are editing a file with nano:
sudo nano abc.txt halfway through editing, you realize you need to enter some commands in the terminal immediately, but nano is running in the foreground preventing you from typing.
You might think the only way is to save the file, exit nano, run the command, and then reopen nano.
In fact, you just need to press CTRL + Z, and the foreground command will pause, returning to the command line. Then you can run the command you want, and after it finishes, enter “fg” in the terminal window to return to the previously paused task.
It’s quite interesting to try opening a file with nano, entering some text, and then pausing the session. Then open another file with nano, enter something, and pause the session again. If you enter “fg,” you will return to the second file opened with nano. You will only return to the first file opened with nano after exiting nano and entering “fg.”
4
Using nohup to Run Commands After Logging Out of SSH Sessions
If you are using SSH to log into another machine, the nohup command is really useful.
So how do you use nohup?
Imagine you are remotely logged into another computer via ssh, you run a time-consuming command, and then log out of the SSH session, but the command is still executing. Nohup can make this scenario a reality.
For example, for testing purposes, I used my Raspberry Pi to download a distribution. I would never connect a monitor, keyboard, or mouse to my Raspberry Pi.
I always connect to the Raspberry Pi from my laptop using SSH. If I download large files on the Raspberry Pi without using nohup, I would have to wait until the download is complete before I can log out of the SSH session and shut down my laptop. If that’s the case, why use the Raspberry Pi to download files?
Using nohup is simple; just enter the command you want to execute after nohup as in the following example:
nohup wget http://mirror.is.co.za/mirrors/linuxmint.com/iso//stable/17.1/linuxmint-17.1-cinnamon-64bit.iso &
5
Run Linux Commands at a Specific Time
The ‘nohup’ command is very useful when you are connected to a server via SSH and need to keep tasks running until you log out of SSH.
What if you need to execute the same command at a specific time?
The ‘at’ command can handle this situation well. Here is an example of using ‘at’.
at 10:38 PM Fri at> cowsay ‘hello’ at> CTRL + D The above command will run the cowsay program at 10:38 PM on Friday.
The syntax used is to append the date and time after ‘at’. When the at> prompt appears, you can enter the command you want to run at that time.
CTRL + D returns to the terminal.
There are many date and time formats, and you need to check the ‘at’ man page for more usage methods.
6
Man Page
The Man page will outline the usage of commands and parameters, teaching you how to use them. Man pages may seem dull and boring (I think they weren’t designed to entertain us).
But that doesn’t mean you can’t do something to make them look prettier.
export PAGER=most You need to install ‘most’; it will make your man pages more colorful.
You can set a specific line length for the man page with the following command:
export MANWIDTH=80 *** If you have a browser available, you can use -H to open any man page in the default browser.
man -H Note that the above command only works if you set the default browser to the environment variable $BROWSER.
7
Using htop to View and Manage Processes
Which command do you use to find out what processes are running on your computer? I bet it’s ‘ps’ followed by different parameters to get the output you want.
Install ‘htop’! You will definitely love it.
htop presents processes in a list format in the terminal, similar to the Task Manager in Windows. You can use function key combinations to switch the arrangement and displayed items. You can also kill processes directly in htop.
Simply enter htop in the terminal to run it.
htop
8
Using ranger to Browse the File System
If htop is a good helper for process control in the command line, then ranger is a good helper for browsing the file system in the command line.
You may need to install it first, but once installed, you can start it by entering the following command in the command line:
ranger is similar to some other file managers in the command line window, but compared to the vertical layout, it has a horizontal layout, meaning that if you press the left arrow key, you will go back to the previous folder, and the right arrow key will switch to the next.
It’s worth reading the ranger man page before using it, so you can operate ranger with shortcut keys.
9
Cancel Shutdown
Whether in the command line or graphical user interface, you realize you don’t really want to shut down after the shutdown has started.
shutdown -c Please note that if the shutdown has already started, it may be too late to cancel it.
Here’s another command you can try:
pkill shutdown
10
Simple Way to Kill Hanging Processes
Imagine that the application you are running has inexplicably frozen.
You can use ‘ps -ef’ to find that process and kill it or use ‘htop’.
There is a faster and easier command called xkill.
Simply enter the following command in the terminal and click on the window of the application you want to kill.
xkill What if the whole system hangs?
Hold down the ‘alt’ and ‘sysrq’ keys, and then slowly press the following keys:
REISUB
This will restart your computer without pressing the power button.
11
Download Youtube Videos
Generally, most of us like to watch Youtube videos and stream them through our favorite players.
If you need to be offline for a while (for example, during a flight from southern Scotland to southern England), you might want to download some videos to your storage device for later viewing.
All you need to do is install youtube-dl from the package manager.
You can use the following command with youtube-dl:
youtube-dl url-to-video
You can get the video URL by clicking the share link on the Youtube video page. Just copy the link and paste it into the command line (remember to use shift + insert shortcut).
Summary
I hope you find this article helpful and discover at least one trick among these 11 that makes you exclaim, “I didn’t know I could do that!”
Popular Articles:
1. “Historical Article Classification Guide! Selected Excellent Articles Are Here!”
2. Prevent Cache Breakdown? Please Use Bloom Filter!
3. Java 14 Out-of-the-Box Guide! You Strong, You Strong!
4. start.aliyun.com Officially Launched! Rapidly Build Spring Cloud Applications
5. Tencent and Alibaba “Fought” on B Station, When Did You See This Scene?
6. 41 Must-Know SpringBoot Interview Questions, Don’t Miss Out!
7. Online Service CPU 100%? One-Click Location Is So Simple!
8. Big Differences, Didn’t Expect Adult Websites Use Technology That Outpaces Us!
9. 6 Websites for Freelancing, You Have Skills, You Have Money!
10. A Piece of Code Found Online Suddenly Broke, Causing a Major Bug in the Project!