Linux shell rare usage and skill __linux

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

Using the Linux shell is my daily basic work, but I often forget some useful shell commands and L tips. Of course, I can remember the order, but I'm not sure I can remember how to use it to perform a particular task. So I began to record these usages in a text file and put them in my Dropbox, now, to share this document with you. I'm going to keep updating this file. It is important to note that there are some uses to install additional software in your Linux system.

Update:november 25, 2013

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

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

To get a process into the background:

Ctrl + Z

To move a process to the foreground:

Fg

Produces a random hexadecimal number where n is the number of characters:

OpenSSL Rand-hex N

Execute a 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

Use wget to crawl the complete site directory structure 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}

Lists the process trees that include child processes:

PS AXWEF

To create a war file:

JAR-CVF Name.war File

To test hard drive write speed:

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

Test hard drive Read speed:

Hdparm-tt/dev/sda

Gets the MD5 hash of the text:

Echo-n "Text" | Md5sum

Check XML format:

Xmllint--noout File.xml

To extract the tar.gz into a new directory:

Tar zxvf package.tar.gz-c New_dir

To obtain HTTP header information using curl:

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

To modify a file or directory timestamp (YYMMDDHHMM):

Touch-t 0712250000 File

To perform FTP downloads with the wget command:

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

Generate a random password (in the example 16 characters in length):

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

To quickly back up 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 commands in the history (this is line 100th):

!100

Extract:

Unzip package_name.zip-d Dir_name

Enter multiple lines of text (CTRL + D exit):

Cat > Test.txt

To create an empty file or empty an existing file:

> Test.txt

Sync time with Ubuntu NTP server:

Ntpdate ntp.ubuntu.com

Display all TCP4 listening ports with netstat:

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

Qcow2 Mirrored 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, displaying its output (default is 2 seconds):

Watch Ps-ef

All Users list:

Getent passwd

Mount root in Read/write mode:

Mount-o REMOUNT,RW/

Mount a directory (this is the case where links are not available):

Mount--bind/source/destination

To update DNS server dynamically:

Nsupdate < <eof
Update add $HOST 86400 A $IP
send
EOF

Recursively grep all directories:

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

List the top 10 largest files:

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

Show remaining memory (MB):

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

Open vim and skip to end of file:

Vim + some_file_name

Git clone Specifies branch (master):

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

Git switches to another branch (develop):

git checkout Develop

Git Delete Branch (myfeature):

Git branch-d myfeature

Git Deletes a remote branch

git push origin:branchname

Git pushes the new branch to the remote server:

Git push-u origin mynewfeature

Print last Cat command in history:

!cat:p

The last cat command in the Run history:

!cat

Find all the empty directories under/home/user:

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.