In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
In this issue, Xiaobian will bring you specific Linux Shell commands. The article is rich in content and analyzes and narrates from a professional perspective. After reading this article, I hope you can gain something.
introduction
Shell, as the most attractive and indispensable component of Unix operating system, has not been eliminated after decades of baptism, but has become more mature and stable, probably because it is a very stable adhesive, able to put a large number of powerful components arbitrarily matched, always very good and quickly complete the user's task.
Some of the commands in this article may seem like "small tricks," so we'll have to admire Shell, but I'll dig into some details and hopefully make you laugh when I see interesting places.
1. Run the previous command with SUDO
$ sudo !!
Everyone should know sudo, not explain. However, it is usually the case that after typing the command and executing the error, it is discovered that the sudo has been forgotten. At this point, novice users will: press the up arrow, press the left arrow, stare at the cursor back to the beginning, type sudo, enter; expert users will be more determined, press Ctrl-p, press Ctrl-a, type sudo, enter.
This is the first time that I have seen this, right?
Of course, the effect of these solutions is exactly the same, but the models are different, um, no explanation.
The two exclamation marks are actually a feature of bash called event designators.!! It's like!- 1, quote the previous command, of course!- 2,!- 50。By default bash keeps track of the last 500 commands executed by the user in the ~/.bash_history file, and the history command displays them.
2. Share files in the current folder as HTTP
$ python -m SimpleHTTPServer
This command starts Python's SimpleHTTPServer module, and considering Python is installed by default in most Linux distributions, this command is probably the easiest way to transfer files across platforms.
After the command is executed, HTTP service will be opened on port 8000 of this machine. Open http://ip:8000 in the browser of other machines that can access this machine, that is, open a directory list. Click to download it.
3. Save a ROOT user file in VIM opened as normal user
:w ! sudo tee %
This topic read tangled, in fact, is very common, often forget sudo directly with vim edit/etc files,(but not necessarily, vim found that the saved file can not be saved when the prompt) and so on edit good, save time only to find no permissions. Curve method is to save a temporary file, exit and then sudo cp back. However, in fact, this process can be directly completed in vim, and this is the case with commands.
Check vim's documentation (type:help :w) and you'll see the command:w! {cmd}Let vim execute an external command {cmd} and pass the contents of the current buffer from stdin.
tee is a widget that saves stdin to a file.
% is the name of a read-only register in vim that always holds the file path of the currently edited file.
So executing this command is equivalent to modifying the currently edited file from outside vim to complete it.
4. Switch back to previous directory
$ cd -
Many of you know this, the crossbar--represents the path to the previous directory.
cd -is actually short for cd $OLDPWD, bash's fixed variable $OLDPWD always holds the path to the previous directory.
In contrast,$PWD always holds the path to the current directory. These variables are useful when writing shell scripts.
5. Replace a phrase in the previous command
$ ^foo^bar^
Another event designator replaces foo with bar in the previous command.
In the need to repeatedly run debugging a long command, need to test a certain parameter, use this command will be more practical; but most people will first choose to press the arrow on the road command, and then move the cursor to modify a parameter, so more intuitive, but not efficient enough to use the reference character high, and in the script with this method can simplify a lot.
The original style of this command would look like this:
!!: s/foo/bar/
This article was introduced at the beginning!! The following paragraph should be familiar to everyone. The replacement operations of vim and sed are all syntax like this.
The Definitive Guide to Bash Command Line History
6. Quick backup of a file
$ cp filename{,.bak}
This command copies the filename file to filename.bak, as you may have seen in some of the more complex installation tutorials. The principle lies in bash's expansion of curly braces. filename{,.bak} will be expanded into filename.bak and then passed to cp, so there is a backup command.
The curly braces in bash are the meaning of a permutation, you can try this:
$ echo {a,b,c}{a,b,c}{a,b,c}
A full permutation of three sets will be output:
aaa aab aac aba abb abc aca acb accbaa bab bac bba bbb bbc bca bcb bcccaa cab cac cba cbb cbc cca ccb ccc
7. Password free SSH login host
$ ssh-copy-id remote-machine
This command writes the public key string of the current user to ~/.ssh/authorized_keys of the remote host, so that the next time you log in using ssh, the remote host will directly complete the identity verification according to this string of keys, and no longer ask for the password. The premise is that your current user has generated a public key, the default is not, first execute ssh-keygen try it!
This command, if done manually, would look like this:
your-machine$ scp ~/.ssh/identity.pub remote-machine:your-machine$ ssh remote-machineremote-machine$ cat identity.pub >> ~/.ssh/authorized_keys
If you want to delete the key on the remote host, just open authorized_keys, search for your username, delete that line, and you're done.
8. Capture LINUX desktop video
$ ffmpeg -f x11grab -s wxga -r 25 -i :0.0 -sameq /tmp/out.mpg
We see other people's 3D desktop how cool video on some video sites, usually this is how to come, ffmpeg can directly decode X11 graphics, and convert to the corresponding output format.
The usual usage of ffmpeg is to output a file according to a bunch of parameters. The output file is usually put in ***. The following parses the following parameters:
-f x11grab Specifies the input type. Because the x11 buffer is not a normal video file format that can be detected, you must specify ffmpeg to know how to get the input.
-s wxga Sets the size of the grab area. Wxga is the standard expression for 1366*768, which can also be changed to-s 800×600.
-r 25 Sets the frame rate, which is the number of frames captured per second.
-i :0.0 Set input source, local X defaults to 0.0
-sameq maintains the same image quality as the input stream for post-processing.
PostScript
Shell is a programming language, it may be a bit embarrassing, although many people use Shell every day, but never see it on the TIOBE programming language rankings and the like, can be said to have no name, because many users do not realize that it is a language, only as a tool that can complete the task well, basically take it for granted, just like the menu and button of GUI programs.
Mastering Shell, usually allows tasks to be completed in seconds, which distinguishes Shell from C, Perl, Python and other languages. No one denies that the latter is more competent for more tasks, but they do it at different levels. Shell relies on a large number of system components to bind calls, while the latter relies on various libraries, each of which is good at different application areas. The analogy is that Shell is concrete, which can easily bind some building components into a stable high-rise building. But the same adhesive, sticky glass windows, sticky books, sticky shoes, concrete is absolutely inappropriate, Shell is not good at some detailed operations, such as it does not even support floating point operations, let alone graphics operations. But that doesn't stop Shell from helping us with a lot of heavy lifting.
The above is what the Linux Shell commands shared by Xiaobian are, and if there are similar doubts, you may wish to refer to the above analysis for understanding. If you want to know more about it, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.