- 《Linux运维之道》笔记
- pwd
- cd
- ls
- touch
- mkdir
- cp
- rm
- mv
- find
- du
- cat
- more
- less
- head
- tail
- wc
- grep
- echo
- ln
- gzip
- vim
- useradd
- groupadd
- id
- passwd
- usermod
- userdel
- groupdel
- user && group file
- gpasswd
- chmod
- chown
- getfacl
- setfacl
- fdisk
- partprobe
- parted
- mkfs
- mount && umount
- df
- pvcreate
- vgcreate
- lvcreate
- pvdisplay
- vgdisplay
- lvdisplay
- cat
- lvextend
- lvs
- xfs
- lvremove
- vgremove
- pvremove
- iconv
- fdisk
- partprobe
- mdadm
- mkfs
- mkdir
- mount
- mount
- echo
- mdadm
- time
- mdadm
- rpm
- vim
- tar
- rpm
- rpm
- date
- kill
- yum
- systemctl
- systemctl
- systemctl
- vim
- uptime
- free
- df
- ip
- netstat
- ps
- top
- ifconfig
- hostnamectl
- route
- cat
- vi
- vi
- ping
- traceroute
- nslookup
- dig
- netstat
- alias
- rpm
- echo
- firefox
- firefox
- echo
- NAME
- TEST
- BASHPID
- echo
- NAME
- A
- echo
- cp
- sed
- cat
- awk
- xshell
- pwd
- ls
- cd
- mkdir
- rmdir
- rm
- cp
- ln
- locate
- whereis
- which
- echo
- find
- greb
- man
- help
- help
- info
- zip
- unzip
- gzip
- gzip
- gzip
- gunzip
- gunzip
- bzip
- bunzip
- tar
- tar
- zip
- unzip
- tar
- tar
- tar
- tar
- tar
- shutdown
- halt
- reboot
- runlevel
- cat
- logout
- mount
- linux
- umount
- w
- who
- last
- lastlog
- other:
《Linux运维之道》笔记
技巧:tab键,history,clear,which man /file n info n p u q
1
2
3
4
last
w
pkill
pwd
1
2
pwd
pwd -P
cd
1
2
3
4
5
6
cd
cd ..
cd -
cd
cd ~
cd /usr/src
ls
1
2
3
4
5
6
7
8
9
10
11
12
ls
ls /etc
ls -a
ls -l
ls -ld /root
ls -lh
ls -lu /etc/passwd
ls -lt
ls -d */
ls -lh |grep "^d"
ll -Sh |grep "^-"
ls >a
touch
1
touch hello.txt
mkdir
1
2
mkdir leo
mkdir -p /temp/test/jerry/book/computer
cp
1
2
3
4
cp /etc/hosts /tmp/
cp /etc/hosts /tmp/host
cp -r /var/log/ /tmp/
cp -a /etc/passwd /var/tmp
rm
1
2
rm readme.txt
rm -rf Jacob
mv
1
2
mv hello.txt hello.doc
mv hello.doc /root/
find
1
2
3
4
5
6
7
8
9
10
11
12
13
find -name hello.doc
find /root -name "*.log"
find -iname "Jacob"
find / -empty
find / -group tom
find / -mtime -3
find / -mtime +4
find / -mtime 2
find ./ -size +10M
find ./ -type f
find / -user tom
find ./ -size +1M -exec ls -l {} \;
find / -size +1M -a -type f
du
1
2
3
du /root
du -a /root
du -sh /root
cat
1
2
3
cat /root/install.log
cat -n /etc/passwd
cat -b /etc/passwd
more
1
more /root/install.log
less
1
less /root/install.log
head
1
2
head -c 2K /root/install.log
head -20 /root/install.log
tail
1
2
3
tail -c 2K /root/install.log
tail -20 /root/install
tail -f /var/log/messages
wc
1
2
3
4
wc /root/install.log
wc -c /root/install.log
wc -l /root/install.log
wc -w /root/install.log
grep
1
2
3
4
5
grep th test.txt
grep --color th test.txt
grep -i the test.txt
grep -w num test.txt
grep -v the test.txt
echo
1
2
3
4
5
6
7
8
9
echo "Hello The World"
echo -e "\\"
echo -e "\a"
echo -e "11\b22"
echo -e "hello\c"
echo -e "hello\ftheworld"
echo -e "hello\tthe\tworld"
echo -e "hello\vthe\vworld"
echo -e "\033[32mOK\033[0m"(30-37)
ln
1
2
3
4
5
ln -s /test/hello.txt /tmp/hi.txt
ln -s /test/ /var/test
rm /test/hello.txt;cat /tmp/hi.txt
ln /test/hello.txt /test/hi.txt
rm /test/hello.txt;cat /tmp/hi.txt
gzip
以下命令中以*
开头的为重点掌握命令
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
gzip hello.txt
gzip -d hello.txt.gz
bzip2 hello.txt
bzip2 -d hello.txt.bz2
tar -cf etc.tar /etc/
*tar -czf boot.tar.gz /boot
*tar -cjf etc.tar.gz /tmp/
tar --delete etc/hosts -f etc.tar
tar -f etc.tar -r /root/install.log
tar -tf boot.tar.gz
*tar -tvf etc.tar
*tar -xzf boot.tar.gz
*tar -xjf etc.tar.bz2
tar -xzf boot.tar.gz -C /tmp
tar -czf mess.tar.gz /var/log/messages --remove-files
vim
1
2
3
4
5
6
vim:进入插入模式:a,A,i,I,o,O
光标操作:h,j,k,l,gg,G,nG,^,$,fx,Fx,W,nw,b,nb
编辑文档:x,dd,ndd,d$,J,u,rx,yy,p,P,r !ls
查找与替换:/host n,N ?host n,N :s/root/admin/ :s/root/admin/g :3,5s/sbin/bin/g :%s/nologin/fault/g
保存与退出::q! :wq :x :w :w b.txt ZZ
技巧::set nu :set ignorecase :split ctrl+w+h左,ctrl+w+l右,ctrl+w+j上,ctrl+w+k下 :close :split second.txt :vsplit !ls ctrl+n自动补齐
useradd
1
2
3
useradd Frank
useradd -c administrator -d /home/admin -e 2013-12-24 -g root -u 500 -G\ bin,adm,mail admin
useradd -s /sbin/nologin -M user2
groupadd
1
2
groupadd tom
groupadd -g 1000 jerry
id
1
id root
passwd
1
2
3
4
5
6
passwd
passwd tom
echo "qwer0987" |passwd --stdin tom
passwd -l tom
passwd -u tom
passwd -d tom
usermod
1
2
3
4
5
usermod -d /home/tomcat tom
usermod -e 2017-10-01 tom
usermod -g mail tom
usermod -s /bin/bash user2
usermod -u 1001 tom
userdel
1
2
userdel tom
userdel -r tom
groupdel
1
groupdel jerry
user && group file
1
2
3
4
cat /etc/passwd
cat /etc/shadow
cat /etc/group
cat /etc/gshadow
gpasswd
1
2
3
gpasswd admin
gpasswd -A mail admin
421rwx
chmod
1
2
3
4
5
6
7
chmod u=rwx,g=rwx,o=rwx install.log
chmod a=rw install.log
chmod g-x,o-wx install.log
chmod 700 install.log
chmod 644 install.log
chmod 755 /home
chmod --reference=install.log.syslog install.log
chown
1
2
3
chown user2:mail install.log
chown :root install.log
chown root install.log
getfacl
1
getfacl install.log
setfacl
1
2
3
4
5
setfacl -m u:user1:rw test.txt
setfacl -m g:user1:r test.txt
setfacl -x g:user1 test.txt
setfacl -x u:user1 test.txt
setfacl -b test.txt
fdisk
1
2
3
4
5
IDE hd
SATA/USB/SCSI sd
CD/DVD sr
fdisk -l
fdisk /dev/sdb
partprobe
1
partprobe /dev/sdb
parted
1
2
3
4
5
parted /dev/sdb mklabel gpt
parted /dev/sdb print
parted /dev/sdb mkpart primary ext3 1 2G
parted /dev/sdb mkpart primary ext3 2G 4G
parted /dev/sdb rm 2
mkfs
1
2
mkfs.xfs /dev/sdb1
mkswap /dev/sdb2
mount && umount
1
2
3
4
5
6
7
8
9
10
mkdir /data1
mount /dev/sdc1 /data1
mount
touch /data1/test.txt
mount /dev/cdrom /media/
umount /dev/cdrom
umount /dev/sdc1
vi /etc/fstab
mount -a
mount
df
1
df -h
pvcreate
1
2
pvcreate /dev/sdb1 /dev/sde
pvcreate /dev/sdb{1,2,3}
vgcreate
1
2
vgcreate test_vg1 /dev/sdb5 /dev/sdb6
vgcreate test_vg2 -s 16M /dev/sdc5 /dev/sdc6
lvcreate
1
2
3
lvcreate -L 2G -n test_lv1 test_vg1
lvcreate -l 200 -n test_lv2 test_vg2
lvcreate -L 2G -n test_lv1 test_vg1 /dev/sdb6
pvdisplay
1
pvdisplay
vgdisplay
1
vgdisplay
lvdisplay
1
lvdisplay
cat
1
cat >>/etc/fstab <<EOF
lvextend
1
lvextend -L +12G /dev/test_vg/test_data
lvs
1
lvs
xfs
1
xfs_growfs /dev/test_vg/test_data
lvremove
1
lvremove /dev/test_vg/test_data
vgremove
1
vgremove /dev/test_vg
pvremove
1
pvremove /dev/sdb{1,2,3,5}
iconv
1
iconv -f gbk -t utf-8 .vimrc
fdisk
1
2
3
4
fdisk -l
fdisk /dev/sdb
fdisk /dev/sdc
fdisk /dev/sdd
partprobe
1
partprobe -a
mdadm
1
2
3
4
mdadm -C /dev/md0 -l 0 -n 3 /dev/sdb1 /dev/sdc1 /dev/sdd1
mdadm -C /dev/md1 -l 5 -n 3 -x 1 /dev/sdb2 /dev/sdc2 /dev/sdd2 /dev/sde2
mdadm --detail /dev/md0
mdadm --detail /dev/md1
mkfs
1
mkfs.xfs /dev/md0
mkdir
1
mkdir /raid0
mount
1
2
3
mount /dev/md0 /raid0
mkfs.xfs /dev/md1
mkdir /raid5
mount
1
mount /dev/md1 /raid5
echo
1
echo "DEVICE /dev/sdb1 /dev/sdb2 /dev/sdc2 /dev/sdd1 /dev/sdd2 /dev/sde2" >/etc/mdadm.conf
mdadm
1
2
3
4
5
6
7
8
mdadm -Evs >>/dev/mdadm.conf
echo "/dev/md0 /raid0 xfs defaults 0 0">> /etc/fstab
echo "/dev/md1 /raid5 xfs defaults 0 0">> /etc/fstab
cd
time dd if=/dev/zero of=txt bs=1M count=1000
cd /raid0
time dd if=/dev/zero of=txt bs=1M count=1000
cd /raid5
time
1
2
time dd if=/dev/zero of=txt bs=1M count=1000
mdadm /dev/md1 -f /dev/sdb2
mdadm
1
2
3
mdadm --detail /dev/md1
software manage:
rpm
1
2
3
4
5
6
7
8
9
10
11
rpm -vih ftp-0.17-51.1.el6.x85_64.rpm
rpm -e ftp
rpm -q ftp
rpm -qa
rpm -qi bash
rpm -ql bash
rpm -qc bash
rpm -qf /etc/inittab
rpm -qpi ftp-0.17-51.1.el6.x85_64.rpm
rpm -V bash
5 S L T D U G M ?
vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
vim /etc/yum.repos.d/media.repo
[media]
name=CentOS7
baseurl=file:///media/CentOS7
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
yum clean all
yum install dialog
yum -y expect
yum update
yum remove dialog
yum list
yum clean all
yum groulist
yum groupinstall "GNOME Desktop"
yum search web
yum history
yum langavailable
yum langinstall Chinese
yum install createrepo
createrepo /mysoft
$releasever $arch $basearch $YUM0-9
tar
1
2
3
4
5
6
tar -xzf xxx.tar.gz
cd xxx
./configure --help
./configure
make
make install
rpm
1
2
rpm --nodeps -ivh xxx
rpm --nodeps -e xxx
rpm
1
rpm --rebuilddb
date
1
2
date -s "2016-11-12 14:00"
hwclock -w
kill
1
kill 16613
yum
1
2
3
4
5
6
7
yum install gcc
### /usr/local/nginx/sbin/nginx
/usr/local/nginx/sbin/nginx
/usr/local/nginx/sbin/nginx -s stop
systemctl
1
2
3
4
5
6
7
8
systemctl start sshd
systemctl stop sshd
systemctl enable sshd
systemctl disable sshd
systemctl status sshd
systemctl reload sshd
systemctl condrestart sshd
systemctl
1
2
3
4
5
6
7
8
systemctl enable atd
at 23:11
tar -cjf log.tar.bz2 /var/log
shtdown -h now
ctrl-d
at -l
at -c 1
at -d 1
systemctl
1
2
3
4
5
6
systemctl enable crond
crontab -e
23 23 * * 5 tar -czf log.tar.bz2 /var/log
00 */3 * * * who
00 10 * * 3,5 free |mail -s "Mem" 2710121990@qq.com
copy xxx.sh /etc/cron.hourly|cron.daily|weekly
vim
1
2
3
4
5
vim /etc/at.allow
vi /etc/at.deny
vi /etc/cron.allow
vi /etc/cron.deny
uptime
1
uptime
free
1
2
free -m
df
1
2
3
df -hiT
df -hT
ip
1
2
ip a s
ip l show
netstat
1
2
3
netstat -nutlp
netstat -s
ps
1
2
3
4
ps -e
ps -ef
ps -ax
ps -axu
top
1
2
3
4
top
top -d 1 -p 1,2
M N z
ifconfig
1
2
3
4
ifconfig eno16777736 192.168.0.31 netmask 255.255.255.0
ifconfig eno16777736
ifconfig eno16777736 down
ifconfig eno16777736 up
hostnamectl
1
2
hostnamectl status
hostnamectl set-hostname centos.examples.com
route
1
2
3
4
5
6
7
route
route -n
route add default gw 192.168.0.254
route add -net 172.16.0.0/16 gw 192.168.0.254
route add -net 192.56.76.0 netmask 255.255.255.0 dev eno167777736
route del default gw 192.168.0.254
route del -net 172.16.0.0/16
cat
1
2
3
cat /etc/sysconfig/network-scripts/ifcfg-eno16777736
systemctl restart network
cat /etc/sysconfig/network-scripts/ifcfg-eno16777736:0
vi
1
vi /etc/sysconfig/network-scripts/route-eno16777736
vi
1
2
vi /etc/hostname
ping
1
2
3
4
ping 127.0.0.1
ping 192.168.0.31
ping 192.168.0.254
ping 202.106.0.20
traceroute
1
traceroute -I www.google.com
nslookup
1
nslookup www.google.com
dig
1
dig www.google.com
netstat
1
2
3
netstat -an
netstat -nutlp
alias
1
2
3
alias
alias h5="head -5"
unalias h5
rpm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
rpm -qa |grep gcc
echo "path"|passwd --stdin tom
ls
ls>list.txt
hostname>>list.txt
mail -s test xx@gmail.com < list.txt
ls -l abc install.log
ls -l abc install.log 2>error.txt
ls -l abc install.log >all 2>&1
ls -l abc install.log &>all
find /etc -name passwd & 2>&1 |less
fcitx-autostart & &>a
### ^a,^e,^f,^b,^l,^u,^k,^c,^z,^w,!d,Tab
^a,^e,^f,^b,^l,^u,^k,^c,^z,^w,!d,Tab
echo
1
2
echo "pass"|passwd --stdin root>/dev/null
id tom >> user 2>> error
firefox
1
2
3
4
5
6
firefox
firefox &
ls /tmp;ls /root ; ls /home
ls test.txt && cat test.txt
gpedit||vim
id tom &>/dev/null &&echo "Hi,tom" ||echo ""No such user"
firefox
1
2
3
firefox &
jobs
fg 1
echo
1
2
3
4
5
6
7
8
echo {a,b,c}
echo user{1,5,8}
echo {0..10}
echo {1..10..2}
echo a{2..-1}
mkdir /tmp/{dir1,dir2,dir3}
ls -ld /tmp/dir{1,2,3}
chmod 777 /tmp/dir{1,2}
NAME
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
NAME=tomcat
echo $NAME
typeset -r NAME
NAME=jerry
declare INT_NUMBER
typeset -i INT_NUMBER
INT_NUMBER=test
echo $INT_NUMBER
INT_NUMBER=200
echo $INT_NUMBER
read P_NUMBER
echo $INT_NUMBER
read -p "Please input a number:" P_NUMBER
echo $P_NUMBER
set
unset P_NUMBER
TEST
1
2
3
4
5
6
7
TEST=pass
echo $TEST
bash
echo $TEST
exit
export TEST
export NAME=tom
BASHPID
1
BASHPID,GROUPS,HOSTNAME,PWD, OLDPWD, RANDOM UID HISTSIZE HOME PATH PS1 PS2
echo
1
2
3
4
5
6
7
8
echo $PATH
ls
PATH=/root
ls
PATH=$PATH:/root
### $0,$1-9,$*,$@,$$,$?
$0,$1-9,$*,$@,$$,$?
NAME
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
NAME=Jacob
echo ${NAME:-no user}; echo ${NAME}
echo ${NAME:-no user}; echo ${EMAN}
echo ${NAME:=no user}; echo ${NAME}
echo ${EMAN:=no user}: echo ${EMAN}
echo ${NAME:?no defined}; echo ${EMAN}
echo ${EMAN:?no defined}; echo ${NAME}
echo ${NAME:+OK};echo ${NAME}
echo ${EMAN:+ERROR};echo ${EMAN}
USR=$(head -l /etc/passwd)
echo $USR
echo ${USR#*:}
echo ${usr##*:}
echo ${USR%:*}
echo ${USR%%:*}
echo ${USR/root/admin}
echo ${USR//root/admin}
A
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
A[1]=11
A[2]=22
A[3]=33
echo ${A[1]},${A[2]},${A[3]}
echo ${A[1]:$[A[2]}:${A[3]}
echo ${A[*]}
echo $A{[@]}
B=(aa bbb cccc)
echo ${B[0]}:${B[1]}:${B[2]}
echo "length of B_0 is ${#B[0]"
echo ${#B[@]}
### $((x++))
$((x++))
$((x%y))
$((x**y))
expr 3 \* 8
expr 3 % 8
test -d /etc/&&echo 'Y'||echo "NO"
test -d /etc/passwd && echo "Y"||echo "N"
[ -d /etc/ ] && echo "Y" || echo "N"
[ -e /etc/passwd ] && echo "Y" || echo "N"
[ -f /etc/password ] && echo "Y" || echo "N"
[ -h /etc/grub.conf ] && echo "Y" || echo "N"
[ -n $PATH ] && echo "Y" || echo "N"
[ -z $t ] && echo "Y" ||echo "N"
[ -z $PATH ] && echo ""Y"" || echo "N"
[ 22 -eq 22 ] && echo "Y" || echo "N"
[ 32 -ge 22 ] && echo "Y" || echo "N"
[ 10 -ge 22 ] && echo "Y" || echo "N"
[ 10 -le 22 ] && echo "Y" || echo "N"
echo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
echo *
echo \*
echo \>
find / \
>-name "test.txt" \
>-type f \
>-size +5M
echo '$HOME'
echo 'test\$'
echo '`date `'
echo "this's book."
echo "$HOME"
echo "\$HOME"
echo "`date`"
echo "$(date)"
cp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
cp /etc/passwd /tmp/
grep root /tmp/passwd
alias grep="grep --color"
grep :..0: /tmp/passwd
grep 00* /tmp/passwd
grep o[os]t /tmp/passwd
grep [0-9] /tmp/passwd
grep [f-q] /tmp/passwd
grep ^root /tmp/passwd
grep bash$ /tmp/passwd
grep sbin/[^n] /tmp/passwd
grep '0\{1,2\}' /tmp/passwd
grep "\(root\).*\1" /tmp/passwd
grep "\(root\)\(:\).*\2\1" /tmp/passwd
grep ^$ /tmp/passwd
grep -v ^$ /tmp/passwd
alias egrep="egrep --color" /tmp/passwd
egrep '0{1,2}' /tmp/passwd
egrep '0+' /tmp/passwd
egrep '(root|admin)' /tmp/passwd
grep [[:digit:]] /tmp/passwd
grep [[:alpha:]] /tmp/passwd
grep [[:punct:]] /tmp/passwd
grep [[:space:]] /tmp/passwd
grep "i\b" /tmp/passwd
grep "\W" /tmp/passwd
sed
1
2
3
4
5
6
7
8
9
10
11
12
sed '2a TYPE=Ethernet' test.txt
sed '3i TYPE=Ethernet' test.txt
sed 's/yes/no/g' test.txt
sed '3,4d' test.txt
sed '/ONBOOT/a TYPE=Ethernet' test.txt
sed '/^GATEWAY/d' test.txt
sed -f sed.sh test.txt
sed 's/yes/no/;s/static/dhcp/' test.txt
sed -e 's/yes/no' -e 's/static/dhcp' test.txt
sed '
>s/yes/no/
>s/static/dhcp/' test.txt
cat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
cat sed.sh
/body/{
s//\/body/2
}
sed -f sed.sh test.txt
cat sed.sh
/h[0-9]/{
s//\<&\>/1
s//\<\/&\>/2
}
sed -f sed.sh test.txt
/.*/{
/^$/d
}
/static/a IPADDR=192.168.0.1
/NETMASK/i IPADDR=192.168.0.1
/ONBOOT/c ONBOOT=yes
-n 1,2l
/.*/{
/netmask/y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/
}
-n '1,2p'
/.*/{
$r mail.txt
}
'2q'
#n
/Name/{
N
L
}
#n
/222/{
N
l
}
......
awk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
awk
mysql:
#install
yum -y install gcc make cmake ncurses-devel libxm12-devel libtool-ltd1-devel gcc-c++ autoconf automake bison zlib-devel
wget http://cdn.mysql.com/archives/mysql-5.6/mysql-5.6.11.tar.gz
groupadd mysql
useradd -r -s /sbin/nologin -g mysql mysql
tar -xzf mysql-5.6.11.tar.gz -C /usr/src/
cd /usr/src/mysql-5.6.11/
cmake . -DENABLE_DOWNLOADS=1
make && make install
chown -R mysql.mysql /usr/local/mysql
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data
cp /usr/local/mysql/my.cnf
/usr/local/mysql/bin/mysqld_safe --user=mysql &
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig/ --add mysqld
chkconfig mysqld on
PATH=$PATH:/usr/local/mysql/bin/
echo "export PATH=$PATH:/usr/local/mysql/bin/" >> /etc/profile
mysql -u root -e "SELECT User, Host, Password FROM mysql.user"
/usr/local/mysql/bin/mysql_secure_installlation
#manage tool
mysql
mysql --user=user_name --password=your_password database_name
mysql db_name <script.sql > out.tab
mysql -u root
mysql -u root mysql
mysql -u root -p 'pass'
mysql -u root -p -h 192.168.0.254
mysqladmin
mysqldump -u root -p --all-databases > all_database_sql
mysqldump -u root -p --database mysql > mysql_database_sql
mysqldump -u root -p mysql user > user_table
mysql -u root -p < all_database_sql
mysql -u root -p mysql < mysql_database_sql
mysql -u root -p mysql < user_table
#sql usage
CREATE DATABASE hr;
SHOW databases;
USE hr;
CREATE TABLE employees(
employee_id INT NOT NULL AUTO_INCREMENT,
fist_name char(20) NOT NULL,
last_name char(20) NOT NULL,
e_mail varchar(50),
telephone INT(15),
department varchar(20),
hire_date date,
PRIMARY KEY(employee_id),
KEY(department))
ENGINE=innodb DEFAULT CHARSET=UTF-8;
CREATE TABLE test (c CHAR(20) CHARACTER SET utf8 COLLATE utf8_bin);
CREATE TABLE new_user SELECT * FROM mysql.user;
show tabes;
DESCRIBE employees;
ALTER DATABASE hr DEFAULT CHARACTER SET=UTF8;
ALTER DATABASE hr DEFAULT COLLATE=utf8_general_ci;
CREATE TABLE test1 (id INT, name CHAR(20));
ALTER TABLE test1 RENAME test2;
ALTER TABLE test2 ADD date TIMESTAMP;
ALTER TABLE test2 ADD note CHAR(50);
ALTER TABLE test2 ADD INDEX (date;
ALTER TABLE test2 MODIFY id TINYINT NOT NULL, CHANGE name first_name CHAR(20);
ALTER TABLE test2 ADD PRIMARY KEY (id);
ALTER TABLE test2 DROP COLUMN note;
DROP table hr;
DROP INDEX 'PRIMARY' ON user;
DROP INDEX 'index' ON tbl_name;
RENAME TABLE test1 TO temp,
test3 TO test1,
temp TO test3;
DROP DATABASE hr;
INSERT INTO employees (employee_id, first_name, last_name,
e_mail, telephone, department, hire_date)
VALUES
(001, "eric","william", "test@gmail.com", 01065103488, "tech", 20110112);
INSERT INTO employees (employee_id, first_name, last_name)
VALUES(001,"eric","william");
INSERT INTO employees (employee_id, first_name, last_name)
VALUES(001, "eric", "william"), (002, "jack", "smith"), (003, "lucy", "black");
INSERT INTO employees ()
VALUES (001,"eric", "william", "test@gmail.com", 01065103488, "tech", 20120112);
SELECT * FROM hr.employees;
UPDATE employees SET hire_date=hire_date+1;
UPDATE hr.employees SET last_name="hope" WHERE employee_id=2;
LOAD DATA INFILE '/tmp/txt' INTO TABLE hr.employees;
LOAD DATA INFILE '/tmp/txt2' INTO TABLE hr.employees
FIELDS TERMINATED BY ',';
USE hr;
DELETE FROM employees WHERE employee_id=5;
DELETE FROM employees WHERE first_name="eric";
DELETE a1,a2 FROM t1 AS a1 INNER JOIN t2 AS a2
WHERE a1.id=a2.id;
SELECT * FROM employees;
SELECT employee_id, first_name, department FROM employees;
SELECT AVG(score) FROM test;
SELECT COUNT(employee_id) FROM employees;
SELECT DISTINCT(e_mail) FROM employees;
SELECT first_name FROM employees WHERE last_name="william";
SELECT * FROM employees ORDER BY hire_date DESE/AES;
SELECT * FROM employees LIMIT 2;
GRANT ALL ON hr.* to 'tomcat'@'localhost' IDENTIFIED BY 'pass';
GRANT SELECT ON hr.* to 'tomcat'@'192.168.0.88' IDENTIFIED BY 'pass';
GRANT RELOAD, PROCESS ON *.* to 'admin'@'localhost';
GRANT ALL ON hr.* to 'jacob'@'%' IDENTIFIED BY 'pass';
SHOW GRANTS FOR jerry@192.16.0.253;
FLUSH PRIVILEGES;
UPDATE mysql.user SET Password = PASSWORD('newpwd') WHERE User ='root';
FLUSH PRIVILEGES;
mysqladmin -u root -p password 'centos'
mysql -u root -p
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpwd');
REVOKE ALL ON hr.* FROM tomcat@'%';
REVOKE SELECT ON *.* from jacob@'%';
DROP USER jerry@'172.16.0.253';
mysqldump --all-databases >bak.sql
mysqldump --databases db1 db2 db3 > bak.sql
mysqldump db4 >bak.sql
mysqldump --databases db4 > bak.sql
mysql < bak.sql
mysql db4 < bak.sql
权限 权限级别 权限说明
CREATE 数据库、表或索引 创建数据库、表或索引权限
DROP 数据库或表 删除数据库或表权限
GRANT OPTION 数据库、表或保存的程序 赋予权限选项
REFERENCES 数据库或表
ALTER 表 更改表,比如添加字段、索引等
DELETE 表 删除数据权限
INDEX 表 索引权限
INSERT 表 插入权限
SELECT 表 查询权限
UPDATE 表 更新权限
CREATE VIEW 视图 创建视图权限
SHOW VIEW 视图 查看视图权限
ALTER ROUTINE 存储过程 更改存储过程权限
CREATE ROUTINE 存储过程 创建存储过程权限
EXECUTE 存储过程 执行存储过程权限
FILE 服务器主机上的文件访问 文件访问权限
CREATE TEMPORARY TABLES 服务器管理 创建临时表权限
LOCK TABLES 服务器管理 锁表权限
CREATE USER 服务器管理 创建用户权限
PROCESS 服务器管理 查看进程权限
RELOAD 服务器管理 执行flush-hosts, flush-logs, flush-privileges, flush-status, flush-tables, flush-threads, refresh, reload等命令的权限
REPLICATION CLIENT 服务器管理 复制权限
REPLICATION SLAVE 服务器管理 复制权限
SHOW DATABASES 服务器管理 查看数据库权限
SHUTDOWN 服务器管理 关闭数据库权限
SUPER 服务器管理 执行kill线程权限
MYSQL的权限如何分布,就是针对表可以设置什么权限,针对列可以设置什么权限等等,这个可以从官方文档中的一个表来说明:
权限分布 可能的设置的权限
表权限 'Select', 'Insert', 'Update', 'Delete', 'Create', 'Drop', 'Grant', 'References', 'Index', 'Alter'
列权限 'Select', 'Insert', 'Update', 'References'
过程权限 'Execute', 'Alter Routine', 'Grant'
## 慕课网达人养成计划1 笔记
xshell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
xshell:new(名称,主机名,用户名), setup, service network restart
### 根目录中常见目录:
根目录中常见目录:
/bin和/sbin(root), /usr/bin和/usr/sbin(root):系统命令;
/boot:用户启动数据;
/dev:硬件文件;
/etc:系统默认配置文件;
/home:普通用户家目录;
/root:root用户家目录;
/lib:函数库文件;
/media(磁带机),/misc(光盘),/mnt(U盘,移动硬盘):挂载目录
/tmp:临时目录
/proc,/sys:内存的挂载点,不能直接操作;
/usr:系统软件资源目录;
/var:系统可变文档;
/home,/root,/tmp可用于日常使用
### [root@localhost ~]#
[root@localhost ~]#
### 命令 [选项] [参数]:ls -alih,-a=--all
命令 [选项] [参数]:ls -alih,-a=--all
pwd
1
pwd(print working directory ), date, ll(ls -l), mv(move), ctrl+l=clear, tab命令补全
ls
1
2
3
4
ls -aldhi: all, long list, dir(查看目录属性), human,inode(文件ID);
文件类型:-,d,l(soft link),块设备文件,字符设备文件,套接字文件,管道文件;
"-rwx------. 1 root root 1207 1月 14 18:18 anaconda-ks.cfg":
read,write,x执行,引用计数(hard link),u所有者,g所属组,o其他人,大小,最后一次修改时间,文件名;
cd
1
cd(change directory)[路径]:cd ~, cd , cd -, cd .., cd ., cd /
mkdir
1
mkdir(make directory)[文件夹名]:mkdir -p [dir name]
rmdir
1
rmdir [空文件夹]
rm
1
rm(remove) -rf [文件]/[文件夹]:dir,force
cp
1
2
3
cp(copy) -ra [源文件] [目标文件]:dir, all(-pdr)
ln
1
2
3
4
ln(link) -s [原文件] [目标文件]:soft
hard link:拥有相同节点和存储block块,可通过i节点识别,不能跨分区,不能针对目录使用
soft link(一定要写绝对路径):类似windows快捷方式,拥有自己的i节点和block块,但是数据块中只保存原文件的文件名和i节点号,并没有实际的文件数据,可通过lrwxrwxrwx识别,修改任意文件,另一个都改变,删除原文件,软连接不能使用
locate
1
2
3
4
locate 文件名(只能搜索文件名):在后台数据库中按文件名搜索,搜索速度更快
/var/lib/mlocate:#locate命令所搜索的后台数据库
updatedb:立即更新(否则一天更新一次)
/etc/updatedb.conf配置文件:prune_bind_mounts="yes"(开启搜索限制),prunefs=(不搜索的文件系统),prunenames=(不搜索的文件类型),prunepaths=(不搜索的路径)
whereis
1
whereis -bm 命令名:binary,manual(注:whatis whoami "who am i")。显示外部命令的位置及帮助文档
which
1
which 命令名:显示外部命令的位置及其别名
echo
1
echo $path(path:系统搜索命令的路径)
find
1
2
3
4
5
6
7
8
9
10
find(文件名) [搜索范围] [搜索条件]:匹配使用通配符*?[](匹配任何一个中括号内的字符),是完全匹配
"find / -name insatll.log"
"find /root -iname install.log"
"find /root -user root", "find /root -nouser(sys proc 外来文件 不可删)"
"find /var/log/ -m(modify内容)time[a(文件访问)time c(chang属性)time] +10(day)"
"find . -size -25k -a size +10k"
"find . -size +2M -a -size -5M"
"find . -size 25"(25扇区(512字节)块)
"find . -inum 262421"
"find /etc -size +20k -a -size -50k -exec ls -lh {} \;"
greb
1
2
greb(内容) -vi 字符串 文件名:取反, ignore-case。在文件当中搜索符合条件的字符串,匹配使用正则表达式匹配,是包含匹配
man
1
2
3
4
5
6
man 命令:/-d, n, shift+n
"man -f(=whatis) ls"
"man 5 passwd"
"man 4 null"
"man 8 ifconfig"
"man -k(=apropos) passwd"
help
1
help命令 --help:获取命令选项的帮助
help
1
help shell内部命令:只能获取shell内部命令的帮助, 如"whereis cd""help cd" "man cd"
info
1
2
3
4
5
6
info(比man更详细的命令帮助文档) 命令:enter(进入子帮助页面)、u(进入上层页面)、n(进入下一节帮助小节)、p(进入上一节帮助小节)、q(退出)
/*
### 常见压缩格式:.zip .gz .bz2 .tar.gz .tar.bz2
常见压缩格式:.zip .gz .bz2 .tar.gz .tar.bz2
zip
1
zip [-r] 压缩文件名 源文件[源目录]:压缩为.zip格式,源文件保留
unzip
1
unzip 压缩文件:解压.zip文件
gzip
1
gzip 源文件:压缩为.gz格式,源文件会消失
gzip
1
gzip -c 源文件 > 压缩文件:压缩为.gz格式,源文件保留“gzip -c cangls > cangls.gz”
gzip
1
gzip -r 目录:压缩目录下的所有子文件,但是不能压缩目录
gunzip
1
gunzip(=gzip -d) 压缩文件:解压缩
gunzip
1
gunzip -r 目录:解压缩目录中的所有文件
bzip
bzip2 [-k] 源文件:压缩为.bz2格式,不保留源文件[保留源文件],不能压缩目录
bunzip
bunzip2(=bzip2 -d) 压缩文件:解压缩,-k保留源文件
tar
1
tar -cvf 打包文件名 源文件:打包,显示过程,指定打包后的文件名。"tar -cvf jp.tar jp"
tar
1
2
3
tar -xvf 打包文件名:解打包,显示过程,指定打包后的文件名。"tar -xvf jp.tar"
*/
zip
1
zip [-r] 压缩文件名 源文件[源目录]:压缩为.zip格式,源文件保留
unzip
1
unzip 压缩文件:解压.zip文件
tar
1
tar -zcvf /temp/压缩包名.tar.gz 源文件1 目录1...:压缩为.tar.gz格式
tar
1
tar -zxvf 压缩包名.tar.gz -C 目录:解压缩.tar.gz格式到目录
tar
1
tar -jcvf /temp/压缩包名.tar.bz2 源文件1 源文件2 目录1...:压缩为.tar.bz2格式
tar
1
tar -jxvf 压缩包名.tar.bz2 -C 目录:解压缩.tar.bz2格式到目录
tar
1
2
tar -zt(test)vf 压缩包名.tar.gz:只是查看压缩内容
shutdown
1
2
3
shutdown(安全的关机重启命令) -chr 时间:cancel, 关机, reboot
"shutdown -r now"
"shutdown -r 05:30 &"
halt
1
halt/poweroff/init 0(不安全的关机命令)
reboot
1
2
3
4
reboot(安全的重启命令)和int 6(不用)
### 系统运行级别(init(调用)):0(关机),1(单用户:修复(如忘了密码)),2(不完全多用户,不含NFS服务(文件共享服务)),3(完全多用户(普通字符界面)),4(未分配),5(图形界面),6(重启)
系统运行级别(init(调用)):0(关机),1(单用户:修复(如忘了密码)),2(不完全多用户,不含NFS服务(文件共享服务)),3(完全多用户(普通字符界面)),4(未分配),5(图形界面),6(重启)
runlevel
1
runlevel:查看系统运行级别
cat
1
cat /etc/inittab修改系统默认运行级别id:3:initdefault:
logout
1
2
3
4
5
logout
### 挂载(分配盘符)命令:
挂载(分配盘符)命令:
mount
1
2
3
4
mount [-t 文件系统(ext3/ext4/iso9660等)] [-o 特殊选项] 设备文件名 挂载点:
"mount", "mount -a"(依据配置文件/etc/fstab的内容)
"mkdir /mnt/cdrom" "mount [-t iso9660] /dev/sr0 /mnt/cdrom"
"fdisk -l" "mkdir -p /mnt/usb" "mount -t vfat /dev/sdb1 /mnt/usb"
linux
1
linux系统默认不支持NTFS文件系统(最多只读)
umount
1
2
3
4
5
6
7
8
9
10
umount 设备文件名或挂载点:"umount /mnt/cdrom"
### 脚本:"vi hello.sh"
脚本:"vi hello.sh"
"#!/bin/bash echo "hello the world!!!""
"chmod 755 hello.sh"
"./hello.sh"
"mount -o remount,noexec /home"
"mount -o remount,exec /home"
w
1
w 用户名:idle 用户闲置时间,jcpu当前正在运行的后台作业所占用的时间,pcpu当前进程所占用的时间,what当前正在运行的命令
who
1
who
last
1
last(所有的用户登陆信息):默认读取/var/log/wtmp文件数据
lastlog
1
lastlog(查询所有用户的最后一次登陆时间):默认读取/var/log/lastlog
other:
uname -a查看linux内核版本 tar -xvf nginx-1.7.7.tar.gz cd nginx-1.7.7 #进入源码包 ./configure –prefix=/usr/local/nginx –conf-path=/etc/nginx/nginx.conf 其中我们通过–prefix制定了安装路径,通过–conf-path制定了配置文件的具体位置。注意:不是所有的程序的configure参数都是一样的 可以使用 ./configure –help查看详细参数说明。如果该程序所依赖的库在当前系统中没有安装,则会导致configure最后报错,遇到这种情况就需要你先安装依赖库。 make make install vi /etc/profile(添加export PATH=$PATH:/path/to/somewhere) source /etc/profile ldconfig ln -s /usr/local/nginx/include? /usr/include/yourname
vnc使用: su user rpm -q vnc vnc-server yum install vnc vnc-server apt-get install vnc vnc-server vncserver vncpasswd vi ~/.vnc/xstartup注释最后两排,添加如下内容: gnome-session & vi /etc/sysconfig/vncservers注释最后两排,添加如下内容: VNCSERVERS=”1:root” VNCSERVERARGS[1]=”-geometry 1024x768” (VNCSERVERS=”1:user1 2:user2 3:user3” VNCSERVERARGS[1]=”-geometry 1024×768” VNCSERVERARGS[2]=”-geometry 1024×768” VNCSERVERARGS[3]=”-geometry 800×600 -depth 24 -nolisten tcp -nohttpd -localhost” ) vncserver:1 vi /etc/sysconfig/iptables /sbin/service iptables restart
centos端口命令: lsof -i tcp:80 netstat -ntlp /sbin/iptables -I INPUT -p tcp –dport 80 -j ACCEPT /etc/init.d/iptables save service iptables restart vi /etc/sysconfig/iptables -A INPUT -p tcp -m state NEW -m tcp –dport 80 -j ACCEPT /sbin/iptables -I INPUT -p tcp –dport 80 -j DROP /etc/init.d/iptables save service iptables restart -A INPUT -p tcp -m state NEW -m tcp –dport 80 -j DROP /etc/init.d/iptables status
uname -a查看linux内核版本
源码包软件安装: tar -xvf nginx-1.7.7.tar.gz cd nginx-1.7.7 #进入源码包 ./configure –prefix=/usr/local/nginx –conf-path=/etc/nginx/nginx.conf make make install
rpm -ivh –force –nodeps *.rpm yum -y name
?: vi /etc/profile(添加export PATH=$PATH:/path/to/somewhere) source /etc/profile ldconfig ln -s /usr/local/nginx/include/usr/include/yourname
chkconfig iptables on service iptables start
centos7安装vnc:
yum -y install tigervnc-server
cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service
vi /etc/systemd/system/vncserver@:1.service
替换
tracepath www.baidu.com curl ifconfig.me curl icanhazip.com jobs fg 1 bg 1 ctrl+z
ubuntu: sudo dpkg -l |grep ssh sudo apt-get install ssh –fix-missing sudo apt auto remove sudo apt-get update ssh root@192.168.36.136 22 cat echo touch /etc/init.d/ssh restart[status|start] 再次建立inittab,写入id:3:initdefault: ,然后进入/etc/rc3.d,将S13kdm移动到其他目录备份起来,重新启动系统,如愿以偿进入字符界面 vi /etc/inittab /etc/init.d/sshd status[start]
只让wheel使用su命令: 1)修改 /etc/pam.d/su 文件,找到“#auth required /lib/security/$ISA/pam_wheel.so use_uid ”这 一行,将行首的“#”去掉。 2)修改 /etc/login.defs 文件,在最后一行增加“SU_WHEEL_ONLY yes”语句。 然后,用“usermod -G wheel 用户名”将一个用户添加到wheel组中。
用wget下载东西,的确很方便,它会自动重连并断点续传。让人很放心。 经常要下载一个网站或网站的某个目录。 下载一个目录,例如下载网站www.example.com/目录mydir下的所有内容 命令如下: wget -r -p -k -np -nc -e robots=off http://www.example.com/mydir/
如果要想下载整个网站,最好去除-np参数。? wget -c -r -p -k -nc -L -np -e robots=off https://mirrors.tuna.tsinghua.edu.cn/cygwin/x86_64/
-r 递归;对于HTTP主机,wget首先下载URL指定的文件,然后(如果该文件是一个HTML文档的话)递归下载该文件所引用(超级连接)的所有文件(递 归深度由参数-l指定)。对FTP主机,该参数意味着要下载URL指定的目录中的所有文件,递归方法与HTTP主机类似。? -c 指定断点续传功能。实际上,wget默认具有断点续传功能,只有当你使用别的ftp工具下载了某一文件的一部分,并希望wget接着完成此工作的时候,才 需要指定此参数。 -nc 不下载已经存在的文件 -np 表示不追溯至父目录,不跟随链接,只下载指定目录及子目录里的东西; -p 下载页面显示所需的所有文件。比如页面中包含了图片,但是图片并不在/yourdir目录中,而在/images目录下,有此参数,图片依然会被正常下 载。 -k 修复下载文件中的绝对连接为相对连接,这样方便本地阅读。 -o down.log 记录日记到down.log -e robots=off 忽略robots.txt -L 递归时不进入其它主机,如wget -c -r www.xxx.org/
vi /etc/inittab
主机与虚拟机交流: 共享文件夹:失败(找不到共享的文件) ftp:失败(不会使用ftp) U盘:失败(ntfs) ssh:
重置centos密码.txt