In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article is about commands that are easy to be ignored under Linux. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
I. Preface
In my work, I found that many students are not familiar with the commands under Linux, especially some powerful tools with few users. As the saying goes, if you want to do good work, you must first sharpen its tools.
II. Orders
1.strace
Strace is used to track system calls during program execution, such as tracking test processes, by simply:
Strace-p [test_pid] or direct strace. / test
But if you need to:
Track threads within a process:-f option
Statistics of the distribution of system calls over a period of time:-C option
Filter some system calls:-e trace option, for example,-e trace=network displays only network-related system calls, and-e trace=open,close,read,write displays only these four system calls, which is often used to obtain only certain specific system calls
Displays the time of the system call:-ttt option
Display the data for each line in detail instead of the...-s option to increase the string length limit such as-s 1024
For example, if you track the read and write system calls of all threads in a process with a pid of 12345, the length of the output string is limited to 1024:
Strace-s 1024-f-e trace=read,write-p 12345
2.tcpdump
Tcpdump is a package grabbing tool on Linux, such as grabbing packets on eth0 network cards, using:
Sudo tcpdump-I eth0
But if you need to:
Display packet capture data in text form:-An option
Display hexadecimal message data:-X option
Output result to file-w option, such as-w 1.cap to output message to 1.cap file, which can be viewed by wireshark
Filter host and port number such as host 11.11.11.11 and port 12345 filter host tcp message with ip 11.11.11.11 and port number 12345
For example, grab the HTTP message at port 80 and display it as text:
Sudo tcpdump-i any port 80-A
In this way, you can clearly see the content of GET and POST requests.
3.nc
Nc can open TCP Server, TCP Client, UDP Server, UDP Client on Linux.
For example, enable TCP Server and Client analog TCP communication on port number 12345:
Server: nc-l 127.0.0.1 12345 Client: nc 127.0.0.1 12345
Open UDP Server and Client analog TCP communication on port number 12345:
Server: nc-ul 127.0.0.1 12345 Client: nc-u 127.0.0.1 12345
Example of Unix Socket communication:
Server: nc-Ul / tmp/1.sock Client: nc-U / tmp/1.sock
4.curl
Curl is used to simulate HTTP requests. It is often used in terminals to simulate requests, such as the most basic usage:
Curl http://www.baidu.com
But if you need to:
Specify the HTTP header-H option, such as-H "Host: xx.xx.xx.xx"
Specify the request method-X option, such as-X POST,-d specify post data
Displays request details, including request and response header-v options
Automatic tracking of redirect requests-L option
Common curl request options-sSfL: do not display progress information, display error messages, fail when HTTP errors occur, and automatically track redirection
5.find
Find can be used to find files, such as:
Find. -name "1.txt"
It means to find a file named 1.txt under the current directory and its subdirectories, and it is more powerful to use it with xargs, such as:
Find. -type f | xargs grep 'abcd'
Means to find a file line that contains an abcd string under the current directory and its subdirectories, often used to search for code.
6.lsof
The main uses of the lsof command include:
Sudo lsof-I: [port] View the process information of port occupation, which is often used to confirm which process the port is occupied by when port binding fails.
Sudo lsof-p [pid] to see which files or sockets are open by the process
7.ss
The ss command on Linux can be used to replace netstat,ss to read statistics directly under parse / proc/net, which is much faster than netstat traversing every PID directory under / proc.
Common examples:
Ss-t-a shows all TCP Sockets
Ss-u-a shows all UDP Sockets
Ss-x src / tmp/a.sock shows the processes connected to / tmp/a.sock
Ss-o state [state TCP-STATE] such as ss-o state established displays all established connections
8.awk/sed
Awk and sed are very powerful in text processing, where awk is processed by column and sed by row.
If the data is separated by colons, output * column data ($0 represents all column data in the row, $1 represents * column, and $2 represents the second column.)
Awk-F ":"'{print $1}'
Based on the results of awk, the functions such as frequency statistics can be easily completed by combining commands such as sort, uniq and head.
View the 100th to 200th lines of the file: sed-n '100200p' log.txt replace a specific substring echo "int charset=gb2312 float" in the string | sed "s/charset=gb2312/charset=UTF-8/g" replace the test file where each line matches ab as cd sed-I's test
9.screen
When using telnet or SSH to log in to the remote host, the session will be terminated because of the network interruption, and the SIGHUP signal will be triggered to terminate the task, so we often see some tasks run in the way of nohup to avoid being interrupted. Screen solves this problem cleverly through the way of multi-terminal. Example:
Screen-S test opens a screen and has a terminal. All the executed programs will be displayed in ps.
Ctrl+ a key + d key exit the current screen and go to the superior window
Screen-ls view all screen lists, such as
13333.test (Detached) 14039.test4 (Detached) indicates that two screen,screen are identified as 13333.test and 14039.test4
Screen-r [pid.] tty.host enters the selected screen, such as screen-r 13333.test
Exit closes the current screen
Thank you for reading! This is the end of this article on "which commands are easy to be ignored under Linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
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.