Skip to content

Instantly share code, notes, and snippets.

@hochun836
Last active July 23, 2022 01:49
Show Gist options
  • Save hochun836/426377f4a4d4990c985aa808c2b0961f to your computer and use it in GitHub Desktop.
Save hochun836/426377f4a4d4990c985aa808c2b0961f to your computer and use it in GitHub Desktop.
# base
fileName is case-sensitive
command is also case-sensitive
program is a file
process is running in memory by executing the program
absolute path starts with / (this / means the root directory)
# hotkey
ctrl + a // move cursor to begin
ctrl + e // move cursor to end
ctrl + u // from current cursor position, delete to begin
ctrl + k // from current cursor position, delete to end
ctrl + w // just delete one word
ctrl + l // move the screen one page down giving the illusion of a clean screen
ctrl + r // shell propmt will be (reverse-i-search) to search history command
ctrl + c // cancel the current job
ctrl + z // stop the current job and move it to background
<command> & // execute command in background
esc + . // get the last option or argument of the last command
# package
yum --version // show yum version
yum repolist [-v] // v: verbose, ll /etc/yum.repos.d/
yum repolist all
yum install epel-release // epel: Extra Packages for Enterprise Linux
yum install net-tools // ex. ifconfig, netstat (PS: ifup, ifdown are built-in)
yum install bind-utils // ex. host, dig, nslookup
yum install rpm wget tree zip unzip traceroute mtr tcpdump telnet conntrack bridge-utils man-pages gcc libcgroup-tools psmisc git rsync nfs-utils
yum search <keyword>
yum remove <package> // <=> yum erase <package>
yum update <package>
yum grouplist // list environment groups & groups
yum groupinstall "GNOME Desktop" "Graphical Administration Tools" // for gui
yum groupinfo "GNOME Desktop"
yum info [package-name]
yum list [package-name]
yum list <all | installed | recent | updates>
yum list installed <package-name>
yum list dev\*gcc
yum list --enablerepo=epel | less
yum provides <file-path> // list which rpm packages provide this file
yum-config-manager // depend on => yum install yum-utils
yumdb // depend on => yum install yum-utils
rpm --help
rpm -q epel-release // q: query
rpm -qa // a: all packages
rpm -qa | grep gitlab
rpm -qc quagga // c: list all configuration files
rpm -qd quagga // d: list all documentation files
rpm -ql quagga // l: list files in package
rpm -qf $(which ifconfig) // query package(s) owning file
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
rpm -i mysql-community-release-el7-5.noarch.rpm // i: install package(s)
rpm -ivh mysql-community-release-el7-5.noarch.rpm // v: provide more detailed output, h: print hash marks as package installs (good with -v)
rpm -q mysql-community-release-el7-5.noarch // not include the file extension (.rpm)
rpm -e mysql-community-release-el7-5.noarch // e: erase (uninstall) package
cat $(which yum) | head -1 // python script
cat $(which yum-config-manager) | head -1 // python script
cat /etc/yum.conf
cat /etc/yum/pluginconf.d/fastestmirror.conf
=> ref: https://blog.gtwang.org/linux/yum-linux-command-tutorial-and-examples/
=> ref: https://centos.pkgs.org/
# common
clear // clear screen
cd // change directory to home
cd ~ // <=> cd
cd - // go to back
cat --help
cat -n <file-path> // n: number all output lines
cat -E <file-path> // E: display $ at end of each line
cat -T <file-path> // T: display TAB characters as ^I
cat -A <file-path> // A: equivalent to -vET
tar -zxvf <local-file-path.tar.gz> -C <change-to-some-dir> // x: extract, v: verbose, f: file, -C: change to directory (must exist)
tar -zcvf <local-file-path.tar.gz> <file-path1> [file-path2 ...] // c: create a new archive
unzip <local-file-path.zip> [-d exdir] // d: extract files into exdir
zip <local-file-path.zip> <file-path1> [file-path2 ...]
file <file-path> // show file information
find <dir-path> -user <user> -group <group> -name <file-name> // find filePath
seq [FIRST] [INCREMENT] LAST // print numbers from FIRST to LAST, in steps of INCREMENT.
pwd // print name of current/working directory
mkdir [-p] [-v] <directory-path> // p: parent (no error if existing, make parent directories as needed), v: verbose
cp [-i] <src-path> [<src-path> ...] <dest-path> // i: prompt before overwrite (overrides a previous -n option)
touch <file-path> ... // update the access and modification times of each file to the current time. if file not exist, then it wil be created, unless -c or -h
alias // list all alias
alias <name> // list this alias
alias <name>=<command> // set alias (PS. no any space around =)
unalias <name> // cancel this alias
type <command> // show command is shell builtin or not
type -t <command> // t: output => file, alias, builtin
type -p <command> // p: if file, show path
type -a <command> // a: include found in $PATH
sleep <number>[suffix] // suffix => s: second (default), m: minute, h: hour, d: day
history // list history
history -c // clear history
date // show local date and time
timedatectl // show detail information
locale --help // get locale-specific information
locale
locale -a // -a <=> --all-locales, write names of available locales
stat <path>
stat -c%a <path>
time echo 100
# man
man [section-number] <command>
man man
man open
man 2 open
# man section number
1 Executable programs or shell commands
2 System calls (functions provided by the kernel)
3 Library calls (functions within program libraries)
4 Special files (usually found in /dev)
5 File formats and conventions eg /etc/passwd
6 Games
7 Miscellaneous (including macro packages and conventions), e.g. man(7), groff(7)
8 System administration commands (usually only for root)
9 Kernel routines [Non standard]
# compile
--------------- source code ---------------
gcc // gnu compiler collection
make // resolve dependencies of gcc
----------------- package -----------------
rpm
yum // resolve dependencies of rpm
-------------------------------------------
yum search gcc
gcc.x86_64 : Various compilers (C, C++, Objective-C, Java, ...)
gcc-gfortran.x86_64 : Fortran support
gcc-go.x86_64 : Go support
gcc-c++.x86_64 : C++ support for GCC
gcc-gnat.x86_64 : Ada 95 support for GCC
gcc-objc.x86_64 : Objective-C support for GCC
gcc-objc++.x86_64 : Objective-C++ support for GCC
gcc-plugin-devel.x86_64 : Support for compiling GCC plugins
// depend on => yum install gcc
gcc --help
gcc --version // display compiler version information
gcc -v // display the programs invoked by the compiler
gcc <source-file-path> // output a.out (a.out is executable)
gcc -o <output-file-path>
// depend on => yum install make
make --help
make --version
make clean
make
make install
=> ref: https://www.bilibili.com/video/BV1hE411N7BK
// depend on => yum install autoconf
autoscan --help
autoscan --version
autoheader --help // generate a template file of C `#define' statements for `configure' to use. to this end, scan TEMPLATE-FILE, or `configure.ac' if present, or else `configure.in'
autoheader --version
autoconf --help // generate a configuration script from a TEMPLATE-FILE if given, or `configure.ac' if present, or else `configure.in'
autoconf --version
// depend on => yum install automake
aclocal --help // generate 'aclocal.m4' by scanning 'configure.ac' or 'configure.in'
aclocal --version
automake --help // generate 'Makefile.in' for configure from 'Makefile.am'
automake --version
=> ref: https://www.cnblogs.com/lsgxeva/p/7592485.html
=> ref: https://stackoverflow.com/questions/2531827/what-are-makefile-am-and-makefile-in/2531841#2531841
=> ref: http://blog.itist.tw/2016/09/compile-and-install-openssh-from-source-code-on-centos-7.html
./configure --help // `configure' configures this package to adapt to many kinds of systems
./configure --prefix=/usr/local/mysql --localstatedir=/db // --prefix: install architecture-independent files in prefix [/usr/local], --localstatedir: modifiable single-machine data [prefix/var]
=> ref: https://www.itread01.com/content/1546286048.html
# namespace
ls -al /proc/1/ns
ls -al /proc/$$/ns
ipc
mnt
net
pid
user
uts
# resource
rpm -qf $(which cgcreate)
cgcreate -h // -h <=> --help
cgcreate -g <controllers>:<path> // create control group(s)
cgclassify -h // -h <=> --help
cgclassify [-g <controllers>:<path>] <pid> [<pid> ...] // move running task(s) to given cgroups
ls -al /sys/fs/cgroup/cpu/
cat /sys/fs/cgroup/cpu.cfs_period_us
cat /sys/fs/cgroup/cpu.cfs_quota_us
cat /sys/fs/cgroup/cpu.rt_period_us
cat /sys/fs/cgroup/cpu.rt_runtime_us
cat /sys/fs/cgroup/tasks
ipcs // provide information on ipc facilities
ipcmk -Q // create message queue (-Q <=> --queue)
mount -h // mount a filesystem (-h <=> --help)
mount --make-private -t
# hardware (cpu)
lscpu -h
lscpu
cat /proc/cpuinfo
nproc --help // print the number of processing units available to the current process
nproc --all
=> ref: https://www.cyberciti.biz/faq/linux-xen-vmware-kvm-intel-vt-amd-v-support/
# hardware (disk)
fdisk -h
fdisk -l // list all partition tables in all disks
fdisk -l <disk> // list all partition tables in the specify disk
df --help // df: disk free
df -h // h: human readable format
df -aTh // a: all, T: print file system type
du --help // du: disk usage
du -h [path]
# hardware (device)
ls /dev // mount source
ls /mnt /media // mount destination
cat /proc/mounts
mount -h
mount -l // lists all mounts with labels
mount -t <type> <mount_source> <mount_destination>
mount -t <type> -o <option> <mount_source> <mount_destination>
umount <mount_destination>
findmnt -h
findmnt
cat /etc/fstab // auto mount
Q: how to mount vmware shared folders to centos ?
- step1. set shared folders (ex. shared_folder)
- step2. install vm tools to centos
yum install open-vm-tools // for centos (no gui)
yum install open-vm-tools-desktop // for centos desktop
- step3. mount shared folders to centos
mkdir ~/mnt_folder
mount -t fuse.vmhgfs-fuse .host:/shared_folder ~/mnt_folder
ls -al ~/mnt_folder
=> ref: https://linuxhint.com/mount_vmware_shares_command_line_linux_vm/
# ssh
ssh [user@]<host> // login shell (user default: the current user)
ssh [user@]<host> <command> // nologin shell (user default: the current user)
ssh -i <private-key-path> <user>@<host>
sudo <host> // user is root
sudo ssh <host> <command> // user is root
ssh-keygen // generate public key & private key
ssh-keygen -f <output_keyfile> -C <comment>
ssh-keygen -f ./my_rsa // create my_rsa & my_rsa.pub
ssh-copy-id <host> // copy public key to host
scp [-r] <from-path> <target-path> // r: recursive, remote path format: <user@host:remote-file-path>
# gpg
gpg --list-keys
gpg --list-secret-keys
# power
shutdown // broadcast message about when the computer shutdown
shutdown -c // c: cancel
shutdown -h now // shutdown now
reboot
reboot -f // f: force
# info.
cat /sys/class/dmi/id/product_uuid
cat /etc/redhat-release
cat /etc/centos-release
cat /etc/os-release
cat /etc/passwd // list all users
cat /etc/group // list all groups
id [user] // print user and group information for the specified user (user default: the current user)
groups [user] // show user's groups (user default: the current user)
passwd [user] // change the password (user default: the current user)
echo -e "$PATH\n$PWD" // e: enable interpretation of backslash escapes
echo -n $MAIL // n: do not output the trailing newline
w // show who is logged on and what they are doing
whoami // print effective userid ($USER)
# job
jobs // list all background jobs
bg <job-id> // change status of the background job from stopped to running
fg <job-id> // move the background job to foreground
kill %<job-id> // kill the job
# crontab
cat /etc/crontab
crontab -l [-u <user>] // l: list, u: user (user default: the current user)
crontab -e // e: edit
crontab -r // r: remove
# redirect
stdin: 0, default: keyboard
stdout: 1, default: terminal
stderr: 2, default: terminal
echo 100 > aa.txt // > <=> 1>
echo 200 > aa.txt
echo 300 >> aa.txt // >> <=> 1>>
xxxxx 2> aa.txt
yyyyy 2> aa.txt
zzzzz 2>> aa.txt
ls aa.txt bb.txt 1>result.out 2>result.err // stdout: result.out, stderr: result.err
ls aa.txt bb.txt 1>result.out 2>/dev/null // stdout: result.out, stderr: /dev/null (abandon any error)
ls aa.txt bb.txt 1>result.out 2>&1 // stdout: result.out, stderr: result.out
ls aa.txt bb.txt 2>&1 1>result.out // stdout: result.out, stderr: terminal
ls aa.txt bb.txt &>result.out // &>result.out <=> 1>result.out 2>&1
ls aa.txt bb.txt >&result.out // >&result.out <=> 1>result.out 2>&1
ls aa.txt bb.txt &>>result.out // ok
ls aa.txt bb.txt >>&result.out // error
cat < /etc/passwd // <=> cat /etc/passwd
=> ref: https://blog.csdn.net/u011630575/article/details/52151995
=> ref: https://blog.csdn.net/zhaominpro/article/details/82630528
# true & false
echo 100 > aa.txt
true > aa.txt // clear the content of aa.txt
echo $? // 0
echo 100 > aa.txt
false > aa.txt // clear the content of aa.txt
echo $? // 1
# pipe
cat /etc/passwd | grep root
ls -al | wc -l
# regexp (regular expression)
basic regular expression (BRE)
^ $ . * \ [] [^]
extended regular expression (ERE)
+ ? | () {}
regexp is different from glob (aka. pathname pattern expansion)
regexp
grep, sed, awk, find
glob
ls, cat, ... (most of command in linux)
=> ref: https://www.bilibili.com/video/BV1Kg411g7bC?p=3
=> ref: https://transbiz.com.tw/regex-regular-expression-ga-%E6%AD%A3%E8%A6%8F%E8%A1%A8%E7%A4%BA%E5%BC%8F/
# text (grep: based on lines)
alias grep // alias grep='grep --color=auto'
alias egrep // alias egrep='egrep --color=auto' ('egrep' means 'grep -E')
grep --help
grep <pattern> <file-path1> [file-path2 ...] // by default, pattern is a basic regular expression (BRE)
grep -n '100' a1.txt // n: print line number with output lines
grep -n '^100' a1.txt // lines which start with 100
grep -n '100$' a1.txt // lines which end with 100
grep -n '^$' a1.txt // lines which are empty
grep -nv '^$' a1.txt // lines which are not empty (v: invert match)
grep -n ' ' a1.txt // lines which contain one space
grep -n '.' a1.txt // lines which contain one arbitrary char (except empty lines)
grep -n '\.' a1.txt // lines which contain one dot
grep -n '0*' a1.txt // lines which contain zero or more 0 continuously
grep -n '00*' a1.txt // lines which contain one or more 0 continuously
grep -n '^.*0' a1.txt // .* is greedy
grep -n '0' a1.txt // lines which contain one char which is 0
grep -n '[0]' a1.txt // lines which contain one char which is 0
grep -n '[^0]' a1.txt // lines which contain one char which is not 0
grep -n '[012]' a1.txt // lines which contain one char which is 0, 1 or 2
grep -no '[^0]' a1.txt // o: show only the part of a line matching PATTERN
grep -nE '0+' a1.txt // lines which contain at least one char which is 0 (E: pattern is an extended regular expression)
grep -nE '0?' a1.txt // lines which contain at most one char which is 0
grep -nE '100|200' a1.txt // lines which contain 100 or 200
grep -nE '(1|2)00' a1.txt // lines which contain 100 or 200
grep -nE '[12]00' a1.txt // lines which contain 100 or 200
grep -nEo '0{4,8}' a1.txt // lines which contain four to eight chars which is 0
grep -nEo '0{4}' a1.txt // lines which contain exactly four chars which is 0
grep -nEo '0{4,}' a1.txt // lines which contain at least four chars which is 0
grep -nEo '0{,8}' a1.txt // lines which contain at most eight chars which is 0
grep -n -A <num> '100' a1.txt // A: print num lines of trailing context (after)
grep -n -B <num> '100' a1.txt // B: print num lines of leading context (before)
grep -n -C <num> '100' a1.txt // C: print num lines of output context (after + before)
grep -c '100' a1.txt // c: print only a count of matching lines per file (like: wc -l)
grep -i 'aBc' a1.txt // i: ignore case distinctions
grep -w 'abc' a1.txt // w: force PATTERN to match only whole words
ps -ef | grep 'crond'
ps -ef | grep 'crond' | grep -v grep
ps -ef | grep '[c]rond'
# text (sed: based on lines)
=> keypoint
- when reading, find specified lines and do action (add, edit, delete)
man sed
info sed
sed --help // stream editor
sed [option]... <script-only-if-no-other-script> <file-path1> [file-path2 ...]
sed -n '3p' b1.txt // find 3rd line and then print (n: suppress automatic printing of pattern space)
sed -n '/peter/p' b1.txt // find lines which contain peter and then print
sed -nr '/0+/p' b1.txt // r: use extended regular expressions (ERE) in the script
sed '2,4d' b1.txt // find 2nd to 4th lines and then delete thems (this doesn't affect origin file)
sed -i '2,4d' b1.txt // find 2nd to 4th lines and then delete thems (this will affect origin file), i: edit files in place
sed -i<suffix> '2,4d' b1.txt // edit files in place and makes backup by suffix
sed '1a 100,HC Kang' b1.txt // find 1st line and then append 100,HC Kang
sed '1i 100,HC Kang' b1.txt // find 1st line and then insert 100,HC Kang
sed '1c 100,HC Kang' b1.txt // find 1st line and then replace 1st line with 100,HC Kang
sed '1s#[0-9]#x#g' b1.txt // find 1st line and then substitute all numbers for x char
sed 's#[0-9]#x#g' b1.txt // find each line and then substitute all numbers for x char
sed 's#[0-9]##g' b1.txt // find each line and then substitute all numbers for empty
sed 's#[0-9]##' b1.txt // find each line and then substitute first number for empty
sed -n '1s#[0-9]#x#gp' b1.txt // find 1st line and then substitute all numbers for empty (only show 1st line)
p: print
'mp' // find m-th line
'm,np' // find m-th to n-th line
'$p' // find the last line
'm,$p' // find m-th to the last line
'm,+np' // find m-th to (m+n)-th line
'm,~np' // find m-th to (n*k)-th line, where k is 0, 1, 2, 3 ...
'm~np' // find (m+n*k)-th line, where k is 0, 1, 2, 3 ...
'/regexp/p' // find all lines which matched by regexp
'm,/regexp/p' // find m-th to one line which first matched by regexp after m-th line
'/regexp1/,/regexp2/p' // TODO
'/regexp1/,np' // TODO
d: delete (delete the line)
a: append (after the line)
i: insert (before the line)
c: replace (replace the line)
s: substitute (substitute text on the line)
=> ref: https://www.gnu.org/software/sed/manual/html_node/Range-Addresses.html
=> ref: https://riptutorial.com/sed/example/13752/specific-range-of-lines
tips: !
sed -r '/^$|#/d' /etc/ssh/sshd_config // except the empty line and #
sed -nr '/^$|#/!p' /etc/ssh/sshd_config // except the empty line and # (!p is not print)
target: 123456 converts to <123456>
echo 123456 | sed 's#123456#<123456>#g' // ok
echo 123456 | sed 's#(.*)#<\1>#g' // error because () is ERE
echo 123456 | sed -r 's#(.*)#<\1>#g' // ok, tips: protect by () and then use \1, \2, \3 ...
target: 123456 converts to 456-123
echo 123456 | sed 's#123456#456-123#g' // ok
echo 123456 | sed -r 's#([1-3]{3})([4-6]{3})#\2-\1#g' // ok
compare1
echo 123456 | sed -r 's#([0-9]{3})#x\1y#' // x123y456
echo 123456 | sed -r 's#([0-9]{3})#x\1y#g' // x123yx456y
compare2
echo 123456 | sed -r 's#([0-9]{2})3([0-9]{2})#x\2y\1z#g' // x45y12z6
echo 123456 | sed -r 's#([0-9]{2})3([0-9]{3})#x\2y\1z#g' // x456y12z
target: get ip
ip addr show ens33 | sed -n '3p' | sed -r 's#.*t (.*)/.*#\1#g' // ok
ip addr show ens33 | sed -nr '3s#.*t (.*)/.*#\1#gp' // ok
target: get acl of a file
stat /etc/hosts | sed -n '4p' | sed -r 's#.*\(0(.*)/-.*#\1#g' // ok
stat /etc/hosts | sed -nr '4s#.*\(0(.*)/-.*#\1#gp' // ok
stat -c%a /etc/hosts // ok
# text (awk)
=> keypoint
- when begin, do something
- when reading, find specified lines and do action (add, edit, delete)
- when end, do something
- row (record) is distinguished from \n (default)
- column (field) is distinguished from space(s) (default)
awk --help
awk -f <program-file-path> <readed-file-path> // -f <=> --file
awk '<program>' <readed-file-path>
--- row ---
awk 'NR==1' b1.txt // find 1st line (NR: number of record)
awk 'NR>=1 && NR<=5' b1.txt // find 1st to 5th line
awk '/regexp/' b1.txt
awk '/regexp/,/regexp/' b1.txt
--- column ---
ls -al /var/ | awk '{print $5}' // find each line and then print 5th field
ls -al /var/ | awk 'NR==4{print $0}' // find 4th line and then print all fields
ls -al /var/ | awk 'NR==4,NR==7{print $0}' // find 4th to 7th line and then print all fields
ls -al /var/ | awk '{print $5,$9}'
ls -al /var/ | awk '{print $5,$9}' | column -t // column --help
ls -al /var/ | awk '{print $5,$NF}' | column -t // $NF is the last field (NF: number of field)
awk -F <field-separator> '{print $1}' b1.txt
awk -v FS=<field-separator> '{print $1}' b1.txt // <=> above command (FS: field separator)
awk -v FS=<field-separator> -v XX=100 '{print $1,XX}' b1.txt
awk -F : '$3~/^1/' /etc/passwd // lines which 3rd field contain(~) regexp(/^1/)
awk -F : '$3!~/^1/' /etc/passwd // lines which 3rd field don't(!) contain(~) regexp(/^1/)
awk 'BEGIN{a[0]=100;a[1]="peter";print a[0],a[1]}' // 100 peter
awk 'BEGIN{a[0]=100;a[1]=peter;print a[0],a[1]}' // 100 (char which not in "" will be considered as variable)
awk 'BEGIN{a[0]=100;peter=200;a[1]=peter;print a[0],a[1]}' // 100 200
awk 'BEGIN{a[0]=100;a[1]="peter";for(i in a)print i,a[i]}' // for loop to print array
awk -F : '{a[$NF]++}END{for(i in a)print i, a[i]}' /etc/passwd // count bash in /etc/passwd
awk -F : '{a[$NF]++}END{for(i in a)print i, a[i]}' /etc/passwd | sort -rnk2 // sort --help
target: change 1st field and the last field in /etc/passwd
awk -F : '{print $NF,$2,$3,$4,$5,$6,$1}' /etc/passwd // miss :
awk -F : '{print $NF":"$2":"$3":"$4":"$5":"$6":"$1}' /etc/passwd // ok
awk -F : -v OFS=: '{print $NF,$2,$3,$4,$5,$6,$1}' /etc/passwd // ok (OFS: output field separator)
target: get ip
ip addr show ens33 | awk 'NR==3' | awk '{print $2}' | awk -F / '{print $1}' // ok
ip addr show ens33 | awk 'NR==3' | awk -F '[ /]+' '{print $3}' // ok, awk supports ERE
ip addr show ens33 | awk -F '[ /]+' 'NR==3{print $3}' // ok
target: count how many empty lines in /etc/services
awk '/^$/' /etc/services | wc -l // ok
awk '/^$/{i++}END{print i}' /etc/services // ok
target: sum 1 to 100
seq 100 | awk '{sum=sum+$1}END{print sum}' // ok
seq 100 | awk '{sum+=$1}END{print sum}' // ok
seq 100 | awk '{sum+=$1;print sum}END{print sum}' // ok, show calculate process
awk 'BEGIN{for(i=1;i<=100;i++)sum+=i;print sum}' // ok
awk 'BEGIN{for(i=1;i<=100;i++){sum+=i;print sum}}' // ok, show calculate process
compare array in shell vs. awk
--- shell ---
a[0]=100
a[1]=peter
echo ${a[0]} ${a[1]}
for i in ${a[*]}
do
echo $i
done
--- awk ---
awk 'BEGIN{a[0]=100;a[1]="peter";for(i in a)print i,a[i]}'
target: check disk usage
df -h | awk -F '[ %]+' '{if($5>70)print "disk not enough",$1,$5,$NF}' // not exclude header
df -h | awk -F '[ %]+' 'NR>1{if($5>70)print "disk not enough",$1,$5,$NF}' // ok
target: find word which length >= 5
echo I am Peter Kang. Hello Everyone. Nice to meet you. | awk -F '[ .]' '{for(i=1;i<=NF;i++)print $i}' // test
echo I am Peter Kang. Hello Everyone. Nice to meet you. | awk -F '[ .]+' '{for(i=1;i<=NF;i++)print $i}' // test
echo I am Peter Kang. Hello Everyone. Nice to meet you. | awk -F '[ .]+' '{for(i=1;i<=NF;i++)print $i, length($i)}' // test
echo I am Peter Kang. Hello Everyone. Nice to meet you. | awk -F '[ .]+' '{for(i=1;i<=NF;i++)if(length($i)>=5)print $i}' // ok
# text
cut -d <delimiter> -f <fields>
cut -c <characters>
cut -b <bytes>
# process
ps --help <simple|list|output|threads|misc|all> // all will show simple + list + output + threads + misc
ps --help <s |l |o |t |m |a>
ps -l // l: long format
ps -e // e: select all processes (identical to -A)
ps -f // f: do full-format listing
ps aux
top
top -p <pid>
rpm -qf $(which pstree)
pstree --help
pstree [-ap] // a: show command line arguments, p: show pid
pwdx // report current working directory of a process
# kernal & shell
dmesg // <=> cat /var/log/dmesg
uname // print certain system information. with no option, same as -s
uname [-asr] // a: all information, s: kernel name, r: kernel release
ll /lib/modules/$(uname -r)
cat /etc/redhat-release
cat /etc/os-release // show os
cat /etc/shells // list all shell
# variable
set // list all shell variables
env // list all environment variables (think as hereditary, not global)
env <command> //
env -i <command> // i: ignore environment (start with an empty environment)
env -u <variable> <command> // u: unset (remove variable from the environment)
env <variable>=<value> <command> //
unset <variable> //
readonly <variable> // make variable readonly (cannot assign new value and cannot unset)
export <variable> // make shell variable to environment variable
export -p
export -n <variable> // cancel environment variable
# common variable
echo $PATH
echo $HOSTNAME // hostname
echo $PWD // pwd
echo $USER // whoami
echo $UID
echo $HOME
echo $MAIL
echo $LANG
echo $PS1
echo $PS2
echo $HISTFILE
echo $HISTSIZE
echo $SHELL
echo $BASH
echo $BASHPID
echo $PPID
echo $$ // the current shell pid
echo $?
echo $@ // the shell script parameters
echo $0
echo $1
echo $2
echo $3
echo $<num>
# sub shell
source ~/.bash_profile // use the same shell
. ~/.bash_profile // <=> source ~/.bash_profile
# acl (access control list: owner/group/others)
getfacl <file> // get file access control lists
su [-] [user] // change to some user (user default: root), -: make the shell a login shell
sudo <command> // change to root to run command, and then change back
suod -u <user> <command> // u: specified user name or ID
visudo // vi /etc/sudoers
id [user] // print user and group information for the specified user (user default: the current user)
id -u // print only the effective user id (-u <=> --user)
id -g // print only the effective group id (-g <=> --group)
id -G // print all group ids (-G <=> --groups)
chmod <ugo> <file> // u, g o: 0, 1, 2, 3, 4, 5, 6, 7
chmod <ugoa><+-=><rwx> <file> // ex. chmod ug=rwx,o-x <file>
chown <user>:<group> <file>
chown $(id -u):$(id -g) <file>
useradd <user> // change password: passwd <user>
userdel <user>
usermod -g <group> <user> // g: force use <group> as new primary group (see: groups <user> & cat /etc/group & cat /etc/passwd)
usermod -G <group>[,<group>] <user> // G: add <user> to <group> with removing <user> from other groups (see: groups <user> & cat /etc/group)
usermod -aG <group>[,<group>] <user> // aG: append <user> to <group> without removing <user> from other groups (see: groups <user> & cat /etc/group)
usermod -aG wheel <user> // wheel's members can use 'sudo'
groupadd <group>
groupdel <group>
Q: useradd vs. adduser
=> ref: https://askubuntu.com/questions/345974/what-is-the-difference-between-adduser-and-useradd
# network
man ifconfig // this program is obsolete
ifconfig // like window ipconfig
ifconfig -a // a: show up & down devices
ifconfig <device-name> // show some device
ifconfig <device-name> up // startup some device
ifconfig <device-name> down // shutdown some device
ifconfig <device-name> <ip> // temp edit ip
ifup <device-name> // startup some device (need the device config)
ifdown <device-name> // shutdown some device (need the device config)
nmcli -h // nmcli (network manager command line)
nmcli
nmcli d // d: device, list devices managed by network manager
netstat -plant // list using ports
ss -plant // p: processes, l: listening, a: all, n: numeric, t: tcp
cat /etc/sysconfig/network-scripts/ifcfg-<device-name> // show some device config
hostnamectl // show hostname
hostnamectl set-hostname <new-hostname> // set hostname (this set /etc/hostname)
vi /etc/hosts // manually, add ip host-name mapping
ip route // show route table
ping <ip> // ping pong by icmp
ping <name> // before icmp, need to resolve name
traceroute <ip> // trace route
mtr <ip> // dynamic trace route
wget -h
wget <url> // this will save a file
wget -o <local-file-path> <url> // o: log messages to <local-file-path>
wget -O <local-file-path> <url> // O: write documents to <local-file-path>
wget -P <directory-prefix> <url> // P: save files to <directory-prefix>/...
curl -h // -h <=> --help, this is not the full help (the full help is stripped into categories)
curl --help category // list an overview of all categories
curl --help <category> // ex. auth, connection, curl, dns, file, ftp, http, ...
curl --help all
curl <url> // this will not save a file
curl -L <url> // -L <=> --location, L: follow redirects
curl -o <local-file-path> <url> // o: write output to <local-file-path> instead of stdout
curl -s -o <local-file-path> <url> // s: silent mode (don't output anything)
curl -sS -o <local-file-path> <url> // S: show error. with -s, make curl show errors when they occur
curl -X <method> -H <header> <url>
curl -X <method> -H <header> -H <header> <url> // multi headers
host //
dig //
EX. wget
// recursive
wget -e robots=off -r -np --page-requisites --convert-links 'http://example.com/folder/'
=> ref: https://stackoverflow.com/questions/273743/using-wget-to-recursively-fetch-a-directory-with-arbitrary-files-in-it
EX. curl
// success
curl http://hochun836.com/demo-angular/
curl http://hochun836.com/demo-angular // response code: 301
curl -L http://hochun836.com/demo-angular
curl -o index.html http://hochun836.com/demo-angular/
curl http://hochun836.com/demo-angular/ > index.html // > index.html like -o index.html
curl -s -o index.html http://hochun836.com/demo-angular/
curl -s http://hochun836.com/demo-angular/ > index.html // > index.html like -o index.html
// fail
curl http://hochun837.com // curl: (6) Could not resolve host: hochun837.com; Unknown error
curl -s http://hochun837.com
curl -sS http://hochun837.com
curl -o index2.html http://hochun837.com
curl -s -o index2.html http://hochun837.com
curl -sS -o index2.html http://hochun837.com
=> ref: https://unix.stackexchange.com/questions/196549/hide-curl-output
Q: wget vs. curl
=> ref: https://unix.stackexchange.com/questions/47434/what-is-the-difference-between-curl-and-wget
=> ref: https://www.baeldung.com/linux/curl-wget
=> ref: https://kknews.cc/zh-tw/design/jqm3b4y.html
Q: how to execute a script from network ?
curl <shell-script-url> | bash
curl <shell-script-url> | sudo bash
# network (centos6)
ifconfig // see eth[0,1,2...]
cat /etc/udev/rules.d/70-persistent-net.rules
# network (centos7)
ifconfig // see ens[0,1,2...]
ip addr
ip link help
ip link // show mtu & qdisc & state & mode & group & qlen
ip netns help
ip netns // <=> ip netns list
ip netns add <name>
ip netns exec <name> <command>
ip netns add test_ns
ip link set dev lo up // set state to 'up' of the device lo
ip netns exec test_ns ping 127.0.0.1
ip link add veth100 type veth peer name veth101
ip link set veth101 netns test_ns
ip netns exec test_ns ip link
ip netns exec test_ns ifconfig veth101 10.1.123.2/24 up
ip netns exec test_ns route -n
ifconfig veth100 10.1.123.1/24 up
ping 10.1.123.2
route -n
ip netns exec test_ns ping 10.1.123.1
ip netns exec test_ns route -n
# route
ip route
route -h // -h <=> --help
route // list kernel routing tables
route -n // don't resolve names (-n <=> --numeric)
route -v // be verbose (-v <=> --verbose)
route add -host <destination> gw <gateway> [dev <device-name>]
route add -net <destination> netmask <subnet> gw <gateway> [dev <device-name>] // subnet format is xxx.xxx.xxx.xxx
route add default gw <gateway>
route del <destination>
route del default
=> ref: https://www.bilibili.com/video/BV1ht411f7FP?p=3
# firewall
iptables -h // centos6 (-h <=> --help)
iptables -L [chain [rulenum]] // list the rules in a chain or all chains (-L <=> --list)
iptables -L [chain] -n // numeric output of addresses and ports (-n <=> --numeric)
iptables -L [chain] -v // verbose mode (-v <=> --verbose)
iptables -L [chain] --line-numbers // print line numbers when listing
iptables -L [chain] -t [table] // table to manipulate (default: `filter') ex. table: nat (-t <=> --table)
iptables -F [chain] // delete all rules in chain or all chains (-F <=> --flush)
iptables -X [chain] // delete a user-defined chain (-X <=> --delete-chain)
iptables -Z [chain [rulenum]] // zero counters in chain or all chains (-Z <=> --zero)
iptables -S [chain [rulenum]] // print the rules in a chain or all chains (-S <=> --list-rules)
firewall-cmd -h // centos7
firewall-cmd --list-all
firewall-cmd --list-services
firewall-cmd --list-ports
firewall-cmd --zone=public --add-port=1433/tcp --permanent
firewall-cmd --zone=public --remove-port=1433/tcp --permanent
firewall-cmd --reload
ls -al /etc/firewalld/
ls -al /usr/lib/firewalld/
setenforce [ Enforcing | Permissive] // modify the mode SELinux is running in (temporarily)
setenforce [ 1 | 0 ]
getenforce // get the current mode of SELinux
sestatus // show SELinux status
cat /etc/selinux/config // SELinux (Security-Enhanced Linux)
=> ref: https://www.cnblogs.com/sparkdev/p/9340924.html
=> ref: https://dotblogs.com.tw/echo/2017/06/19/linux_selinux_mode
# service (centos6)
service <service-name> status // ex. sshd, network, firewalld, crond, atd, chronyd
service <service-name> start
service <service-name> stop
service <service-name> restart
chkconfig // check service config on different runlevel
vi /etc/inittab // edit default runlevel
# service (centos7, PS: service & chkconfig still work by using systemctl)
systemctl status <service-name> // ex. sshd, multi-user.target
systemctl start <service-name>
systemctl stop <service-name>
systemctl restart <service-name>
systemctl enable <service-name>
systemctl enable --now <service-name> // in addition to enabling it, start unit
systemctl disable <service-name>
systemctl disable --now <service-name> // in addition to disabling it, stop unit
systemctl is-enabled <service-name>
systemctl set-default <multi-user.target|graphical.target> // multi-user like runlevel 3, graphical like runlevel 5
systemctl get-default
systemctl list-dependencies // recursively show units
systemctl cat <service-name> // show unit file
ls -al /etc/systemd/system/default.target
cat /etc/systemd/system/default.target
ls -al /etc/systemd/system/default.target.wants/
# other
init 3 // change to command interface
init 5 // change to graphic interface
# jq (process the json and query the desired results)
yum install jq // depend on => yum install epel-release
jq --help
- processing json inputs
- applying the given filter to its json text inputs
- producing the filter's results as json on standard output
jq <filter> <file>
echo '{"foo": 0}' | jq .
echo {"foo": 0} | jq . // parse error: Invalid literal at line 1, column 5
=> ref: https://blog.csdn.net/qq_38423105/article/details/89786736
=> ref: https://jqplay.org/
=> ref: https://www.itread01.com/p/518194.html
# scl (Software Collections)
yum install scl-utils // no depend on others
yum install centos-release-scl // setup repository
yum install python27 // depend on => yum install centos-release-scl
scl -h // -h <=> --help
scl -l // -l <=> --list
scl enable python27 bash
=> ref: https://www.softwarecollections.org/en/scls/
# docker
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo // setup repository
yum install docker-ce docker-ce-cli containerd.io // install docker engine
systemctl start docker // start docker service
systemctl status docker // check docker service
systemctl enable docker // start docker service when boot
=> ref: https://docs.docker.com/engine/install/centos/
# docker uninstall
yum remove docker-ce docker-ce-cli containerd.io
rm -rf /var/lib/docker/
# docker compose
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose // if need
docker-compose version
=> ref: https://docs.docker.com/compose/install/
# kubernetes (by kubeadm)
- step1. start chronyd, stop firewalld
systemctl enable --now chronyd
systemctl disable --now firewalld
systemctl status chronyd
systemctl status firewalld
- step2. cancel selinux, swap
vi /etc/selinux/config
vi /etc/fstab
- step3. add config file
- step4. load br_netfilter
modprobe br_netfilter
lsmod | grep br_netfilter
- step5. reboot
reboot
getenforce
free -m
- step6. install docker
- step7. config cgroup
- step8. install kubeadm kubectl kubelet
yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
systemctl enable --now kubelet
- step9. init cluster by kubeadm
kubeadm init
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
export KUBECONFIG=/etc/kubernetes/admin.conf
- step10. deploy a pod network to the cluster
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
=> ref: https://www.bilibili.com/video/BV1cK4y1L7Am?p=7
=> ref: https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/
# nginx
yum install nginx // create (user, group): (nginx, nginx), depend on => yum install epel-release
systemctl enable nginx
systemctl start nginx
ls -al /etc/nginx
cat /etc/nginx/nginx.conf
ls -al /usr/share/nginx/html // found by nginx.conf
=> https://phoenixnap.com/kb/how-to-install-nginx-on-centos-7
# apache
yum install httpd // create (user, group): (apache, apache)
systemctl enable httpd
systemctl start httpd
cat /etc/httpd/conf/httpd.conf
ls -al /etc/httpd/conf/ // httpd.conf
ls -al /etc/httpd/conf.d/
ls -al /etc/httpd/conf.modules.d/ // 00-mpm.conf
ls -al /var/log/httpd/
ls -al /var/www/html/
ls -al /lib64/httpd/modules/
cat /etc/httpd/run/httpd.pid // main process id (PID)
ps aux | grep httpd // main process created by root, sub processes created by apache
netstat -tupln | grep 80
httpd -h // list available command line options
httpd -M // a synonym for -t -D DUMP_MODULES (show all loaded modules: static & shared)
httpd -l // list compiled in modules (that is, static)
httpd -t // <=> service httpd configtest
httpd -v // show version number
httpd -V // show compile settings (Server MPM: prefork or worker)
watch -n 1 'ps aux | grep httpd' // n: seconds to wait between updates
rpm -qf $(which ab) // httpd-tools-2.4.6-97.el7.centos.x86_64
ab -c <concurrency> -n <requests> <url> // c: number of multiple requests to make at a time, n: number of requests to perform
# mysql
yum install mariadb-server
systemctl enable mariadb
systemctl start mariadb
mysql -u <user> -p // login mysql by <user> and then key password
cat /etc/my.cnf
ls -al /etc/my.cnf.d/
cat /var/log/mariadb/mariadb.log
cat /var/run/mariadb/mariadb.pid
=> adv: https://gist.github.com/hochun836/9b4fd2b3cad4826ffe43720a0287ac03
# sql server (aka. mssql)
- install sql server
sudo curl -o /etc/yum.repos.d/mssql-server.repo https://packages.microsoft.com/config/rhel/7/mssql-server-2019.repo
sudo yum install -y mssql-server
sudo /opt/mssql/bin/mssql-conf setup // choose an edition of sql server
systemctl enable --now mssql-server // memory at least 2G
systemctl status mssql-server
- open firewall
sudo firewall-cmd --permanent --add-port=1433/tcp
sudo firewall-cmd --reload
sudo firewall-cmd --list-all
- install sqlcmd (sql server command line)
sudo curl -o /etc/yum.repos.d/msprod.repo https://packages.microsoft.com/config/rhel/7/prod.repo
sudo yum install -y mssql-tools unixODBC-devel
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
source ~/.bash_profile
sqlcmd -?
=> ref: https://docs.microsoft.com/zh-tw/sql/linux/quickstart-install-connect-red-hat?view=sql-server-ver15
=> ref: https://stackoverflow.com/questions/48581303/failed-start-for-microsoft-sql-server-database-engine-on-linux
# python (aka. python2)
python --version // 2.x (built-in)
pip --version // command not found
yum install python-pip // <=> yum install python2-pip
wget https://bootstrap.pypa.io/pip/2.7/get-pip.py && python get-pip.py // another way
ls -al /usr/bin/python*
ls -al /usr/bin/pip*
ls -ald /usr/lib/python*
# python3
yum install python36 // depend on => yum install epel-release
python3 --version
pip3 --version
# nvm (node version manager)
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
exit and login
nvm --version // <=> nvm -v
ls -al ~/.nvm
=> ref: https://github.com/nvm-sh/nvm
=> ref: https://www.footmark.info/linux/centos/nvm/
# rvm (ruby version manager)
gpg2 --keyserver hkp://pgp.mit.edu --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB // import keys
curl -sSL https://get.rvm.io | bash -s stable // install rvm
source ~/.rvm/scripts/rvm // avoid rvm command not found
rvm version // <=> rvm -v
ls -al ~/.rvm/rubies/
ls -al ~/.rvm/gems/
=> ref: https://rvm.io/
=> ref: https://noobient.com/2019/02/12/installing-rvm-and-ruby-on-centos-7/
# gitlab
- step1. install dependencies
sudo yum install -y curl policycoreutils-python openssh-server perl
- step2. enable openssh server daemon if not enabled: sudo systemctl status sshd
sudo systemctl enable sshd
sudo systemctl start sshd
- step3. check if opening the firewall is needed with: sudo systemctl status firewalld
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo systemctl reload firewalld
- step4. install postfix to send notification emails
sudo yum install postfix
sudo systemctl enable postfix
sudo systemctl start postfix
- step5. add the gitlab package repository and install the package
*** ce ***
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
yum install -y gitlab-ce
*** ee ***
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash
yum install -y gitlab-ee
- step6. edit config
vi /etc/gitlab/gitlab.rb // external_url 'http://192.168.145.151:8001'
gitlab-ctl reconfigure
gitlab-ctl restart
gitlab-ctl status
firewall-cmd --add-port=8001/tcp --permanent
firewall-cmd --reload
firewall-cmd --list-all
- step7. login
username: root
password: cat /etc/gitlab/initial_root_password
=> ref: https://about.gitlab.com/install/#centos-7
=> ref: https://xyz.cinc.biz/2020/08/centos-7-gitlab-install-ssl.html
# gitlab (offline)
- step1. download the gitlab package and required dependencies
- step2. transfer the files to the offline environment
- step3. install dependencies
rpm -ivh policycoreutils-python
rpm -ivh perl
...
- step4. install the gitlab package
rpm -Uvh gitlab-ee-14.9.1-ee.0.el7.x86_64.rpm
=> ref: https://docs.gitlab.com/ee/topics/offline/quick_start_guide.html
=> ref: https://packages.gitlab.com/gitlab
# jenkins
wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
yum upgrade
yum install epel-release java-11-openjdk-devel
yum install jenkins
vi /etc/sysconfig/jenkins
JENKINS_USER="root" // this must exist in centos users
JENKINS_PORT="8002"
systemctl daemon-reload
systemctl start jenkins
systemctl status jenkins
firewall-cmd --add-port=8002/tcp --permanent
firewall-cmd --reload
firewall-cmd --list-all
cat /var/lib/jenkins/secrets/initialAdminPassword
=> ref: https://www.jenkins.io/doc/book/installing/linux/
# bind (one type of dns server)
yum install bind
id named
ls -al /var/named
ls -ald /etc/named*
cat /var/named/named.ca
vi /etc/named.conf
named-checkconf // check /etc/named.conf
systemctl start named
systemctl status named
netstat -plant | grep 53
=> ref: https://www.bilibili.com/video/BV1at4y1a7Ge?p=9
# nfs (network file system)
--- server ---
showmount -e
--- client ---
yum install -y nfs-utils
showmount -e <ip>
=> ref: https://www.bilibili.com/video/BV1mY4y1a7Qe
=> ref: https://www.bilibili.com/video/BV1bZ4y1p7pk?p=6
# [note] command too long
ls \
-al /var
=> note: there is not any space follwing \ (backslash)
// bad example
ls \
-al /var
# [note] shell kind
login vs. nologin
interactive vs. nointeractive
ls -al /etc/bashrc
ls -al /etc/profile
ls -al ~/.bashrc
ls -al ~/.bash_profile
# [note] who is PID 1
centos6: init
cat /etc/inittab
ls -al /etc/init/
centos7: systemd
ls -al /etc/init.d/
# [note] encounter "no manual entry for xxx"
yum install man-pages
# [note] write a infinity loop
while :; do :; done& // &: run in background
# [note] sh -c
echo 100 > a.txt
sudo chown root:root a.txt
echo 200 >> a.txt // permission denied
sudo echo 200 >> a.txt // permission denied (sudo only works on echo not >>)
sudo sh -c 'echo 200 >> a.txt'
cat a.txt
=> ref: https://iter01.com/537956.html
=> ref: https://askubuntu.com/questions/831847/what-is-the-sh-c-command
# [note] fix shell propmt color
export PS1="\e[0;36m$PS1\e[m" // 0;36 is some color code
=> ref: https://www.cyberciti.biz/faq/bash-shell-change-the-color-of-my-shell-prompt-under-linux-or-unix/
# [note] highlight vim syntax
yum install vim-enhanced
alias vi=vim
=> ref: https://www.if-not-true-then-false.com/2012/vi-vim-syntax-highlighting-on-fedora-centos-red-hat-rhel/
# [note] install gui for centos7
yum groupinstall "GNOME Desktop" "Graphical Administration Tools"
systemctl set-default graphical.target
reboot
# [note] using yum, if encounter "There was a problem importing one of the Python modules"
=> check: python version and modules needed
=> reason: yum depends on python
which yum // /usr/bin/yum
cat /usr/bin/yum // first line: #!/usr/bin/python
ls -ald /usr/lib/python2.7/site-packages/yum/
# [note] use static ip instead of dhcp
=> edit: vi /etc/sysconfig/network-scripts/ifcfg-<device-name>
BOOTPROTO=static
IPADDR=<static ip>
NETMASK=<netmask>
BROADCAST=<broadcast>
NETWORK=<network>
GATEWAY=<gateway>
=> test: ping 8.8.8.8
# [note] wget: unable to resolve host address
=> edit: vi /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4
=> test: wget https://blog.hochun836.com
# [note] introduce /etc/resolv.conf
domain example.com // ping abc => ping abc.example.com
search example1.com example2.com example3.com
nameserver x.x.x.x
=> ref: http://dns-learning.twnic.net.tw/bind/intro4.html
=> ref: https://www.jianshu.com/p/21fd987c088c
# [note] reload network interface
- way1
ifdown <interface-name>
ifup <interface-name>
- way2
ethtool -i <interface-name> // find driver name
modprobe -r <driver-name> // r: remove
modprobe <driver-name>
# [note] cancel selinux
- way1 (temporarily)
setenforce 0
- way2 (permanent, need reboot)
vi /etc/selinux/config
SELINUX=disabled
# [note] cancel swap
vi /etc/fstab
comment /dev/mapper/centos-swap swap
# [note] fix timezone
date // Thu Aug 26 00:42:18 EDT 2021 (ps. EDT is America/New_York)
timedatectl
ls /usr/share/zoneinfo/
ls -l /etc/localtime // /etc/localtime -> ../usr/share/zoneinfo/America/New_York
timedatectl list-timezones | grep Taipei // Asia/Taipei
timedatectl set-timezone Asia/Taipei
date
timedatectl
ls -l /etc/localtime // /etc/localtime -> ../usr/share/zoneinfo/Asia/Taipei
=> ref: https://blog.gtwang.org/linux/centos-linux-change-system-timezone-command-tutorial/
# [note] after fix timezone, adjust time
yum install ntp // ntp: network time protocol
systemctl enable --now ntpd
systemctl status ntpd
date // wait a moment for adjust time
=> ref: https://blog.gtwang.org/linux/linux-ntp-installation-and-configuration-tutorial/
# [note] do something cross cluster
=> ref: https://blog.csdn.net/lianghecai52171314/article/details/104523211
# [note] file system structure (1)
ls -al /
bin -> usr/bin
lib -> usr/lib
lib64 -> usr/lib64
sbin -> usr/sbin
usr
ls -al /etc
init.d -> rc.d/init.d
rc0.d -> rc.d/rc0.d
rc1.d -> rc.d/rc1.d
rc2.d -> rc.d/rc2.d
rc3.d -> rc.d/rc3.d
rc4.d -> rc.d/rc4.d
rc5.d -> rc.d/rc5.d
rc6.d -> rc.d/rc6.d
rc.local -> rc.d/rc.local
rc.d
ls -al /usr/bin
python -> python2
python2 -> python2.7
python2.7
sh -> bash
bash
csh -> tcsh
tcsh
ls -al /sbin/init
/sbin/init -> ../lib/systemd/systemd
# [note] file system structure (2)
/bin (binary)
/boot (bootstrap)
ls -al /boot // see vmlinuz-3.10.0-1127.el7.x86_64, efi, grub
uname -r // the kernel release
/dev (device)
/etc (configuration)
/home (home directory for user)
/lib (library)
/lib64
/media
/mnt (mount)
/opt
/proc (processs, real-time info.)
cat /proc/cpuinfo
cat /proc/meminfo
ll /proc/$$
/root (home directory for root)
/run
/sbin (binary for superuser)
/srv
/sys
/tmp (temporary)
file in tmp will be deleted auto after some time
/usr
/var
# [note] hard link vs. symbolic link (symlink, soft link)
echo 100 > ~/test_file
ln ~/test_file ~/hard_link
ln -s ~/test_file ~/soft_link
ls -l ~/test_file ~/hard_link ~/soft_link
rm -f ~/test_file
ls -l ~/hard_link ~/soft_link
IMPORTANT: fileName is just a reference to inode
- hard link
ref1 (test_file) -> inode A -> data block A
ref2 (hard_link) -> inode A -> data block A
- soft link
ref3 (soft_link) -> inode B -> data block B -> inode A -> data block A
=> ref: https://www.bilibili.com/video/BV1JJ411S7qy
# [note] cat /etc/services
service-name port/protocol [aliases ...] [# comment]
tcpmux 1/tcp # TCP port service multiplexer
tcpmux 1/udp # TCP port service multiplexer
...
ftp 21/tcp
ftp 21/udp fsp fspd
ssh 22/tcp # The Secure Shell (SSH) Protocol
ssh 22/udp # The Secure Shell (SSH) Protocol
telnet 23/tcp
telnet 23/udp
lmtp 24/tcp # LMTP Mail Delivery
lmtp 24/udp # LMTP Mail Delivery
smtp 25/tcp mail
smtp 25/udp mail
vi /etc/sysconfig/network-scripts/ifcfg-ens33
ifdown ens33 && ifup ens33 // if you edit ifcfg-ens33
// dynamic
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=...
DEVICE=ens33
ONBOOT=yes
// static
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
IPADDR=192.168.145.161
NETMASK=255.255.255.0
BROADCAST=192.168.145.255
NETWORK=192.168.145.0
GATEWAY=192.168.145.2
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=...
DEVICE=ens33
ONBOOT=yes
DNS1=8.8.8.8
DNS2=8.8.4.4
// DNS1, DNS2 affect /etc/resolv.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment