preface
What is a Linux Shell
Linux Shell is the interface program between users and Linux kernel, which provides users with an excuse to use the operating system. When a command is passed to the Linux kernel, it will respond.
Shell is a user program, or an environment provided for user and system interaction.
It is a language interpreter that executes the commands read from the standard input device. It has its own built-in Shell command set, and the Shell can also be called by other commands in the system.
The Shell runs when you log in or open the console.
Shell is not part of the system kernel, but it can use the kernel system to execute commands, create files, and so on.
Linux Shell itself is an interpretative programming language.
Using Linux shell is the basic work of some programmers every day, but we often forget some useful shell commands and skills. Of course, I can remember the command, but I can't say I can remember how to use it to perform a specific task. It should be noted that some uses require additional software to be installed in your Linux system. I won't say much now. Let's take a look at the details.
Check whether the remote port is open to bash:
echo >/dev/tcp/8.8.8.8/53 && echo "open"
Put the process in the background:
Ctrl + z
Generates a random hexadecimal 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
Intercept 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
Grab the complete website directory structure with wget and store it 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 the process tree including child processes:
ps axwef
To create a war file:
jar -cvf name.war file
Test hard disk write speed:
dd if=/dev/zero of=/tmp/output.img bs=8k count=256k; rm -rf /tmp/output.img
Test hard disk read speed:
hdparm -Tt /dev/sda
Get md5 hash of text:
echo -n "text" | md5sum
Check xml format:
xmllint --noout file.xml
Set tar GZ extract to new directory:
tar zxvf package.tar.gz -C new_dir
Get HTTP header information using curl:
curl -I http://www.example.com
Modify the timestamp of the file or directory (YYMMDDhhmm):
touch -t 0712250000 file
Execute ftp download with wget command:
wget -m ftp://username:password@hostname
Generate random password (16 characters in the example):
LANG=c < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-16};echo;
Quick backup of a file:
cp some_file_name{,.bkp}
To access the Windows shared directory:
smbclient -U "DOMAIN\user" //dc.domain.com/share/test/dir
Execute the command in the history (here is line 100):
!100
Decompression:
unzip package_name.zip -d dir_name
Enter multiline text (CTRL + d exit):
cat > test.txt
Create an empty file or empty an existing file:
\> test.txt
Synchronization time with Ubuntu NTP server:
ntpdate ntp.ubuntu.com
Display all tcp4 listening ports with netstat:
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
Run the file repeatedly and display its output (once every 2 seconds by default):
watch ps -ef
List of all users:
getent passwd
Mount root in read/write mode:
mount -o remount,rw /
Mount a directory (this is the case where links cannot be used):
mount --bind /source /destination
Dynamically update DNS server:
nsupdate < <EOF update add $HOST 86400 A $IP send EOF
Recursive 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
Show remaining memory (MB):
free -m | grep cache | awk '/[0-9]/{ print $4" MB" }'
Open Vim and skip to the end of the file:
vim + some_file_name
Git clone specified branch (master):
git clone git@github.com:name/app.git -b master
Git switch to other branches (develop):
git checkout develop
Git delete branch (myfeature):
git clone git@github.com:name/app.git -b master
Git switch to other branches (develop):
git checkout develop
Git delete branch (myfeature):
git branch -d myfeature
Git Delete remote branch
git push origin :branchName
Git pushes the new branch to the remote server:
git push -u origin mynewfeature
Last cat command in print history:
!cat:p
The last cat command in the running history:
!cat
Find all empty subdirectories under / home/user:
find /home/user -maxdepth 1 -type d -empty
Get test Lines 50-60 in TXT file:
< test.txt sed -n '50,60p'
Run the last command (if the last command is mkdir /root/test, the following will run: sudo mkdir /root/test):
sudo !!
Create temporary RAM file system – ramdisk (create / tmpram directory first):
mount -t tmpfs tmpfs /tmpram -o size=512m
Grep whole words:
grep -w "name" test.txt
Add text to a file when the permission needs to be upgraded:
echo "some text" | sudo tee -a /path/file
List all kill signal parameters:
kill -l
Prohibit recording 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 --globaluser.email "me@example.com"
To sync with master if you have unpublished commits:
git pull --rebase origin master
Move all files with "txt" in the file name to the / home/user directory:
find -iname "*txt*" -exec mv -v {} /home/user \;
Display files side by side by line:
paste test.txt test1.txt
Progress bar in shell:
pv data.log
Send data to Graphite server using netcat:
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 a large volume of tar GZ files (100MB each), and then merge 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 the root password to strengthen MySQL security installation:
/usr/bin/mysql_secure_installation
When Ctrl + c doesn't work:
Ctrl + \
Get file owner:
stat -c %U file.txt
block device list:
lsblk -f
Find files with spaces at the end of the file name:
find . -type f -exec egrep -l " +$" {} \;
Find the file with tab indent in the file name
find . -type f -exec egrep -l $'\t' {} \;
Print a horizontal line with "=": select all, copy and put it into the notes
printf '%100s\n' | tr ' ' =
These are the details of common shell commands
last
I have collected and sorted out some materials. These materials should be the most comprehensive and complete war preparation warehouse for my friends of [software testing]. This warehouse has also accompanied me through the most difficult journey. I hope it can also help you.
WeChat official account: Software Test dao free
For more software testing resources, please add software testing technology exchange group: 1033482984
Don't just be a person who never stops collecting and never starts taking action. You can't learn from yourself when you do a lot of things. If you can think a little more and look at the experience and practices of others, you will grow faster and have better results! Come on, tester! The road is at your feet, and success is tomorrow!