11 Linux terminal commands that surprised you
I have been using Linux for ten years. Through this article, I will show you a series of commands, tools, and skills. I hope someone will tell me this at the beginning, instead of holding me on the road to my growth.
1. Commands
The following shortcuts are very useful and can greatly improve your work efficiency:
- CTRL + U-cut the content before the cursor
- CTRL + K-cut the content from the cursor to the end of the row
- CTRL + Y-paste
- CTRL + E-move the cursor to the end of the row
- CTRL + A-move the 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 word behind the cursor
- Shift + Insert-paste text to the terminal
In order to make the above content easier to understand, let's look at the following line of commands.
sudo apt-get intall programname
As you can see, there is a spelling error in the command. For normal execution, replace "intall" with "install ".
Imagine that the cursor is at the end of the line, and there are many ways to return her back to the word install and replace it.
I can press ALT + B twice so that the cursor will be at the following position (here it is used to represent the position of the cursor ).
sudo apt-get^intall programname
Now you can press the arrow keys twice and insert "s" to install.
If you want to copy the text in the browser to the terminal, you can use the shortcut key "shift + insert ".
2. SUDO !!
If you do not know this command, I think you should thank me very much, because if you do not know it, then every time you input a long string of commands and see "permission denied", it will be painful.
How to Use sudo !!? Very simple. Imagine you just entered the following command:
apt-get install ranger
"Permission denied" appears unless you have logged on to an account with high permissions.
Sudo !! Run the previous command in sudo format. So the previous command becomes like this:
sudo apt-get install ranger
If you do not 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 terminal background.
- CTRL + Z-pause the application
- Fg-call the program to the front-end
How to use this technique?
Imagine you are using nano to edit a file:
sudo nano abc.txt
Halfway through file editing, you realize that you need to input some commands on the terminal right away, But nano is running on the front-end so that you cannot enter the commands.
You may think the only way is to save the file, exit the nano, and re-open the nano after running the command.
In fact, you only need to press CTRL + Z, and the front-end command will be paused, and the screen will be switched back to the command line. Then you can run the command you want to run. After the command is run, enter "fg" in the terminal window to return to the previously paused task.
An interesting attempt was to use nano to open the file, input something, And pause the session. Use nano to open another file and enter something to pause the session. If you enter "fg", you will return to the second file opened with nano. Only after you exit the nano and enter "fg" Will you return to the first file opened with nano.
4. Use nohup to run the command after logging out of the SSH session
If you use ssh to log on to another machine, the nohup command is very useful.
So how to use nohup?
Imagine using ssh to remotely log on to another computer. You run a very time-consuming command and quit the ssh session, but the command is still being executed. Nohup can turn this scenario into reality.
For example, I used my raspberry to download the release because of the test requirements. I will never give my Raspberry Pi an external monitor, keyboard or mouse.
Generally, I use SSH to connect to Raspberry Pi from my laptop. If I use Raspberry Pi to download large files without using nohup, I have to wait until the download is complete before I can log out of the ssh session and turn off the notebook. But if so, why should I use Raspberry Pi files?
The nohup method is also very simple. You only need to enter the command to be executed after nohup 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 the Linux Command at a specific time
The 'nohup' command is useful when you connect to the server by using SSH and keep the tasks before logging out by SSH.
What if you want to execute the same command at a specific time?
The 'at' command can properly solve this problem. The following is an example of 'at.
at 10:38 PM Fri
at> cowsay 'hello'
at> CTRL + D
The above command can run the program cowsay at 10:38 P.M. on Friday.
The syntax used is the append Date and Time After 'at. When the at> prompt appears, you can enter the command you want to run at that time.
CTRL + D Return terminal.
There are also many Date and Time formats, You need to flip the 'at' man manual to find more ways to use.
6. Man Manual
The Man Manual provides you with an outline of how to use commands and parameters. The Man manual looks dull and dull. (I think they are not designed to entertain us ).
But it doesn't mean you can't do anything to make them more beautiful.
export PAGER=most
You need to install 'most'; she will make your man manual more colorful.
You can use the following command to set the specified governor for the man manual:
export MANWIDTH=80
Finally, if you have an available browser, you can use-H to open any man page in the default browser.
man -H <command>
Note that the above commands are effective only after you set the default BROWSER to the environment variable $ BROWSER.
7. Use htop to view and manage processes
Which command do you use to find the processes running on the computer? I bet it's 'ps' and add different parameters after it to get the different output you want.
Install 'htop! It makes you feel at ease.
Htop presents processes in the form of a list in the terminal, a bit similar to the Job Manager in Windows. You can use a combination of function keys to switch the arrangement mode and items displayed. You can also directly kill the process in htop.
Simply enter htop in the terminal to run.
htop
8. Use ranger to browse the File System
If htop is a good helper for the command line process control, ranger is a good helper for the command line to browse the file system.
You may need to install it before using it, but once installed, you can run the following command on the command line to start her:
ranger
In the command line window, ranger is similar to some other file managers, but compared to the upper and lower structure layout, ranger is in the left and right structure, which means that you press the left arrow key and you will move forward to the previous folder, the right arrow key switches to the next one.
Before using ranger, the man manual is worth reading, so that you can use the shortcut key to operate ranger.
9. Cancel Shutdown
After the command line or graphic user interface is turned off, you can find that you do not really want to shut down.
shutdown -c
It should be noted that if the shutdown has started, it may be too late to stop the shutdown.
The following is another command you can try:
10. A simple method to kill a suspended Process
Imagine that your running application is dead for unknown reasons.
You can use 'ps-ef 'to locate the 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 the application you want to kill in the window.
xkill
What if the entire system crashes?
Press and hold 'alt' and 'sysrq' on the keyboard, and then enter the following key:
In this way, your computer can be restarted without pressing the power button.
11. Download the Youtube video
In general, most of us like watching Youtube videos and playing Youtube streaming media through our favorite player.
If you need to be offline for a while (for example, traveling from southern Scotland to south England), you may want to download some videos to storage devices and watch them in your spare time.
All you need to do is install youtube-dl from the Package Manager.
You can use the following command to use youtube-dl:
youtube-dl url-to-video
You can click the share link on the Youtubu video page to get the video url. Simply copy the link and paste it to the command line (use the shift + insert shortcut ).
Summary
I hope you can get help in this article, and find at least one technique that will surprise you with the question of "This is what we can do" in these 11 articles.
This article permanently updates the link address: