banner
lMingyul

lMingyul

记录穿过自己的万物
jike
twitter
github
bilibili

Common Series - Linux Common Commands

The Common Series is a record of commonly used programming tools. This article is the first in the Common Series, used to document frequently used Linux commands during daily development for easy reference when needed.

View Directory#

ls#

tree#

Display the file structure of the current directory

Modify File Permissions#

View File Content#

more#

less#

tail#

wc#

grep#

xargs#

xargs can convert input data into command line arguments for specific commands; thus, it can be used in combination with many commands. For example, grep, find

cut#

Used to remove part of the content from each line

Find Files#

locate#

Find files by pathname, the search range is in the /var/lib/mlocate/ database, stored in memory, updated once a day, so locate cannot search for newly created files. You can use updatedb to immediately update the database.

If the system does not come with the locate command, you can use yum install mlocate -y to install it, and after installation, execute the updatedb command

find command#

Find files by filename

sed Text Replacement#

sed is generally used for text content replacement, operating line by line

The basic working method of sed is:

  • Read the file into memory line by line (this memory is also called the pattern space)
  • Use each script of sed to operate on that line
  • Output the line after processing

Format

sed ‘operation command’ one or more files

Bash Keyboard Shortcuts#

Archiving and Backup#

gzip#

Compress a single or multiple files

gunzip#

Decompress files

zip#

Compress and archive into a .zip file

unzip#

Decompress .zip files

tar#

Archive multiple files or directories

View Disk Space#

Query Processes#

ps#

top#

lsof#

Others#

Terminate Process#

Analyze Thread Stack#

Use the command pmap to output the memory status of the process, which can be used to analyze the thread stack;

Performance Monitoring#

Monitor CPU#

Query Memory#

Query Port Occupation#

Query Page Swapping#

View the status of page swapping. When page swapping occurs, the server's throughput will drop significantly; if the server is in poor condition and it is suspected that page swapping occurred due to insufficient memory, you can use the command sar -W to confirm whether a large amount of swapping has occurred;

Comprehensive Application#

When sar is unavailable in the system, you can use the following tools as alternatives: vmstat under Linux, prstat under Unix systems

eg: View CPU, memory, and usage: vmstat n m (n is the monitoring frequency, m is the monitoring count)

Use the watch tool to monitor changes. When continuous monitoring of a certain data change in an application is needed, the watch tool can meet the requirements; after executing the watch command, it will enter an interface that outputs the currently monitored data, and once the data changes, it will highlight the change;

eg: Monitor memory changes when operating redis:

ping#

Send ICMP packets to a specified host to confirm network connectivity with the host. The sending interval is 1 s, and you can interrupt the sending with Ctrl + C. A normal network will show a 0% packet loss rate.

traceroute#

Will list all hops the network takes from the local machine to the destination host

ip#

A multifunctional network configuration tool used to check the system's network interfaces and routing tables

  • Will display multiple network interfaces, common interfaces:
    • lo: Loopback interface, a virtual interface used by the system to "talk to itself"
    • eth0: Ethernet interface
  • If the first line of the interface contains the word UP, it indicates that the interface is enabled
  • The inet field in the 3rd line is the IP address of that network interface

netstat#

Used to check various network settings and statistics, requires installation of net-tools yum install net-tools

ssh#

Used for communication between the local host and the remote host

Other Common Commands#

References#

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.