In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "what are the basic commands of Linux". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's ideas to study and learn what are the basic commands of Linux.
1. Tail-f
The cat command can be used to view the contents of a file. But there will be more options when viewing. The cat command outputs the entire file, which is sometimes unnecessary. If you only want to output the first or last line, you can use the tail or head command to do so. By default, the head command outputs the first 10 lines, and the tail command outputs the last 10 lines.
The tail command is usually used to view log files because the tail command has a-f option, which stands for "follow", which can be used to view files. This option outputs additional data when the content of the file increases, so that the log entries attached to the file can be displayed immediately.
2. Scp
Scp stands for secure copy (secure copy), which allows files to be copied between hosts on the Internet. One way to use scp is to copy files from a personal computer to a remote server and vice versa. Scp collaborates with secure Shell Protocol (SSH).
This command is very simple and works similar to the cp command. The only difference is that files can be copied to other hosts using scp, which is not possible with a normal cp command.
Scp [target] [destination]
Scp looks like the familiar cp command. To copy files from the server to your personal computer, you must do the following:
Scp derk@127.0.0.1:/target/file.txt ~ / destination
In this case, the user is "derk" and the host is 127.0.0.1. The host address is followed by a colon Specify the path to the file to be copied after the colon. The second parameter is destination, which in this case is a folder on the personal computer. The result of this command is to copy file.txt from the server to the local computer's ~ / destination folder.
For example, this is useful for downloading database backups from the server. If you want to upload files from a personal computer to a remote host, you need to switch parameters.
Scp ~ / target/file.txt derk@127.0.0.1:/destination
This command copies file.txt from the personal computer to the destination folder on the remote host.
3. Cd-
Cd is one of the most frequently used commands on the Linux command line. However, many developers are not aware of a good option that comes with the cd command-hyphens.
Cd-
Add a hyphen after the cd command to return to the previously selected directory. The following is an example of the actual operation:
4. Diff
If you've ever used versioning, you've probably used the diff command. For example, when using Git, this command can view changes made to a file.
The diff command represents differences (difference), and files can be compared line by line. Suppose there are two files that contain a list of continents, and the only difference between these files is the order of the continents.
Using the diff command on these two files, you will get the following output. At the same time, be sure to add the-c option, which outputs differences in context mode, making the output more readable.
5. Locate
The locate command is a very powerful tool for searching for files on your computer. The locate command is much faster than the find command. It is so fast because instead of reading the file system to search for file or directory names, it refers to a database to find what the user is looking for and generates the corresponding output based on the search.
The syntax of the locate command is very simple:
Locate [filename]
The output of this command lists all files that contain the specified term, and in the following example, the search term is "xml".
You can also use regular expressions to search for exact matches. Specify the regular expression with the-r option.
Locate-r / filename$
6. Lsof
The lsof command lists all open files. Its syntax is simple, just type lsof. This command has no other options and lists all open files in the active process.
This command applies to a variety of situations, one of which is to see which processes are running on a port. To do this, you must specify the-I option. In the following example, we want to see which processes are running on port 22, the port of SSH.
Lsof-I TCP:22
You can also list a series of ports. The following example lists all processes running in a port range of 20-30.
Lsof-I TCP:20-30
Finally, the output of the lsof command can be used to terminate all processes for a specific user-- in this case, derk.
Kill-9 `lsof-t-u derk`
7. History
The history command stores a list of all other commands run from the current terminal session. The following figure is an example of the output of the history command:
You can combine the history command with grep to make the search more accurate.
History | grep npm
You can not only use the history command to view all the commands that have been run. You can also use the history command to quickly execute one of the previously executed commands again.
Whenever you execute the history command, a number is displayed in front of each line. You can execute the same command again with an exclamation point followed by a line number.
! 488
Reviewing the previous example, the above command will execute the ls-al command again.
8. Wget
Wget can download files from Web. The syntax of the wget command is shown below, simply by specifying the resources to download. In this example, we will download a random image.
Wget https://picsum.photos/200
Wget is in its simplest form, with no options, and downloads the resources specified in URL to the current directory. By default, you will find a lot of details about the wget command output download, such as download speed and progress bar. To turn off output, you can use the-Q option. If you want to save the downloaded file with a different name, you can use the-0 option followed by the name of the file.
Wget-O my-image.jpg https://picsum.photos/200 thank you for reading, the above is the content of "what are the basic commands of Linux". After the study of this article, I believe you have a deeper understanding of what the basic commands of Linux have, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.