Shell
Links
Quick notes
System information
neofetch, system infodu -sh <file>/<directory>, check the size of file or directorydf -h, display free disk space-h, 1k = 1024 byte-H, 1k = 1000 byte
uname -s, print kernel name- Linux
- Darwin
uname -r, linux release numberlast -n 50, check last logged in userslastb -n 50,pstree -p, process treew, show who is logged on and what they are doing
Auto delete files in tmp (CentOS 7)
tmpwatch- removes files which haven’t been accessed for a period of time- install:
yum install -y tmpwatch - delete files not accessed in 7 days:
tmpwatch 7d /tmp
- install:
cron定期执行指定程序crondcrontab -e0 0 * * * tmpwatch 7d /tmp
sed
Sed is the ultimate stream editor.
- Sed: http://www.grymoire.com/Unix/Sed.html
- Regular Expression: http://www.grymoire.com/Unix/Regular.html
Some examples:
sed s/spaceship/honukai/g <old.file >new.file- change
= “ “ sed -i.bak '/ZSH_THEME/s/".*"/"honukai"/'- backup old file to
.bak ZSH_THEME="robbyrussell"=>ZSH_THEME="honukai"
- backup old file to
- change
= sed -i.bak 's/^key\s*=.*/key = value/'^, start with\s, space, tag, …
timezone
apt-get install tzdata
ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
file exist
file=data
if [ -f ${file} ]
then
echo "$file found"
else
echo "$file not found"
fi
-dexists and is a directory-eexists-fexists and is a regular file-hexists and is a symbolic link
Symbol link
ln -sf <target> <symlink>
Example for glibc:
ln -sf libstdc++.so.6.0.21 libstdc++.so.6
strings /usr/lib64/libstdc++.so.6 | grep GLIBCXX
Open port in CentOS 7
firewall-cmd --permanent --add-port=8888/tcp
firewall-cmd --reload
firewall-cmd --list-ports
Create and delete user
Create user:
useradd <username> -b <base_dir> -e <expire_date>
echo <passwd> | passwd --stdin <username>
-b,--base-dir, HOME_DIR=${BASE_DIR}/${USERNAME}-d,--home-dir-e, example:2018-01-30
Delete user:
userdel -r <username>
-f, force remove, even if the user is still logged in. Dangerous!-r, remove user’s home directory
The art of command line
https://github.com/jlevy/the-art-of-command-line
AMAZING!
set -o vi, vi style command line!!, last commandjq, JSON processor
man bash
bash -c <string>, Docker use
TODO
List all versions
Yum.
yum --showduplicates list <package>
yum install <package>-<version>
Brew.
brew info <package>
brew search <package>@
brew install <package>@<version>
brew link <package>@<version> --force --overwrite
print colours
for i in {0..255}; do
printf "\x1b[38;5;${i}mcolour${i}\x1b[0m\n"
done