Home>

1 File management 2 Software management 3 System management

4 Service Management 5 Network Management 6 Disk Management

7 User management 8 Script related 9 Service configuration

====================================

----------------------------------

1 File management

----------------------------------

Create a blank file

touch

Do not prompt to delete non-empty directories

rm -rf directory name

(-r:recursively delete -f to force)

###################################

Recover rm deleted files (ext3)

View disk partition format

df -t

Unmount

umount/data /

ext3grep/dev/sdb1 --ls --inode 2

Record information to continue to find file inode information in the directory

ext3grep/dev/sdb1 --ls --inode 131081 #here is inode

Record the inode information and start to restore the directory

ext3grep/dev/sdb1 --restore-inode 49153

###################################

windows text to linux text

dos2unix

Linux text to windows text

unix2dos

Transcoding

iconv -f gbk -t utf8 original .txt>new .txt

View md5 value

md5sum

Hard link

ln

Symbolic connection

ln -s

View page up and down and display line numbers

cat?| nl | less

q exit

End state

ctrl + z

View the beginning of a file

head

See end of file

tail -f #monitor log files

Check file type

file

Rename

rename

rename source_pattern target_pattern source_files

Change default permissions

umask

Sort by numbers

sort -n

Flashback by number

sort -nr

Filtering duplicate rows

sort -u

Remove duplicate lines

uniq

Duplicate line occurrences

uniq -c

Show only duplicate rows

uniq -u

Merge two files separated by tab

paste a b

Merge two files with "+" sign

paste -d "+" a b

Combine multiple rows of data into one row separated by tab

paste -s a

Setting hidden properties

chattr [+-=] [asacdistu] file or directory

Down facet

more

search for

locate string

View the number of rows

wc -l

View the latest changed files in a directory in real time

watch -d -n 1 "df;ls -flat/path"

Quickly backup a file

cp filename {,. bak}

###################################

Configuration editor

gconf-editor

vi configuration file

vi/etc/vimrc

Edit file

vim

Open line number

:set nu

Cancel line number

:set nonu

Jump to 200

200g

Cancel highlighting

:nohl

Set automatic indentation

:set autoindent

View text format

set ff

Change to unix format

set binary

Page forward

ctrl + u

Page backward

ctrl + d

Replace all

g/character 1/s //character 2/g

%s/character 1/character 2/g

#Normal users cannot save documents when they open them

#tee is a small tool to save stdin to a file,And%is the name of a read-only register in vim.Always save

File path before editing file

:w! sudo tee%

###################################

Find by file name

find/etc -name http

Find a certain type of file

find .-type f

Find by file permissions

find/-perm

Find by file owner

find/-user

Find files by their group

find/-group

File use time is less than n days

find/-atime -n

File used n days ago

find/-atime + n

File content changed within n days

find/-mtime -n

File content changed by n days ago

find/-mtime + n

File status changed n days ago

find/-ctime + n

File status change time in n days

find/-ctime -n

#linux file has no creation time

#access time

#modify content modification time

#change state change time (permission, owner)

Find files longer than 1m bytes

find/-size + 1000000c -print

Find files by name after passing to -exec command

find/etc -name "passwd *" -exec grep "xuesong" {} \;

Find the file name,Do not take the path

find. -name "t *" -exec basename {} \;

###################################

======================================================= ====================

----------------------------------

2 Software Management

----------------------------------

Unpack tar

tar xvf 1.tar -c directory

Package tar

tar -cvf 1.tar *

View tar

tar tvf 1.tar

Append files to tar

tar -rvf 1.tar file name

Unpack gz

tar zxvpf gz.tar.gz

Pack gz

tar zcvpf gz.tar.gz

View gz

tar ztvpf gz.tar.gz

Unzip bzip2

bzip2 -dv 1.tar.bz2

Unzip gzip to tar

gzip -dv 1.tar.gz

Compress tar to gz

gzip -v 1.tar

bzip2 compression

bzip2 -v 1.tar

View bzip2

bzcat

rpm installation

rpm -ivh

Uninstall

rpm -e lynx

Force uninstall

rpm -e lynx --nodeps

test

rpm --test lynx

View all installed rpm packages

rpm -qa

Find out if the package is installed

rpm -qa | grep http

Unzip the zip

unzip zip.zip

Compressed zip

zip zip.zip *

http://www.rarsoft.com/rar/rarlinux-3.6.0.tar.gz

Compressed file as rar package

rar a rar.rar * .jpg

Unzip the rar package

unrar x rar.rar

7z compression

7z a 7z. 7z *

7z decompression

7z e 7z.7z

View character lines

zgrep character 1.gz

Package/home,/etc, but exclude/home/dmtsai

tar --exclude/home/dmtsai -zcvf myfile.tar.gz/home/*/etc

In/home, files newer than 2005/06/01 are backed up

tar -n "2005/06/01" -zcvf home.tar.gz/home

download

wgetrc

Text internet

lynx

Make a mirror

cp -v/dev/dvd /software/rhel4.6.iso9660

Clear compilation results

make clean

Source installation

./configure --help | less

./configure --prefix =/usr/local /

make

make install

perl program compilation

perl makefile.pl

make

make test

make install

perl program compilation

python file.py

Compile c program

gcc -g hello.c -o hello

======================================================= ====================

----------------------------------

3 System Management

----------------------------------

Terminal lock screen ctrl + s

Unlock screenctrl + q

PS1 environment variable control prompt display

ps1="[\ [email protected]\ h \ w \ a \@#] \ $"

Start-up mode

vi/etc/inittab

Find Command Directory

whereis

View the path of the command to be executed

which

Let the ministry order run in the background

command&

Put foreground into background (pause)

ctrl + z

View background running programs

jobs

Start background pause process

bg 2

Call back to background process

fg 2

Background runs are not affected by shell exits

nohup cmd&

Clear the entire screen

clear

Reinitialize the screen

reset

1000 used commands by default

history

Clearly documented commands

history -c

cat /root/.bash_history

View logged in user information

last

last -n user

who/var/log/wtmp

List information about users who failed to log in to the system

lastb -a

/var/log/btmp

Firewall log

tail -f/var/log/messages

ssh log

tail -f/var/log/secure

Randomly Generated Password

mkpasswd

-l digits -c size -c lowercase -d number -s special characters

mkpasswd -l 8 -c 2 -c 2 -d 4 -s 0

Online users

who

w

View the current username

whoami

View login username

logname

Show monthly calendar

cal

View server startup time

uptime

Set date

date -s 20091112

Set time

date -s 18:30:50

synchronised time

/usr/sbin/ntpdate stdtime.gov.hk

7 days before

`date -d" 7 days ago "+%y%m%d`

Date format conversion

`date +%y-%m-%d -d" 20110902 "`

Date and time

date +%y-%m-%d_%x

View time

hwclock

Account shadow file

/etc/shadow

List all languages

locale -a

Change language

lang=en

Modify encoding

vi/etc/sysconfig/i18n

utf-8<--->gbk

Mandatory character set

export lc_all=c

Querying static host names

vi/etc/hosts

Maximum connection

/etc/security/limits.conf

grub boot entry added

/etc/grub.conf

title ms-dos

rootnoverify (hd0,0)

chainloader +1

Alias

alias

Monitoring orders

watch

View linux version information

uname -a

cat/proc/version

cat/etc/issue

lsb_release -a

View cpu information

more/proc/cpuinfo

View cpu model and number of logical cores

cat/proc/cpuinfo | grep name | cut -f2 -d:| uniq -c

Number of bits for cpu operation

getconf long_bit

Number of physical cpu

cat/proc/cpuinfo | grep physical | uniq -c

Results greater than 0 support 64-bit

cat/proc/cpuinfo | grep flags | grep "lm" | wc -l

See if the CPU supports virtualization

cat/proc/cpuinfo | grep flags

pae supports paravirtualization, Intel vt supports full virtualization

View memory information

more/proc/meminfo

View comprehensive hardware information

dmidecode

View server model

dmidecode | grep "product name"

View soft raid information

cat/proc/mdstat

View hard raid information

cat/proc/scsi/scsi

Viewing hardware information

lspci

See if raid is supported

lspci | grep raid

Display boot information

dmesg

Process tree

pstree

Report virtual memory statistics 9 times per second

vmstat 1 9

Increase the priority of process 180

renice +1 180

Terminate a pid process

kill -9 pid

/Bin/ls execute at 5:00 PM three days later

at 5pm + 3 days/bin/ls

Edit Periodic Task

crontab -e

Minute hour day month week command or script

01 1-3/2 * * * Command or script

Write commands directly to periodic tasks

echo "40 7 * * 2/root/sh" >>/var/spool/cron/root

View automatic recurring tasks

crontab -l

Delete automatic periodic tasks

crontab -r

Disable or allow users to use periodic tasks

cron.deny and cron.allow

Start automatic periodic service

service crond start | stop | restart | status>

Whether a port is open

netstat -anlp | grep port number

View listening

netstat -anlp

sudo command permissions added

visudo

User alias (all available)=nopasswd:command 1, command 2

wangming linuxfan=nopasswd:/sbin/apache start,/sbin/apache restart

username all=(all) all

Making patches

diff suzu.c suzu2.c>sz.patch

Install patches

patch suzu.c<sz.patch

Display all processes that open the specified file

lsof file

View the progress of the port

lsof -i:32768

Shows the 10 running processes that consume the most memory,Sort by memory usage.cpu +3

ps aux | grep -v user | sort -nk +4 | tail

View kernel modules

lsmod

yum extension source

http://download.fedoraproject.org/pub/epel

wget http://download.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm

rpm -uvh epel-release-5-4.noarch.rpm

Upgrade all package versions,Dependencies,System version kernel is upgraded

yum -y update

Upgrade specified packages

yum -y update package name

Update software without changing software settings,System version upgrade,The kernel does not change

yum -y upgrade

yum search related packages

yum search mail

Will change the configuration file,Change old dependencies,Change system version

dist-upgrade

Edit startup item

/boot/grub/grub.conf

Boot startup script sequence

/etc/profile

/etc/profile.d/*.sb

~/bash_profile

~/.bashrc

/etc/bashrc

-------------------------------------------------- ------------------

top

The first five lines are the overall statistics of the system.

The first line is task queue information,Same as the execution result of the uptime command.Its contents are as follows:

01:06:48 Current time

up 1:22 system runtime,Format is hour:minute

1 user currently logged in users

load average:0.06, 0.60, 0.48 system load,The average length of the task queue.

The three values ​​are the average of 1 minute, 5 minutes, and 15 minutes ago to the present.

The second and third lines are the process and CPU information. When there are multiple CPUs, these contents may exceed two lines.The contents are as follows:

tasks:29 total

1 running number of running processes

28 sleeping

0 stopped number of processes stopped

0 zombie zombie processes

cpu (s):0.3%us

1.0%sy kernel space occupied cpu percentage

0.0%ni Percentage of CPU occupied by processes that have changed priority in user process space

98.7%id idle cpu percentage

0.0%wa CPU time percentage waiting for input and output

0.0%hi

0.0%si

The last two lines are memory information.The contents are as follows:

mem:191272k total physical memory

173656k used total physical memory used

17616k free total free memory

22052k buffers Amount of memory used as kernel cache

swap:192772k total

0k used Total swap area used

192772k free

123988k cached The total amount of buffered swap area.

The contents of the memory are swapped out to the swap area,And then swapped into memory,But the used swap area has not been covered,

This value is the size of the swap area where these contents already exist in memory.

When the corresponding memory is swapped out again, it is no longer necessary to write to the swap area.

Process information area

Details of each process are displayed below the statistics area.Let's first understand the meaning of each column.

Number column name meaning

a pid process id

b ppid parent process id

c ruser real user name

d uid user id of process owner

e user The user name of the process owner

f group process owner group name

g tty The name of the terminal that started the process.Processes not started from the terminal are displayed as?

h pr priority

i ni nice value. Negative values ​​indicate high priority,Positive values ​​indicate low priority

The last CPU used by j p is only meaningful in a multi-cpu environment

k%cpu CPU time percentage last updated to now

l time total CPU time used by the process,Unit of second

m time + total CPU time used by the process,1/100 second

n%mem percentage of physical memory used by the process

o The total amount of virtual memory used by the virt process,The unit is kb. virt=swap + res

p swap process in virtual memory,Swapped out size,The unit is kb.

q res the amount of physical memory that has not been swapped out,The unit is kb. res=code + data

r code the amount of physical memory occupied by the executable code,Unit kb

s data The amount of physical memory occupied by parts other than the executable code (data segment + stack),Unit kb

t shr shared memory size,Unit kb

u nflt page faults

v ndrt was last written to now,The number of pages that have been modified.

w s process status.

d=Uninterruptible sleep state

r=run

s=sleep

t=Track/Stop

z=zombie process

x command command name/command line

y wchan if the process is sleeping,Show the system function names in sleep

z flags task flags,See sched.h

###################################

iptables

Three built-in tables:nat mangle and filter

filter preset rule table,There are three rule chains of input, forward and output

input

forward

output out

accept the packet

reject block the packet

Drop discarded packets without processing

-a Add one or more rules to the end of the selected chain (input, etc.)

-d delete one

-e modify

-p tcp, udp, icmp 0 is equivalent to all all!

-p sets the default policy (does not match all chains and enforces this policy)

-s ip/mask (ip/24) hostname, network name, and clear ip address!

-j target jump,Dedicated built-in target that immediately decides the fate of the pack

-i incoming (network) interface [name] eth0

-o output interface [name]

-m module

--sport source port

--dport target port

#Configuration file

vi/etc/sysconfig/iptables

#Clear the rule entries in the firewall

iptables -f

#Note:iptables -p input accept

#Import firewall rules

iptables-restore<rules file

#Save firewall settings

/etc/init.d/iptables save

#Restart the firewall service

/etc/init.d/iptables restart

#View rules

iptables -l -n

iptables -l -n --line-numbers

#Remove a rule from a rule chain

iptables -d input --dport 80 -j drop

iptables -d input 8

#Replaces the current rules

iptables -r input 8 -s 192.168.0.1 -j drop

#Insert a rule

iptables -i input 8 --dport 80 -j accept

#View forwarding

iptables -t nat -nl

#Enable ip forwarding in the kernel

echo 1>/proc/sys/net/ipv4/ip_forward

###################################

#Allow local loopback

iptables -a input -s 127.0.0.1 -p tcp -j accept

#Allow established or related access

iptables -a input -m state --state established, related -j accept

#Open external access

iptables -p output accept

#Specify that a port is open for IP

iptables -a input -s 192.168.10.37 -p tcp --dport 22 -j accept

#Allowed IP or IP segment access

iptables -a input -s 192.168.10.37 -p tcp -j accept

#Open to the outside world

iptables -a input -p tcp --dport 80 -j accept

#Close the entrance

iptables -p input drop

#Turn off forwarding

iptables -p forward drop

###################################

iptables rules file

#generated by iptables-save v1.2.11 on fri feb 9 12:10:37 2007

* filter

:input drop [637:58967]

:forward drop [0:0]

:output accept [5091:1301533]

#Allowed IP or IP segment access

-a input -s 127.0.0.1 -p tcp -j accept

-a input -s 192.168.0.0/255.255.0.0 -p tcp -j accept

#Open to the outside world

-a input -p tcp --dport 80 -j accept

#Specify that a port is open for IP

-a input -s 192.168.10.37 -p tcp --dport 22 -j accept

#Reject all protocols (when input is allowed)

#-a input -p tcp -m tcp --tcp-flags fin, syn, rst, psh, urg rst -j drop

#Allow established or related traffic

iptables -a input -m state --state established, related -j accept

#Reject ping

-a input -p tcp -m tcp -j reject --reject-with icmp-port-unreachable

commit

#completed on fri feb 9 12:10:37 2007

###################################

Common examples

#Allow IP access to the specified port

iptables -a input -s 192.168.62.1 -p tcp --dport 22 -j accept

#Prohibit the use of a port

iptables -a input -p tcp --dport 22 -j drop

iptables -a input -p tcp --dport 31 -j reject

#Ban qq port

iptables -d forward -p udp --dport 8000 -j reject

#Disable icmp port

#Except 192.168.62.1, forbid others to ping my host

iptables -a input -i eth0 -s 192.168.62.1/32 -p icmp -m icmp --icmp-type 8 -j accept

iptables -a input -i eth0 -p icmp -m icmp --icmp-type 8 -j drop

#Other circumstances are not allowed

iptables -a input -i eth0 -j drop

#Prohibit specified IP access

iptables -a input -p tcp -s ip -j drop

#Prohibit specified IP access port

iptables -a input -p tcp -s ip --dport port -j drop

#Block all TCP connections that are not authorized by your system

iptables -t filter -a input -i eth0 -p tcp --syn -j drop

#Add network segment forwarding

iptables -t nat -a postrouting -s 10.8.0.0/24 -j masquerade

#ip packet traffic limit

iptables -a input -f -m limit --limit 100/s --limit-burst 100 -j accept

iptables -a input -i eth0 -p icmp -j drop

#Port Mapping

iptables -t nat -a prerouting -i eth0 -p tcp -s 192.168.62.0/24 --dport 80 -j redirect --to-ports

3128

#List all rules in a rule chain

iptables -l input

#Delete a rule chain,Without a regular chain,Clear all non-built-in

iptables -x allowed

#Reset the packet counter to zero

iptables -z input

#Define new rule chain

iptables -n allowed

#Define filtering policy

iptables -p input drop

#Modify the name of a custom rule chain

iptables -e allowed disallowed

#Compare whether the communication protocol types match

#-p! tcp Exclude udp and icmp other than tcp. -p all all types

iptables -a input -p tcp

#Compare the source IP of the packet

#192.168.0.0/24! Reverse comparison

iptables -a input -s 192.168.1.1

#Compare the destination IP of the packet

iptables -a input -d 192.168.1.1

#Compare which network card the packet came from

#eth + means all network cards

iptables -a input -i eth0

#Compare which network card the packet is sent from

iptables -a forward -o eth0

#Compare the average traffic of packets over a period of time

#Example is used for comparison:whether the average traffic per hour exceeds 3 packets. In addition to the average times per hour,Also every

Seconds, minutes, or once per day,The default is an average every hour.The parameters are as follows:/second,/minute,/day.

In addition to the number of closures,Setting this parameter will alsoPause the comparison of packets,To avoid

The hacker used the flood attack method,As a result, services are blocked.

iptables -a input -m limit --limit 3/hour

#Compare the number of instantaneous packets

#The example is used to compare whether there are more than 5 packets coming in at one time (this is the default value). The packets exceeding this limit will be straight

Then discard. The effect is the same as above.

iptables -a input -m limit --limit-burst 5

#Compare packets from this machine

#Whether it was generated by a particular user.This can prevent the server from transmitting sensitive data using root or other identities,

Can reduce the loss of system hacking.Unfortunately, this function cannot compare packets from other hosts.

iptables -a output -m owner --uid-owner 500

#Compare packets from this machine

iptables -a output -m owner --gid-owner 0

iptables -a output -m owner --pid-owner 78

iptables -a output -m owner --sid-owner 100

#Used to compare online status

iptables -a input -m state --state related, established

There are four online states:invalid, established, new, and related.

The #-j parameter specifies the processing action to be performed,Processing actions include:accept, reject, drop, redirect,

masquerade, log, dnat, snat, mirror, queue, return, mark, description:

iptables -a forward -p tcp --dport 22 -j reject --reject-with tcp-reset

#There are several options for packets that can be transmitted:icmp port-unreachable, icmp echo-reply or tcp-reset

redirect redirects the packet to another port (pnat)

iptables -t nat -a prerouting -p tcp --dport 80 -j redirect --to-ports 8080

masquerade rewrite packet source ip to firewall nic ip

iptables -t nat -a postrouting -p tcp -j masquerade --to-ports 1024-31000

log logs messages about packets in/var/log

iptables -a input -p tcp -j log --log-prefix "input packets"

snat rewrite packet source IP to a specific IP or IP range

iptables -t nat -a postrouting -p tcp-o eth0 -j snat --to-source

194.236.50.155-194.236.50.160:1024-32000

dnat rewrite packet destination IP to a specific IP or IP range

iptables -t nat -a prerouting -p tcp -d 15.45.23.67 --dport 80 -j dnat --to-destination

192.168.1.1-192.168.1.10:80-100

mirror mirror packet

queue interrupt filter

return ends the filter in the current rule

mark Mark the packet with a code

###################################

iptables configuration example

Allow a certain IP to access any port

iptables -a input -s 192.168.0.3/24 -p tcp -j accept

Set default rules (reject all packets,Allow again what is needed,Such as only web server. It is recommended that all three chains are

drop)

iptables -p input drop

iptables -p forward drop

iptables -p output accept

(Note:It is intended to directly set these three lines down)

Open port 22

iptables -a input -p tcp --dport 22 -j accept

If output is set to drop, write the following

iptables -a output -p tcp --sport 22 -j accept

(Note:If you don't write, you can't ssh. Like other ports,(If output is set to drop, also add a chain)

If the web server is enabled and the output is set to drop, a chain must also be added.

iptables -a output -p tcp --sport 80 -j accept

Be a web server, open port 80, and other similar

iptables -a input -p tcp --dport 80 -j accept

Be a mail server,Open port 25,110

iptables -a input -p tcp --dport 110 -j accept

iptables -a input -p tcp --dport 25 -j accept

Allow icmp packets to pass and ping

iptables -a output -p icmp -j accept (if output is set to drop)

iptables -a input -p icmp -j accept (if input is set to drop)

Allow loopbacks!

iptables -a input -i lo -p all -j accept (if input drop)

iptables -a output -o lo -p all -j accept (if output drop)

======================================================= ====================

----------------------------------

4 Service management

----------------------------------

Start the sendmail service

./sendmail start

/etc/init.d/sendmail start

Turn off the sendmail service

./sendmail stop

View the current status of the sendmail service

./sendmail status

send email

echo content |/bin/mail -s "title" inbox

Opening the service list requires typing *

ntsysv

Stop a service from starting automatically 35 refers to run level

httpd:chkconfig --level 35 httpd off

Let a service start automatically

httpd:chkconfig --level 35 httpd on

View the startup status of all services

chkconfig --list

View the startup status of a service

chkconfig --listgrep httpd

View the status of a service

chkconfig --- list [service name]

Set non-standalone service start status

chkconfig service name on | off | set

Start mysql running in the background

/usr/local/mysql/bin/mysqld_safe --user=mysql&

Boot up execution

vi /etc/rc.d/rc.local

Power on and off to close the service connection

/etc/rc.d/rc3.d/s55sshd

#s start start k shutdown stop 55 level followed by service name

ln -s -f/usr/local/httpd/bin/apachectl /etc/rc.d/rc3.d/s15httpd

======================================================= ====================

----------------------------------

5 Network Management

----------------------------------

###################################

Native network profile

vi/etc/sysconfig/network-scripts/ifcfg-eth0

device=eth0

bootproto=none

broadcast=192.168.1.255

hwaddr=00:0c:29:3f:e1:ea

ipaddr=192.168.1.55

netmask=255.255.255.0

network=192.168.1.0

onboot=yes

type=ethernet

gateway=192.168.1.1

###################################

Increase logical ip address

ifconfig eth0:0 192.168.1.221 netmask 255.255.255.0

View routing table

route

Add routing table

route add default gw 192.168.1.1 dev eth0

Set up dns

vi /etc/resolv.conf

Disable network card

ifconfig eth0 down

Enable network card

ifconfig eth0 up

ifup eth0:0 up

Test hop count

traceroute www.google.com (linux)

tracert www.google.com (windows)

Calculate mask based on ip and maximum number of hosts

ipcalc -m "$ip" -p "$num"

Download the entire website recursively with wget

wget --random-wait -r -p -e robots=off -u mozilla www.example.com

Read wikipedia's hacker entries by dns

dig + short txt hacker.wp.dg.cx

host -t txt hacker.wp.dg.cx

rz ssh small file upload

sz ssh small file download

Ssh login to another linux

ssh -p 22 [email protected]

Operate a remote host using ssh

ssh -p 22 [email protected] environment variable in the script

Copy local files to remote host

scp -p 22 file [email protected]:/directory

ssh connection does not prompt yes

ssh -o stricthostkeychecking=no 192.168.70.130

Copy remote specified files to local

scp [email protected]:remote directory local directory

Mount a folder on a remote host via ssh

sshfs [email protected]:/path/to/folder/path/to/mount/point

To uninstall, use the fusermount command

fusermount -u/path/to/mount/point

Compare remote files with local files with diff

ssh [email protected] cat/path/to/remotefile | diff/path/to/localfile-

Create a port forwarding channel with ssh

ssh -n -l2001:remotehost:80 [email protected]

Nested using ssh

ssh -t host_a ssh host_b

Key trust

ssh-keygen --t rsa

vi user/.ssh/authorized_keys

Remotely shut down a windows machine

net rpc shutdown -i ip_address -u username%password

Disable ping

echo 1>/proc/sys/net/ipv4/icmp_echo_ignore_all

###################################

First ping the open ports of the scanning host

nmap -pt 192.168.1.1-111

Scan out the system kernel version

nmap -o 192.168.1.1

Software version of the scan port

nmap -sv 192.168.1.1-111

Half-open scan (generally not logged)

nmap -ss 192.168.1.1-111

Does not support windows scanning (determining whether it is windows)

nmap -sf 192.168.1.1-111

nmap -sx 192.168.1.1-111

nmap -sn 192.168.1.1-111

Scan without ping

nmap -p0 192.168.1.1-111

details

nmap -d 192.168.1.1-111

Can't find out the real scan host (hidden ip)

nmap -d 192.168.1.1-111

Port range

nmap -p 20-30,139,60000-

Means:Scan ports 20 to 30, port 139, and all ports greater than 60000

Combined scan (no ping, software version, kernel version, details)

nmap -p0 -sv -o -v 192.168.30.251

###################################

======================================================= ====================

----------------------------------

6 Disk management

----------------------------------

View hard drive capacity

df -h

View disk partition format

df -t

Modify read-only file system to read and write

mount -o remount, rw /

View label

e2label/dev/sda5

Create a volume label

e2label/dev/sda5 new-label

ntfs add volume label

ntfslabel -v/dev/sda8 new-label

ext2 partition to ext3 partition

tune2fs -j/dev/sda

Format partition

mkfs -t ext3/dev/hda3

Specify the index block size

mke2fs -b 2048/dev/sda5

File system repair

fsck -y/dev/sda6

View superblock information

dumpe2fs -h/dev/sda5

View the file systems supported by the current system

cat/proc/filesystems

Detect hard drive status

smartctl -h/dev/sda

Detect hard drive information

smartctl -i/dev/sda

Detect all information

smartctl -a/dev/sda

Detect all file sizes in a directory

du -h directory

Display the size of subdirectories in the current directory

du -h --max-depth=1

Mount the optical drive

mount -t iso9660/dev/dvd/mnt

Mount the image file

mount -o loop /software/rhel4.6.iso/mnt /

###################################

Disk grub boot entry added

/etc/grub.conf

title ms-dos

rootnoverify (hd0,0)

chainloader +1

###################################

Build soft raid1

The two hard disk partitions are the same,Create new partition file type as software raid

Create two, click raid to merge into raid1, the mount point here is the normal linux directory

View raid work status

cat/proc/mdstat

Grub boot on both disks

View

cat /boot/grub/grub.conf

grub

root (hd0,0)

setup (hd0)

root (hd1,0)

setup (hd1)

Modify the grub boot entry configuration file

vi /boot/grub/grub.conf

Copy title centos to the last four lines

Paste and modify the newly added guide (hd1,0) just below.

View partition

sfdisk -d/dev/hda

Export a drive partition list

sfdisk -d/dev/hda>fq.hda

Import partition list to newly added hard drive

sfdisk/dev/hdb<fq.hda

Recover newly mounted hard disk partition

mdadm/dev/md1 -a/dev/hdb5

#raid5 Use lvm to expand capacity

###################################

New hard disk mount

fdisk/dev/sdc

p #print partition

d #delete partition

n #create partition,(A hard disk can have up to 4 primary partitions.Extensions occupy a primary partition location.p main partition e extended)

w #save and exit

mkfs -t ext3 -l Volume label/dev/sdc1 #Format the corresponding partition

mount/dev/sdc1/mnt #mount

Add boot mount partition

vi/etc/fstab

Mount with volume label

label =/data/data ext3 defaults 1 2

Mount with real partition

/dev/sdb1/data4 ext3 defaults 1 2

The first number is "1". This option is used by the "dump" command to check how often a file system should be dumped.If not needed

To dump, set this field to 0

The second number "2" This field is used by the fsck command to determine the order of file systems that need to be scanned at startup,Root file system

The value of "/" should be 1 for other fields and 2 for other file systems. Set this if the file system does not need to be scanned at startup

Field is 0

###################################

======================================================= ====================

----------------------------------

7 User Management

----------------------------------

Create users

useradd xuesong

change Password

passwd user

echo "xuesong" | passwd xuesong --stdin

Find user display information

finger

Add group

groupadd

Modify file owner (r recursive)

chown -r

Modify owner user to include dot "."

chown y \ .li:mysql

Modify user group

chgrp

Modify username

usermod -l new username old username

Modify the group the user belongs to

usermod -g user group

Modify user home directory

usermod -d directory -m user

Adding users to additional groups

usermod -g user group

Delete account and home directory

userdel -r

The specified group does not allow logged in users

useradd -g www -m -s/sbin/nologin www

Switch user execution

su-user -c "

#Command 1

"

======================================================= ====================

----------------------------------

8 Script related

----------------------------------

###################################

Regular expression

^ Beginning of line positioning

$Behavioral targeting

. Matches any character except newline

* Matches 0 or more repeated characters

+ Repeat one or more times

?Repeat zero or one time

[] Matches any one character in a group

[^] Match characters not in the specified group

\ Used to escape metacharacters

\<prefix locator (supports vi and grep)

\<love

\>Final locator (supports vi and grep)

love \>

x \ {m \} repeated m times

x \ {m, \} repeats at least m times

x \ {m, n \} repeats at least m times and no more than n times

x?matches capital letter x that appears zero or one

x + matches one or more letters x

(abc | def) + matches a sequence of (at least one) abc or def;abc and def will match

\ d matches any single digit

\ d matches any single non-numeric character

\ w matches any single alphanumeric character,Synonyms are [:alnum:]

\ s matches any whitespace

\ b matches the beginning or end of a word

[:alpha:] represents all letters, regardless of case

[:lower:] means lowercase letters

[:upper:] means uppercase letters

[:digit:] represents numeric characters

() The characters in parentheses are a group

###################################

Basic process structure

if [$a == $b]

then

echo "equal to"

else

echo "not equal"

fi

###################################

case $xs in

0) echo "0" ;;

1) echo "1" ;;

*) echo "other" ;;

esac

###################################

num=1

#while true is equivalent to while:

while [$num -lt 10]

do

echo $num

((num=$num + 2))

done

###################################

grep a a.txt | while read a

do

echo $a

done

###################################

w=`awk -f":"" {print $1} "c`

for d in $w

do

$d

done

###################################

for ((i=0;i<${#o [*]};i ++))

do

echo ${o [$i]}

done

###################################

until loop #when command is not 0

until command

do

body

done

###################################

Process control

break n #break out of several layers of loop

continue n #jump out of several layers of loop,The number of cycles does not change

continue #The number of repetitions does not change

###################################

variable

Assign variable a to a string

a="a b c def"

a=`command`

Indirect call

eval a=\ $$a

Define the variable a as the number of groups

a=(a b c def)

set a1 a2 a3 a4

$1 $2 $*

Run in subshell

(a=bbk)

Defining variable types

declare or typeset

-r read-only (same as readonly)

-i shaping

-a array

-f function

-x export

declare -i n=0

env #View environment variables

env | grep "name" #View defined environment variables

set #View environment and local variables

read name #input variable

readonly name #Set the name variable to read-only,Not allowed to set again

readonly #View the read-only files that exist on the system

export name #variable name from local to environment

export name="redhat" #directly define name as an environment variable

export stat $nu=2222 #variable reference variable assignment

unset name #variable clear

export -n name #remove read-only variables

shift #for moving position variables,Adjusting position variables,Assign $3 to $2. $2 to $1

name + 0 #convert string to number

number "" #convert numbers to strings

Common system variables

$0 #script startup name (including path)

basename $0 #only the script name

$n #The nth parameter of the current program, n=1,2, ... 9

$* #All parameters of the current program (not including the script itself)

$##The number of parameters of the current program (not including the script itself)

$$#pid of the current program

$! #Pid to execute the previous instruction

$?#execute the return value of the previous instruction

Variable reference techniques

$(name:+ value) #If name is set, display value, if not set, it is empty

$(name:-value) #if name is set, display it,Show value if not set

${name:& #63;value} #User error message value is not set

${name:= value} #If not set, set value and display,

${#a} #get the bytes in the variable

${#a [*]} #number of arrays

${a [2]} #A parameter of the script

${a:4:9} #Take 4th to 9th digits

${a/www/http} #take a variable and replace the first keyword on each line

${a //www/http} #take variables and replace each line of keywords

A variable is defined as:

file =/dir1/dir2/dir3/my.file.txt

${file #* /} #remove the first/and the left string:dir1/dir2/dir3/my.file.txt

${file ##* /} #remove the last/and the string on the left:my.file.txt

$(file #*.) #remove the first one. And the string to its left:file.txt

$(file ##*.) #remove the last one. And its left string:txt

${file%/*} #remove the last line/and the right string:/dir1/dir2/dir3

${file %%/*} #remove the first/and the string to its right:(null)

$(file%. *) #remove the last one. And the string to its right:/dir1/dir2/dir3/my.file

$(file %%. *) #remove the first one. And the string to its right:/dir1/dir2/dir3/my

##Is stripped to the left (on the keyboard #to the left of $)

#%Is stripped to the right (%is to the right of $on the keyboard)

#Single symbol is the smallest match ﹔ Two symbols are the biggest match

###################################

test condition judgment

#Symbol [] equivalent to test

expression is a string operation

-n str #Whether the string str is not empty

-z str #Whether the string str is empty

expression is a file operation

-b #block file

-p #whether the file is a named pipe

-c#whether a character file

-r #whether the file is readable

-d #is a directory

-s #Whether the length of the file is not zero

-e #whether the file exists

-s #whether it is a socket file

-f #whether it is a normal file

-x #whether the file is executable,True

-g #whether the sgid bit of the file is set

-u #Whether the suid bit of the file is set

-g #Whether the file exists and is owned by the group

-w #whether the file is writable,True

-k #whether the file is pasted

-t fd #fd is an open file descriptor connected to the terminal (fd defaults to 1)

-o #Whether the file exists and is owned by the user

! #Negate

expression is an integer operation

expr1 -a expr2 #If expr1 and expr2 evaluate to true,True

expr1 -o expr2 #If expr1 or expr2 evaluates to true,True

Two-value comparison

Integer string

-lt&​​lt ;:#less than

-gt> ;:#greater than

-le<=:#less than or equal to

-ge>=:#greater than or equal to

-eq ==:#wait

-ne! =:#is not equal to

Judging the size,0 is true, 1 is false

test 10 -lt 5

echo $?

1

Determines whether the string length is 0

test -n "hello"

0

###################################

Redirect

#Stdout and stderr stdin stdin

cmd 1>fiel #redirect standard output to file

cmd>file 2>&1 #redirect standard output and standard error to file

cmd 2>file #redirect standard error to file

cmd 2>file>redirect standard error to file (append)

cmd>>file 2>&1 #redirect standard output and standard error to file (append)

cmd<file>file2 #cmd command takes file file as stdin (standard input) and file2 file as standard

Quasi-output

cat<file #open file for reading and writing

cmd<file cmd #command with file as stdin

cmd<delimiter

cmd;#Read from stdin until the delimiter delimiter is encountered.

delimiter

Operator

most

Otherwise 0

The result is 1,

Otherwise 0

Operator precedence

computation

Operation

let

expr

loop=`expr $loop + 1`

Will return an error.)

6

grep usage

-i ignore case

Case Sensitive

\ f form feed

\ n newline

\ r enter

= Assignment

}

end {

eof

eof

eof

Until the end

p print

d delete

!!

progress bar

announcement

Select date

#!/bin/sh

random number

Process number

$$

sleep 5

trap

Current directory

$pwd

yes

#!/bin/sh

echo $name

Loop array

do

done

fi

fi

#!/bin/sh

do

if [$?-eq 0]

then

fi

done

#!/bin/sh

do

shift

done

#!/bin/sh

do

case $name in

;;

;;

exit 1

;;

esac

done

fi

fi

#!/bin/sh

exit 1

fi

do

case $name in

u)

;;

p)

;;

h)

;;

*)

exit 1

;;

esac

done

then

exit 1

fi

then

break

fi

then

break

fi

1)

;;

;;

esac

while:

do

then

then

break

else

"

fi

else

"

fi

done

#!/bin/sh

} "

do

} "

done

} "

#!/bin/sh

do

then

break

else

"

fi

else

"

fi

done

#!/bin/bash

n=0

while:;do

else

fi

done

#content

eof

eof

eof

#!/bin/sh

a=1

b=1

do

then

b=`expr $b + 1`

a=1

fia

done

#!/bin/sh

do

done

#!/bin/bash

do

done

#!/bin/bash

done

i=0

do

then

then

fi

fi

done

======================================================= ====================

----------------------------------

----------------------------------

samba

/etc/samba/smb.conf

[global]

workgroup=workgroup

[file]

Restart

service smb restart

type master;

allow-update {none;};

};

3h

15m

1w

1d

)

vi /etc/resolv.conf

Main configuration file

service vsftpd restart

local_enable=yes

chroot_local_user=yes

(11)

(12)

(13)

#!/bin/sh

read m

make&&make install

groupadd www

boot

vi /etc/rc.d/rc.local

servername 127.0.0.1:80

Encoding settings

adddefaultcharset utf-8

groupadd mysql

./configure --prefix =/usr/local/mysql \

--with-client-ldflags=-all-static \

--with-mysqld-ldflags=-all-static \

--with-mysqld-user=mysql \

make&&make install

scripts/mysql_install_db --user=mysql

Configuration file,

cp support-files/my-medium.cnf /etc/my.cnf

cd/usr/local

ln -s/usr/local/mysql/bin/mysql/sbin/mysql

ln -s/usr/local/mysql/bin/mysqladmin/sbin/mysqladmin

/etc/init.d/mysqld start

mysql commonly used commands

Refresh

flush privileges;

show databases;

Open database

use dbname;

show tables;

Delete database

drop database name;

Delete table

Create database

create database name;

Create table

Inquire

select host, user, password from user;

backup database

Restore the database

change the password

select user ();

delete users

show variables like "character_set_%";

show variables;

delete from user where user="";

show variables;

select host, user, password from user;

show table status

zlib-1.2.3.tar.gz

./configure

make

make install

./configure

make

make install

make

make install

--enable-shared \

make

make install

--with-zlib \

make

make install

--with-zlib \

--with-openssl \

--with-bz2 \

--with-gettext \

--enable-ftp \

--enable-bcmath \

--enable-sockets \

--enable-soap \

--enable-mbstring \

--with-pdo-mysql =/usr/local/mysql \

--with-mysqli =/usr/local/mysql/bin/mysql_config

make

make install

vi /usr/local/php/lib/php.ini

phpinfo ();

?>

Restart httpd

#setenforce 0

#service httpd restart

can.

install software

record it

Time of death

turn on

bye

test

sysctl -p

bye

sysctl -p

bye

test

vi /etc/resolv.conf

install software

m4

rpm -qa | grep gcj

Adding environment variables

vi/etc/profile

export

xm list

vcpus=1

on_poweroff="destroy"

on_crash="restart"

vcpus=1

on_poweroff="destroy"

on_crash="restart"

  • Previous Laravel uses memcached cache to optimize article additions, deletions, and changes
  • Next Image lazy loading plugin instance sharing (including parsing)