Summary of 73 commonly used commands in Linux shell
Preface
Using the Linux shell is a basic daily job for some programmers, but we often forget some useful shell commands and techniques. Sure, I can remember the command, but I can't say I can remember how to perform a specific task with it. One thing to note is that some usage requires the installation of additional software in your Linux system. Not much to say below, let’s take a look at the detailed content.
Check whether the remote port is open to bash:
echo >/dev/tcp/8.8.8.8/53 && echo "open"
Let the process transfer Enter the background:
Ctrl + z
Bring the process to the foreground:
fg
Generate random hex number, where n is the number of characters:
openssl rand -hex n
Execute the command in a file in the current shell:
source /home/user /file.name
Truncate the first 5 characters:
${variable:0:5}
SSH debug mode:
ssh -vvv user@ip_address
SSH with pem key:
ssh user@ip_address -i key.pem
Use wget to grab The complete website directory structure is stored in the local directory:
wget -r --no-parent --reject "index.html*" http://hostname/ -P /home/user/dirs
Create multiple directories at once:
mkdir -p /home/user/{test,test1,test2}
List including child processes Process tree:
ps axwef
Create war file:
jar -cvf name.war file
Test hard disk writing Speed:
dd if=/dev/zero of=/tmp/output.img bs=8k count=256k; rm -rf /tmp/output.img
Test hard drive Reading speed:
hdparm -Tt /dev/sda
Get md5 hash of text:
echo -n "text" | md5sum
Check xml format:
xmllint --noout file.xml
Extract tar.gz to a new directory:
tar zxvf package .tar.gz -C new_dir
Use curl to get HTTP header information:
curl -I http://www.example.com
Modify the timestamp of a file or directory (YYMMDDhhmm):
touch -t 0712250000 file
Use wget command to perform ftp download:
wget -m ftp:/ /username:password@hostname
Generate a random password (16 characters long in the example):
LANG=c < /dev/urandom tr -dc _A-Z-a-z- 0-9 | head -c${1:-16};echo;
Quickly back up a file:
cp some_file_name{,.bkp}
Access the Windows shared directory:
smbclient -U "DOMAIN\user" //dc.domain.com/share/test/dir
Execute the commands in the history (Here is line 100):
!100
Unzip:
unzip package_name.zip -d dir_name
Enter Multi-line text (CTRL + d to exit):
cat > test.txt
Create an empty file or clear an existing file:
\> test.txt
Synchronize time with Ubuntu NTP server:
ntpdate ntp.ubuntu.com
Use netstat to display all tcp4 listening ports:
netstat -lnt4 | awk '{print $4}' | cut -f2 -d: | grep -o '[0-9]*'
qcow2 image file conversion:
qemu-img convert -f qcow2 -O raw precise-server-cloudimg-amd64-disk1.img \precise-server-cloudimg-amd64-disk1.raw
Repeatedly run the file, Display its output (default is every 2 seconds):
watch ps -ef
All user list:
getent passwd
Mount root in read/write mode:
mount -o remount,rw /
Mount a directory (this is the case when links cannot be used):
mount --bind /source /destination
Dynamic update DNS server:
nsupdate <
Recursively grep all directories:
grep -r "some_text" /path/to/dir
List the top 10 largest files:
lsof / | awk '{ if($7 > 1048576) print $7/1048576 "MB "$9 }' | sort -n -u | tail
Display remaining memory (MB):
free -m | grep cache | awk '/[0-9]/{ print $4" MB" }'
Open Vim and jump to the end of the file:
vim + some_file_name
Git clone the specified branch (master):
git clone git@github.com:name/app.git -b master
Git switch to other branch (develop):
git checkout develop
Git delete branch (myfeature):
git branch -d myfeature
Git deletes the remote branch
git push origin :branchName
Git pushes the new branch to the remote server:
git push -u origin mynewfeature
Print the last cat command in the history:
!cat:p
Run the last cat command in the history:
!cat
Find all empty subdirectories under /home/user:
find /home/user -maxdepth 1 -type d -empty
Get the contents of lines 50-60 in the test.txt file:
< test.txt sed -n '50,60p'
Run the last command (if the last The command is mkdir /root/test, the following will run: sudo mkdir /root/test):
sudo !!
Create a temporary RAM file system – ramdisk (create / first tmpram directory):
mount -t tmpfs tmpfs /tmpram -o size=512m
Grep whole words:
grep -w "name" test.txt
Append text to a file when privileges need to be elevated:
echo "some text" | sudo tee -a /path/file
List all kill Signal parameter:
kill -l
Disable recording of the last session in bash history:
kill -9 $$
Scan the network for open ports:
nmap -p 8081 172.20.0.0/16
Set git email:
git config --global user. email "me@example.com"
To sync with master if you have unpublished commits:
git pull --rebase origin master
will All files containing "txt" in their file names are moved into the /home/user directory:
find -iname "*txt*" -exec mv -v {} /home/user \;
Display files side by side:
paste test.txt test1.txt
Progress bar in shell:
pv data.log
Use netcat to send data to Graphite server:
echo "hosts.sampleHost 10 `date +%s`" | nc 192.168.200.2 3000
Convert tabs to spaces:
expand test.txt > test1.txt
Skip bash history:
< space >cmd
Go to the previous working directory:
cd -
Split the large tar.gz files (100MB each) and merge them back:
split –b 100m /path/to/large/archive /path/to/output/files cat files* > archive
Use curl to get HTTP status code:
curl -sL -w "%{http_code}\\n" www.example.com -o /dev/null
Set root password to strengthen MySQL security installation:
/usr/bin/mysql_secure_installation
When Ctrl + c does not work:
Ctrl + \
Get the file owner:
stat -c %U file.txt
block device list:
lsblk -f
Find files with spaces at the end of their file names:
find . -type f -exec egrep -l " +$" {} \;
Find the files whose file names have tab indentation
find . -type f -exec egrep -l $'\t' {} \;
Use "=" to print out horizontal lines: select all and copy them into notes
printf '%100s\n' | tr ' ' =
Summary
The above is the entire content of this article. I hope the content of this article can bring some help to everyone's study or work. And convenient, if you have any questions, you can leave a message to communicate.
For more related articles summarizing the 73 commonly used commands in Linux shell, please pay attention to the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...
