Some of the Linux shell uses tips to collect _linux shell

Source: Internet
Author: User
Tags curl md5 hash git clone egrep

Check to see if the remote port is open to bash:

Copy Code code as follows:

echo >/dev/tcp/8.8.8.8/53 && echo "Open"

To get a process into the background:
Copy Code code as follows:

Ctrl + Z

To move a process to the foreground:
Copy Code code as follows:

Fg

Produces a random hexadecimal number where n is the number of characters:
Copy Code code as follows:

OpenSSL Rand-hex N

Execute a command in a file in the current shell:
Copy Code code as follows:

Source/home/user/file.name

Intercept the first 5 characters:
Copy Code code as follows:

${variable:0:5}

SSH Debug Mode:
Copy Code code as follows:

SSH-VVV user@ip_address

SSH with PEM key:
Copy Code code as follows:

SSH user@ip_address-i Key.pem

Use wget to crawl the complete site directory structure and store it in the local directory:
Copy Code code as follows:

Wget-r--no-parent--reject "index.html*" http://hostname/-p/home/user/dirs

Create multiple directories at once:
Copy Code code as follows:

Mkdir-p/home/user/{test,test1,test2}

Lists the process trees that include child processes:
Copy Code code as follows:

PS AXWEF

To create a war file:
Copy Code code as follows:

JAR-CVF Name.war File

To test hard drive write speed:
Copy Code code as follows:

DD If=/dev/zero of=/tmp/output.img bs=8k count=256k; Rm-rf/tmp/output.img

Test hard drive Read speed:
Copy Code code as follows:

Hdparm-tt/dev/sda

Gets the MD5 hash of the text:
Copy Code code as follows:

Echo-n "Text" | Md5sum

Check XML format:
Copy Code code as follows:

Xmllint--noout File.xml

To extract the tar.gz into a new directory:
Copy Code code as follows:

Tar zxvf package.tar.gz-c New_dir

To obtain HTTP header information using curl:
Copy Code code as follows:

Curl-i http://www.example.com

To modify a file or directory timestamp (YYMMDDHHMM):
Copy Code code as follows:

Touch-t 0712250000 File

To perform FTP downloads with the wget command:
Copy Code code as follows:

Wget-m Ftp://username:password@hostname

Generate a random password (in the example 16 characters in length):
Copy Code code as follows:

Lang=c </dev/urandom tr-dc _a-z-a-z-0-9 | Head-c${1:-16};echo;

To quickly back up a file:
Copy Code code as follows:

CP SOME_FILE_NAME{,.BKP}

To access the Windows shared directory:
Copy Code code as follows:

Smbclient-u "Domain\User"//dc.domain.com/share/test/dir

Execute the commands in the history (this is line 100th):
Copy Code code as follows:

!100

Extract:
Copy Code code as follows:

Unzip package_name.zip-d Dir_name

Enter multiple lines of text (CTRL + D exit):
Copy Code code as follows:

Cat > Test.txt

To create an empty file or empty an existing file:
Copy Code code as follows:

> Test.txt

Sync time with Ubuntu NTP server:
Copy Code code as follows:

Ntpdate ntp.ubuntu.com

Display all TCP4 listening ports with netstat:
Copy Code code as follows:

Netstat-lnt4 | awk ' {print $} ' | Cut-f2-d: | Grep-o ' [0-9]* '

Qcow2 Mirrored file Conversion:
Copy Code code as follows:

Qemu-img convert-f qcow2-o Raw precise-server-cloudimg-amd64-disk1.img \
Precise-server-cloudimg-amd64-disk1.raw

Run the file repeatedly, displaying its output (default is 2 seconds):
Copy Code code as follows:

Watch Ps-ef

All Users list:
Copy Code code as follows:

Getent passwd

Mount root in Read/write mode:
Copy Code code as follows:

Mount-o REMOUNT,RW/

Mount a directory (this is the case where links are not available):
Copy Code code as follows:

Mount--bind/source/destination

To update DNS server dynamically:
Copy Code code as follows:

Nsupdate < <eof
Update add $HOST 86400 A $IP
Send
Eof

Recursively grep all directories:
Copy Code code as follows:

Grep-r "Some_text"/path/to/dir

List the top 10 largest files:
Copy Code code as follows:

Lsof/| awk ' {if ($ > 1048576) Print $7/1048576 MB ' $} ' | Sort-n-u | Tail

Show remaining memory (MB):
Copy Code code as follows:

free-m | grep Cache | awk '/[0-9]/{print $ MB '} '

Open vim and skip to end of file:
Copy Code code as follows:

Vim + some_file_name

Git clone Specifies branch (master):
Copy Code code as follows:

git clone git@github.com:name/app.git-b Master

Git switches to another branch (develop):
Copy Code code as follows:

git checkout Develop

Git Delete Branch (myfeature):
Copy Code code as follows:

Git branch-d myfeature

Git Deletes a remote branch
Copy Code code as follows:

git push origin:branchname

Git pushes the new branch to the remote server:
Copy Code code as follows:

Git push-u origin mynewfeature

Print last Cat command in history:
Copy Code code as follows:

!cat:p

The last cat command in the Run history:
Copy Code code as follows:

!cat

Find all the empty directories under/home/user:
Copy Code code as follows:

Find/home/user-maxdepth 1-type D-empty

Get 第50-60 line contents in Test.txt file:
Copy Code code as follows:

< 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):
Copy Code code as follows:

Sudo!!

Create temporary RAM file System –ramdisk (create/tmpram directory first):
Copy Code code as follows:

Mount-t Tmpfs Tmpfs/tmpram-o size=512m

Grep whole words:
Copy Code code as follows:

Grep-w "Name" Test.txt

Append text to a file when elevated permissions are required:
Copy Code code as follows:

echo "Some text" | sudo tee-a/path/file

List all kill signal parameters:
Copy Code code as follows:

Kill-l

To prevent the last session from being logged in bash history:
Copy Code code as follows:

Kill-9 $$

Scan the network for open ports:
Copy Code code as follows:

Nmap-p 8081 172.20.0.0/16

Set up git email:
Copy Code code as follows:

git config--global user.email "me@example.com"

To-sync with master If you have unpublished commits:
Copy Code code as follows:

Git pull--rebase Origin master

Move files containing "TXT" in all file names into the/home/user directory:
Copy Code code as follows:

Find-iname "*txt*"-exec mv-v {}/home/user \;

To display files in line by row:
Copy Code code as follows:

Paste Test.txt Test1.txt

The progress bar in the shell:
Copy Code code as follows:

PV Data.log

Use Netcat to send data to Graphite server:
Copy Code code as follows:

echo "Hosts.samplehost ' date +%s '" | NC 192.168.200.2 3000

Convert tabs to spaces:
Copy Code code as follows:

Expand Test.txt > Test1.txt

Skip Bash History:
Copy Code code as follows:

< space >cmd

Go to the previous working directory:
Copy Code code as follows:

CD-

Split a large volume of tar.gz files (each 100MB), and then merge back:
Copy Code code as follows:

Split–b 100m/path/to/large/archive/path/to/output/files
Cat files* > Archive

Use Curl to get HTTP status code:
Copy Code code as follows:

Curl-sl-w "%{http_code}\\n" Www.example.com-o/dev/null

Set root password to enhance MySQL security installation:
Copy Code code as follows:

/usr/bin/mysql_secure_installation

When the CTRL + C is bad:
Copy Code code as follows:

Ctrl + \

Get file Owner:
Copy Code code as follows:

Stat-c%u file.txt

Block Device list:
Copy Code code as follows:

Lsblk-f

Find a file with spaces at the end of the file name:
Copy Code code as follows:

Find. -type f-exec egrep-l "+$" {} \;

Find a file with a tab indent file name
Copy Code code as follows:

Find. -type f-exec egrep-l $ ' t ' {} \;

Print a horizontal line with "=":
Copy Code code as follows:

printf '%100s\n ' | TR ' =

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.