change zonetime:
1. backup /etc/localtime
2. copy /usr/share/zoneinfo/posix/Asia/Shanghai to /etc/localtime
change language:
export LANG=en_US.UTF-8
cmd:lynx
A text-based web browser
== Fedora20 ==
cmd:systemctl
list-unit-files list available services
enable sshd: enable auto-start
start sshd: start service
status sshd: view service status
disable sshd: disable auto-start
restart sshd: restart service
stop sshd: stop service
cmd:gnome-terminal
Fefora terminal (cmd/command line)
cmd:grub2-set-default
set default bootup entry
sudo cat /boot/grub2/grub.cfg | grep windows
sudo grub2-set-default 'Windows 7 (loader) (on /dev/sda1)'
== Ubuntu ==
cmd:update-rc.d servicename defaults
add service to startup service list
cmd:dict [option] word
server: dictd
client: dict
configure: dictdconfig
etc: /etc/dictd
english-chinese dictionaries: dict-xdict, dict-stardic
english dictionries: dict-gcide
cmd:alsamixer
sound controller
cmd:vmstat delay count
grep pid of with name
cmd:pgrep -f name
grep pid of with name
cmd:pkill -f name
kill pid of with name
cmd:mysql -uroot -p
import data: mysql -uroot -p database_name < file.sql
== Dev ==
/dev/zero
/dev/null
== X window ==
p482 startx
p483 X
== daemon ==
p432 /etc/services (port)
p434 /etc/xinetd.conf
/etc/xinetd.d/*
p434 service service_name start,restart,stop
p440 tcp_wrappers
/usr/sbin/tcpd
/usr/sbin/safe_finger
/etc/hosts.allow
/etc/hosts.deny
cmd:gcc -I. -L. -shared -fPIC -lxxx -o target -c file.c
cmd:chkconfig (p443)
–list: list all the startup services
–add servicename: add a service to the startup service list
–del servicename: delete a service from the startup service list
–level 0123456 servicename on/off: turn on/off service at specified run level
p444 ntsysv –level 0123456
p500 setup
== rpm/yum/dpkg/apt ==
cmd:rpm (p414)
-i(vh) *.rpm: install
-U(vh) *.rpm: update, update or install
-F(vh) *.rpm: freshen, just update but no installation
-v: verbose
-h: show progress
–test: just test it, but don’t install it actually
-qa: list all packages
-q(licdR) pkgname: query installed package
-qp(licdR) *.rpm: query package file
-qf file: query which package contains the file
-l: list all contents
-i: information
-c: configure file
-ccd: document filecccc
-R: required packages
-Va: verify all installed packages
-V pkgname: verify installed package
-Vp *.rpm: verify package file
-Vf filename: verify file
-e pkgname: uninstall package
–rebuilddb
cmd:rpmbuild (p421)
source rpm (SRPM)
–rebuild *.src.rmp
–recompile *.src.rmp
-bb *.spec
-ba *.spec
cmd:yum command
search pkgname: search package in the repository
info pkgname: show package info
provides|whatprovides *filename*: show packages that contain the specified file (alternative to search on https://rpmfind.net)
install pkgname: install package
erase pkgname: unstall package
cmd:add-apt-repository ‘source line’ or PPA Shortcut
‘source line’: e.g., ‘deb http://…’
PPA Shortcut: e.g., ppa:user/repostory
Repository files will be save to /etc/apt/sources.list.d
–remove: remove it from the list
cmd:apt-get
update: retrive new lists of packages
install pkgname: install package
remove pkgname: uninstall package
purge pkgname: uninstall package and remove config files
cmd:apt-cache
search pkgname: search package in the repository
cmd:dpkg
-i *.deb: –install
–contents *.deb: list contents of the package
–info *.deb: show info of the package
–remove pkgname: remove(uninstall) package
–purge pkgname: purge(uninstall) package and config files
–listfiles pkgname: list contents of the package
–status pkgname: show status of the package
–list: list all installed package
–search file: query which package contains the file
== Tarball ==
p396 gcc -coO -lm -LI -Wall (cc)
gcc-c++
glibc
/lib/*.so
/usr/lib/*so
glibc-headers
/usr/include/*.h
p397 make
p401 ./configure –help –prefix
make clean
make
make install
cmd:ldconfig (p407)
mean: load dll(.so) into cache (/etc/ld.so.cache)
config: /etc/ld.so.conf < /etc/ld.so.conf.d/* (reference directories not .so files)
-p: print current loaded dlls in /etc/ld.so.cache
(add to env LD_LIBRARY_PATH can make it loadable)
(libxxx.a: static lib
libxxx.so: shared lib
libxxx.ko: kernel lib)
cmd:ldd (p407) -v filename
p408 md5sum filename > filename.md5
md5sum -c filename.md5
(sha1sum, sha224sum, sha256sum, sha512sum)
== boot ==
BIOS -> Boot Loader -> Kernel -> /sbin/init -> /etc/inittab -> /etc/rc[runlevel].d/S##.ln -> /etc/rc.d/init.d/*
BIOS -> Boot Loader -> Kernel -> /bin/systemd ->
p364 /etc/inittab
p370 init (0-6)
p371 runlevel
p371 depmod
/lib/modules/`uname -r`/modules.dep
p372 lsmod
p372 modinfo (module_name, filename)
p373 insmod
p373 rmmod
p373 modprobe
p374 GRUB
/etc/grub.conf ->
/boot/grub/menu.lst ->
/boot/grub/grub.conf
p382 LILO
p386 kernel ro root=/dev/sda1 init=/bin/bash (runlevel)
p387 chroot (dir)
== job ==
cmd:& (p341)
usage: place it to the end of a command
mean: run command and put it to background running
cmd:Ctrl-z (p342)
mean: pause the current job and put it to background
cmd:jobs (p342)
mean: list background jobs of current bash session
-l: list PID as well
cmd:fg %jobId (p342)
mean: fetch job from background to foreground and run it
cmd:bg %jobId (p343)
mean: let a background job run in background
cmd:kill -9 %jobId / PID (p343)
mean: kill a job by jobId(with %) or by PID
cmd:killall -9 -e [commandName] (p350)
mean: kill jobs by command name
-e: exactly command name match
-i: interactive confirm before kill
cmd:pkill [commandName]
mean: kill jobs by command name
cmd:top (p346)
mean: show running jobs dashboard
-p [PID]: only show the PID in dashboard
after in the dashboard:
h: show helps
k: kill job (with signal 9)
cmd:ps aux (p344)
mean: show all running jobs
p348 pstree -pu
P351 free
p351 uname -r
p351 uptime
cmd:ssh
.ssh/config:
Host myhost IdentityFile /root/.ssh/id_rsa Port 2222 HostName 203.195.157.188(Host) User root
ssh-agent bash -c 'ssh-add /home/user/.ssh/myproj/id_rsa; git clone git@github.com:TheUser/TheProject.git'
cmd:netstat (p352)
mean: show all active service ports
-tupln: show listening tcp/udp ports
-tpln: show connecting tcp sockets
print conn statistic: netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
p353 dmesg
/var/log/dmesg
p353 sar -ur
p354 nice -n 10 (cmd)
p355 renice 10 (pid)
p357 fuser -k file/dir
p358 lsof
p359 pidof (cmd)
== at/cron ==
p330 /etc/init.d/atd
/etc/at.allow
/etc/at.deny
/var/spool/at
p330 at
p331 atq
p331 atrm
cmd:crontab [option] (p332)
-u username: operate user’s cron tasks
-l: list cron tasks
-e: edit cron tasks
-r: remove all cron tasks
/etc/init.d/crond: system service
/etc/crontab: saved system’s cron tasks
/var/spool/cron/”username”: saved user’s current cron tasks
/etc/cron.allow: list the permitted user to use crond
/etc/cron.denny: list the unpermitted users to use crond
/var/log/cron: log file
format: minute(0-59) hour(0-23) day(1-31) month(1-12) week(0-7) command
*: any
,: and, 2,3
-: range, 2-5
/n: period, */5
example(user): */5 2-5 12,13 * * cmd
example(system): */5 2-5 12,13 * * root run-parts /etc/cron.daily
== Script ==
p267 test
p270 [ condition ]
p277 function
p272 if elif else fi
p275 case esac
p279 while do done
p279 until do done
p280 for(()) do done
p281 for var in do done
p282 bash -nx
== Regexp ==
p250 Regexp TABLE (p252)
p252 printf
p254 sed
p257 awk
cmd:diff [option] oldfile newfile [> patchfile] (p258)
-Naur: make patchfile
p259 cmp
p260 patch -p(n), file < patchFile (p404)
p260 pr
== Shell ==
p221 /etc/issue
/etc/issue.net
/etc/motd
p222 /etc/sysconfig/i18n
/etc/profile
/etc/profile.d/*
/etc/bashrc
/etc/inputrc
/etc/man.config
p223 ~/.bash_profile (recommended)
~/.bash_login
~/.profile
~/.bashrc
~/.bash_logout
~/.bash_history
p079 date
p079 cal m y
p080 bc scale=2
p205 echo -e(p264)
p208 env export
p209 set typeset declare
p212 locale LANG=en_US.utf8 zh_CN.utf8
p213 read -pt
p214 declare -iaxr typeset unset
cmd:ulimit (p215)
-a: print all limit info (then can set any limit according to the tip)
-n 1000000: set max number of open files to 1000000
-n: get max number of open files
/etc/security/limits.conf:
* soft nofile 1000000
* hard nofile 1000000
p217 alias unalias
p218 history -c !number !partname !!
p224 source (.)
p225 stty -a
p225 set -+
p228 < << > >> 2> 2>>
p231 ; && ||
== pipe cmd ==
p232 cut -d -f -c
cmd:grep/egrep [option] key/’key’/”key” [file] (p233, p251)
“egrep”=”grep -E”, supports advance regular expressions, that is +, ?, |, ()
-i: –ignore-case
-v: –invert-match, return lines that doesn’t contain the key
base:
^: head
$: tail
.: any single character
\: escape special character
[ab], [a-c], [^a-c]: one of the character within or out of(^) the range
\{n,m\}, \{n,\}: repeat fore-character n to m times
*: repeat fore-character zero or multiple times
advance:
+: repeat fore-character one or multiple times
?: repeat fore-character zero or one times
|: or
():
p234 sort -tkrn
p235 uniq -ic
p235 wc -l
p236 tee -a
p236 tr -d
p337 join
p238 paste
p237 col -x
p239 expand
p239 split -bl
p240 xargs
p241 -
== vi ==
cmd:vi file (p184)
vim, its temp file is “.(filename).swp”
0: navigate cursor to the starting of the line
$: navigate cursor to the end of the line
gg: navigate cursor to the first line of the file
G: navigate cursor to the last line of the fle
/key: search forward
?key: search backward
n: next search result
N: previous search result
x: delete character forward
X: delete character backward
(n)dd: cut 1 line or n lines forward
(n)yy: copy 1 line or n lines forward
p: paste clipboard after the current line
P: paste clipboard before the current line
u: undo
ctrol+r: redo
i: start inserting at the current cursor position
o: new a line under the current sursor position and start inserting
O: new a line above the current sursor position and start inserting
:n1,n2s/replaced/replacing/g: substitute “replaced” with “replacing” within lines from line n1 to line n2
:n1,$s/treplaced/replacing/gc: substitute “replaced” with “replacing” within lines from line n1 to the end of file, with confirmation
:w(!) [file]: write (force) [save as another file]
:q(!): quit (force)
:e!: erase(abandon) changes and restore the file to original status
:set nu/nonu: show or hide line number
:set fileformat=unix: set file format to unix [line feed ("\n")]
:set fileformat=dos: set file format to dos [carriage return and line feed ("\r\n")]
go to a specified(e.g. 123) line:
:123
123G
123gg
cmd:dos2unix [option] file [newfile] (p196)
transform CRLF(^M$) to LF($)
-n: save the result to a new file
cmd:unix2dos [option] file [newfile] (p196)
transform LF($) to CRLF(^M$)
-n: save the result to a new file
== User and Group ==
p287 /etc/passwd
p288 /etc/shadow
p289 /etc/group
p291 /etc/gshadow
p293 /etc/login.defs
p293 /etc/skel/*
p292 /etc/default/useradd
p291 useradd -ugGcdsMmr
p295 usermod -lugGcdsmLUe
p295 userdel -r
p294 passwd -ludS (p300)
p296 chsh -ls
/etc/shells
p296 chfn
p297 finger -s
p298 id
p298 groupadd -gr
p298 groupmod -gn
p299 groupdel
p299 gpasswd -adAMRr
p290 groups
p290 newgrp
cmd:su [-] [USER] (p302)
mean: Change the effective user id and group id to that of USER
-c COMMAND: execute COMMAND and exit user’s context
-, -l, –login: make the shell a login shell (load USER’s .bash_profile)
If USER not given, assume root.
cmd:sudo (p303)
mean: in behavior of root doing sth
-u USER: in behavior of USER doing sth
sudo su -: going into root’s shell
cmd:visudo (p304)
mean: edit /etc/sudoers
p306 shell = /sbin/nologin
/etc/nologin.txt
p307 /etc/pam.d/(cmd)
/lib/security/pam_*.so
p308 /lib/security/pam_securetty (only affect root)
/etc/securetty
p309 /lib/security/pam_nologin.so (only affect non-root user)
/etc/nologin
p309 w
p309 who
p309 finger
p309 users
p309 last
p309 lastlog
p309 talk
p310 ntalk
p310 write
p310 wall
p310 mesg yn
p311 mail
/var/spool/mail/(user)
cmd:sendmail email < file
or:
sendmail email
From: fromEmail
Subject: subject
email body
ctrl+d
p312 pwck grpck
p312 pwconv pwunconv
p312 grpconv grpunconv
p313 chpasswd
== Shutdown ==
p090 shutdown -h now
p090 powseroff
p090 halt
p090 reboot
== Swap ==
p179 dd
p171 mkswap
p171 free
p171 swapon
p171 swapoff
== ZIP ==
p175 compress -dcr uncompress
p176 gzip -dc# v gunzip gcat
p177 bzip2 -dc# v bunzip2 bzcat
cmd:tar -cjf file.bz2 folder(p177)
tar -xjf file.bz2
-c: create
-x: extract
-t: test
-z: gz
-j: bz2
-v: verbose
-p: –preserve-permissions, –same-permissions
-P: –absolute-names, don’t strip leading ‘/’s from file names
-f file: –file=file
== File permission ==
cmd:chown [option] owner[:group] files (p101)
-R: –recursive
cmd:chgrp [option] group files (p100)
-R: –recursive
cmd:chmod [option] mod[,mod] files (p102, p134)
-R: –recursive
r(4) w(2) x(1)
ugoa +-= rwx
Set UID (4): only effect on executable file(wont’ propagate), run with the file owner’s permission(the owner and executor must have the x permission)
Set GID (2):
a) to file – run with the file own group’s permission(the file own group must has the x permission)
b) to directory – the default group of new files/directories will the parent’s folder group
Sticky Bit (1): only effect on directory, under this directory, only the the file owner/parent directory owner/root can delete the file, even if group/other has w permission
the mean of i-node:
file: the count of hard link
directory: the count of sub-directories which is under it directly
cmd:chattr +-= attr file/directory (132)
a: lock the file and can only append content to it (need root to set it)
i: lock the file and can’t change/delete the file (need root to set it)
cmd:lsattr (p133)
cmd:getfattr
get extended attributes (available in “attr” package)
cmd:umask [subtractingMode] (p131)
file default permission: -rw-r–r–
directory default permission: drwxr-xr-x
== File and Directory ==
p115 cd
p116 pwd -P
p117 mkdir -mp
p117 rmdir -p
cmd:ls [option] [dir] (p119)
-a: –all, do not ignore entries starting with .
-l: list view
-h: –human-readable, print size in human readable format (e.g., 1K 232M 2G)
-d: –directory, list directory entries or symbolic links itself, instead of listing contents
-i: –inode, including inode at the result
-n: –numeric-uid-gid, showing uid/gid instead of username/groupname
-F: format, * executable, / directory, @ symbolic link, = socket, | FIFO
p121 cp -dpr a ls if u
p122 rm -r if
p123 mv -v if u
cmd:ln [option] sourcefile newfile (p153)
make hard links by default
-s: –symbolic, make symbolic links instead of hard links
-f: –force, remove existing destination files
p128 touch
cmd:file file (p135)
p123 basename
p124 dirname
== show file content==
cmd:cat [option] file (P124)
-n: show line number
-A: show all invisible characters e.g., ^M(CR) $(LF) ^I(TAB)
cmd:tac file (p125)
show file content inverted, that is last line shows first
cmd:nl file (p125)
show file content, with line number
cmd:more file (p126)
space: next page
enter: next line
q: quit
cmd:less file (p127)
space: next page
enter: next line
/key: search forward
?key: search backward
n: next search result
N: previous search result
q: quit
cmd:head [option] file (p127)
-n: show first n lines
cmd:tail [option] file (p127)
-n: show last n lines
-f/–follow file: follow file and output appended data as the file grows to console
cmd:od [option] file (p128)
-t: specify showing type
c: set type to ASCII
d: set type to decimal
o: set type to octal
x: set type to hexadecimal
== search ==
cmd:type cmd (p202)
check if a command is a builtin command or not
cmd:which [option] cmd (p135)
search executable files in $PATH
-a: list all qualified files
cmd:whereis fullname (p136)
search exactly, base on database, which is updated by command “updatedb”
cmd:locate partname(p136)
fuzzy search, base on database, which is updated by command “updatedb”
cmd:find [path] [option] (p137)
-mtime #: modified time is between # and #+1 days ago
-newer file: newer than the file
-uid n: search by uid
-gid n: search by gid
-user name: search by user name
-group name: search by group name
-nouser: search files with file’s owner not in /etc/passwd
-nogroup: search files with file’s group not in /etc/group
-name filename: the name can include wildcard (?*), but must place them in quote (“?*” or ‘?*’)
-size [+-]size: larger(+) or smaller(-) than the size, c-byte, k-1024bytes
-type type: f-file, d-directory, b-block, c-character, l-symbolic link, s-socket, p-FIFO
-perm mode: the exact mode of files
-perm -mode: shoud(at least) include this mode
-perm +mode: include one of this mode
== file system ==
p149 df -hT .
p151 du -hs
cmd:dd [options] (p179)
if=input file (/dev/zero)
of=output file
bs=block size (in byte)
count=block count
skip=skip block count
p155 fdisk -l
p159 mke2fs -ibLj
p146 dumpe2fs -h
p161 fsck -y
p162 sync
cmd:mount [option] device mountpoint (p162)
/etc/fstab: system mount table
/etc/mtab: current mounted table
/proc/mounts: current mounted table
-a: mount all in /etc/fstab
-n: don’t update /etc/mtab
-t: type, ext2, ext3, vfat, iso9660
-o: option, ro, rw, loop(to iso/CD), remount
cmd:umount [option] device/mountpoint (p164)
-f: force
p164 mknod bcp
p165 mke2label
p165 tune2fs -jlL
p165 hdparm
p180 cpio
== RAID ==
p527 Linear mode
Stripe mode (RAID-0)
Mirror mode (RAID-1)
RAID-0+1 (4 disks)
RAID-5 (n-1)*s (3 or more disks)
p528 NAS (Network Attached Storage)
p529 SAN (Storage Area Network)
p529 iSCSI
== Network debug ==
cmd:nc
netcat. Reads and writes data across network connections using TCP or UDP.
-k, Keep inbound sockets open for multiple connects
-l port, Listen mode, for inbound connects
-u, UDP mode (default TCP mode)
cmd:curl url
-T file, upload(PUT) file to targer url
-X method, use method(GET, POST, DELETE, PUT etc.) to call target url, default value is GET
cmd:telnet host port
cmd:sysctl -w variable=value
/etc/sysctl.conf
sysctl {variable}: print varivable value
sysctl -a: print all current values
sysctl -p: reload config from /etc/sysctl.conf
sysctl -w net.ipv4.ip_local_port_range="1024 65000"
调整/etc/sysctl.conf:
net.ipv4.tcp_syncookies = 1net.ipv4.tcp_syncookies = 1
表示开启SYN Cookies。当出现SYN等待队列溢出时,启用cookies来处理,可防范少量SYN攻击,默认为0,表示关闭;
net.ipv4.tcp_tw_reuse = 1
表示开启重用。允许将TIME-WAIT sockets重新用于新的TCP连接,默认为0,表示关闭;
net.ipv4.tcp_tw_recycle = 1
表示开启TCP连接中TIME-WAIT sockets的快速回收,默认为0,表示关闭。
net.ipv4.tcp_fin_timeout = 30
表示如果套接字由本端要求关闭,这个参数决定了它保持在FIN-WAIT-2状态的时间。
net.ipv4.tcp_keepalive_time = 1200
表示当keepalive起用的时候,TCP发送keepalive消息的频度。缺省是2小时,改为20分钟。
net.ipv4.ip_local_port_range = 1024 65000
表示用于向外连接的端口范围。缺省情况下很小:32768到61000,改为1024到65000。
net.ipv4.tcp_max_syn_backlog = 8192
表示SYN队列的长度,默认为1024,加大队列长度为8192,可以容纳更多等待连接的网络连接数。
net.ipv4.tcp_max_tw_buckets = 5000
表示系统同时保持TIME_WAIT套接字的最大数量,如果超过这个数字,TIME_WAIT套接字将立刻被清除并打印警告信息。默认为180000,改为5000。
如果高负载系统使用了netfilter/iptables,调整以下参数
net.ipv4.ip_conntrack_max = 655360
在内核内存中netfilter可以同时处理的“任务”(连接跟踪条目)
net.ipv4.netfilter.ip_conntrack_tcp_timeout_established = 180
跟踪的连接超时结束时间
fs.file-max= 65000
ulimit -n 设置的是单个进程的最大打开文件数限制。fs.file-max设置的是全局的(kernel-leverl)限制。可以通过cat /proc/sys/fs/file-nr开查看当前值。具体请看文档man proc。一般需要同时设置fs.inode-max值(3-4 times of fs.file-max)
然后执行/sbin/sysctl -p让参数生效