The use and skill of shell commands in Linux

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

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.111cn.net

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 "DomainUser"//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:

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

Get 第50-60 line contents in Test.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

Append text to a file when elevated permissions are required:

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

List all kill signal parameters:

Kill-l

To prevent the last session from being logged in bash history:

Kill-9 $$

Scan the network for open ports:

Nmap-p 8081 172.20.0.0/16

Set up git email:

git config--global user.email "me@111cn.net"

To-sync with master If you have unpublished commits:

Git pull--rebase Origin master

Move files containing "TXT" in all file names into the/home/user directory:

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

To display files in line by row:

Paste Test.txt Test1.txt

The progress bar in the shell:

PV Data.log

Use Netcat to send data to Graphite server:

echo "Hosts.samplehost ' 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 (each 100MB), 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.111cn.net-o/dev/null

Set root password to enhance MySQL security installation:

/usr/bin/mysql_secure_installation

When the CTRL + C is bad:

Ctrl +

Get file Owner:

Stat-c%u file.txt

Block Device list:

Lsblk-f

Find a file with spaces at the end of the file name:

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

Find a file with a tab indent file name

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

Print a horizontal line with "=":

printf '%100sn ' | 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.