Bash

bash

删除空行

1
sed -i '/^$/d' *.md

ssh_copy_id_auto

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/expect  
set timeout 10
set username [lindex $argv 0]
set password [lindex $argv 1]
set hostname [lindex $argv 2]

spawn ssh-copy-id -i $HOME/.ssh/id_rsa.pub $username@$hostname
expect {
#first connect, no public key in ~/.ssh/known_hosts
"Are you sure you want to continue connecting (yes/no)?" {
send "yes\r"
expect "password:"
send "$password\r"
}
#already has public key in ~/.ssh/known_hosts
"password:" {
send "$password\r"
}
"Now try logging into the machine" {
#it has authorized, do nothing!
}
}
expect eof

auto ssh

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
#!/bin/bash
LANG=zh_CN.UTF-8
export LANG

ssh_copy_id_auto() {
user=$name
pass=$passwd
host=$host
port=$port
key=$(echo ~/.ssh/id_rsa.pub)
expect << EOF
set timeout 8;
spawn ssh-copy-id -i $key -p $port $user@$host;
expect {
*(yes/no)?* { send yes\r; exp_continue; }
*password:* { send $pass\r; exp_continue; }
eof { exit 0; }
};
EOF
}

while :
do
echo "目前自动拷贝公钥只支持root用户"
echo -n "请选择 1自动拷贝公钥到远程主机; 2SSH链接远程主机"
echo " "
read choice
case $choice in
1) #Copy ID
echo "输入远程主机用户名:"
read -p "" name
echo "输入远程主机密码"
read -p "" passwd
echo "输入远程主机ip地址"
read -p "" host
echo "输入远程主机端口"
read -p "" port

echo "远程主机用户名 $name"
echo "远程主机密码 $passwd"
echo "远程主机ip地址 $host"
echo "远程主机端口 $port"
echo "Now start copy public_key to remote host..."
sleep 3
ssh_copy_id_auto
break
;;

2) #SSH Connect Remote Host
echo "输入远程主机用户名"
read -p "" name
echo "输入远程主机IP"
read -p "" host
echo "输入远程主机端口"
read -p "" port
echo "远程主机端口 $port"
echo "开始SSH链接远程主机..."
ssh -p $port $name@$host
break
;;
*) # error
echo "ERROR Try again?"
echo "强制结束按Ctrl+C"
esac
done

cleanRAM

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
#!/bin/bash
## Bash Script to clear cached memory on (Ubuntu/Debian) Linux
## By Philipp Klaus
## see <http://blog.philippklaus.de/2011/02/clear-cached-memory-on-uuu/>

if [ "$(whoami)" != "root" ]
then
echo "You have to run this script as Superuser!"
exit 1
fi

# Get Memory Information
freemem_before=$(cat /proc/meminfo | grep MemFree | tr -s ' ' | cut -d ' ' -f2) && freemem_before=$(echo "$freemem_before/1024.0" | bc)
cachedmem_before=$(cat /proc/meminfo | grep "^Cached" | tr -s ' ' | cut -d ' ' -f2) && cachedmem_before=$(echo "$cachedmem_before/1024.0" | bc)

# Output Information
echo -e "This script will clear cached memory and free up your ram.\n\nAt the moment you have $cachedmem_before MiB cached and $freemem_before MiB free memory."

# Test sync
if [ "$?" != "0" ]
then
echo "Something went wrong, It's impossible to sync the filesystem."
exit 1
fi

# Clear Filesystem Buffer using "sync" and Clear Caches
sync && echo 3 > /proc/sys/vm/drop_caches

freemem_after=$(cat /proc/meminfo | grep MemFree | tr -s ' ' | cut -d ' ' -f2) && freemem_after=$(echo "$freemem_after/1024.0" | bc)

# Output Summary
echo -e "This freed $(echo "$freemem_after - $freemem_before" | bc) MiB, so now you have $freemem_after MiB of free RAM."

exit 0

gbk2utf

1
2
3
4
5
6
7
#!/bin/sh
ls * | while read CMD
do
echo $CMD

iconv -f GBK -t UTF-8 $CMD -o $CMD
done

html2md

1
2
3
4
5
6
7
#!/bin/sh
ls * | while read CMD
do
echo $CMD

iconv -f GBK -t UTF-8 $CMD -o $CMD
done

jpg2pdf

1
2
3
4
5
6
7
#!/bin/sh
ls * | while read line;do echo $line;convert $line $line.pdf;done

ls -ltr
echo "合并pdf"
sleep 5
pdfunite *.pdf all.pdf

pdf2md

1
2
3
4
5
6
7
mkdir /path/pdf2md

ls *.pdf | while read CMD
do
echo $CMD
pdftohtml $CMD -i -s -stdout /path/pdf2md/$CMD
done

led键盘灯

1
2
3
4
5
6
7
8
9
10
11
#!/bin/bash

if [ "$1" = "on" ] ||[ "$1" = "ON" ]; then
xset led named 'Scroll Lock'
elif [ "$1" = "off" ] ||[ "$1" = "OFF" ]; then
xset -led named 'Scroll Lock'
else
echo "Usage: $0 on/off"
exit 1
fi
exit 0

备份

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
#!/bin/bash

DATE=$(date)
DISK=$(lsblk | grep ^sdc|awk '{print $1}')

SDC1=$(cat /proc/mounts | grep sdc1 | awk '{print $1}')
SDC2=$(cat /proc/mounts | grep sdc2 | awk '{print $1}')
SDC3=$(cat /proc/mounts | grep sdc3 | awk '{print $1}')
SDC4=$(cat /proc/mounts | grep sdc4 | awk '{print $1}')
SDC5=$(cat /proc/mounts | grep sdc5 | awk '{print $1}')
SDC6=$(cat /proc/mounts | grep sdc6 | awk '{print $1}')

if [ "$DISK" == "sdc" ]
then

if [ "$SDC1" == "/dev/sdc1" ]
then
echo "$DATE sdc1 is already mounted" >> /path/logs/mount-sdc.log
else
echo "$DATE mount sdc1 to /path " >> /path/logs/mount-sdc.log
sudo mount /dev/sdc1 /path/
fi
if [ "$SDC2" == "/dev/sdc2" ]
then
echo "$DATE sdc2 is already mounted" >> /path/logs/mount-sdc.log
else
echo "$DATE mount sdc2 to /path " >> /path/logs/mount-sdc.log
sudo mount /dev/sdc2 /path/
fi
if [ "$SDC3" == "/dev/sdc3" ]
then
echo "$DATE sdc3 is already mounted" >> /path/logs/mount-sdc.log
else
echo "$DATE mount sdc3 to /path " >> /path/logs/mount-sdc.log
sudo mount /dev/sdc3 /path/
fi
if [ "$SDC4" == "/dev/sdc4" ]
then
echo "$DATE sdc4 is already mounted" >> /path/logs/mount-sdc.log
else
echo "$DATE mount sdc4 to /path " >> /path/logs/mount-sdc.log
sudo mount /dev/sdc4 /path/
fi
if [ "$SDC5" == "/dev/sdc5" ]
then
echo "$DATE sdc5 is already mounted" >> /path/logs/mount-sdc.log
else
echo "$DATE mount sdc5 to /path " >> /path/logs/mount-sdc.log
sudo mount /dev/sdc5 /path/
fi
if [ "$SDC6" == "/dev/sdc6" ]
then
echo "$DATE sdc6 is already mounted" >> /path/logs/mount-sdc.log
else
echo "$DATE mount sdc6 to /path " >> /path/logs/mount-sdc.log
sudo mount /dev/sdc6 /path/
fi
else
echo "$(date):磁盘sdc没发现">> /path/logs/mount-sdc.log
fi

mysql

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
#!/bin/bash

# Must be run as the root user
MUSER="user" # MySQL user
MHOST="localhost" # MySQL server ip
MPASS="xxxx" # MySQL password

NOW=$(date +"%d-%m-%Y")

BPATH=/path/tftp/mysql/$NOW

[ ! -d $BPATH ] && mkdir -p $BPATH

DBS="$(/usr/bin/mysql -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')"
echo $DBS #测试链接是否成功

for db in $DBS
do
FILE="${BPATH}/${db}.gz"

[ "$db" == "adserverstats" ] && continue
[ "$db" == "mint" ] && continue
/usr/bin/mysqldump --single-transaction -u $MUSER -h $MHOST -p$MPASS $db | /bin/gzip -9 > $FILE
done

sleep 2
ls -lR /path/mysql
echo "数据库已备份到$BPATH"

pgSQL

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
#!/bin/bash

LANG=zh_CN.UTF-8
export LANG

echo "备份数据库到/path/pgSQL目录..."
echo "备份选择1 取消选择 0"

select N in 备份 稍后备份
do
case $N in
备份)
echo "$(date) 备份数据库" >> ~/logs/pqSQL-backup.log 2>&1
pg_dumpall > /path/pgSQL/$(date +%Y-%m-%d) && echo "$(date) 备份完毕..." >> ~/logs/pgSQL-backup.log 2>&1
break
;;
稍后备份)
echo "$(date) 稍后备份..."
break
;;
esac
done

### 备份数据库
# pg_dumpall > /path/pgSQL/$(date +%Y-%m-%d)

ntp

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
#!/bin/sh

### 时间校对脚本 
### CentOS6.8 + openSUSE15.0 + Ubuntu

net_time_SuSE() {

zypper in -y netdate
systemctl stop ntpd.service
sleep 3
ntpdate us.pool.ntp.org && echo "$(date) verify donw ..." >> /var/log/ntp-sync.log 2>&1
systemctl start ntpd.service
date -u

}

net_time_CentOS() {

# yum install ntp ntpdate -y
/etc/init.d/ntpd stop
sleep 3
ntpdate us.pool.ntp.org && echo "$(date) verify donw ..." >> /var/log/ntp-sync.log 2>&1
/etc/init.d/ntpd start
date -u

}

net_time_Ubuntu() {

apt install -y ntpdate ntp
/etc/init.d/ntp stop
sleep 3
ntpdate us.pool.ntp.org && echo "$(date) verify donw ..." >> /var/log/ntp-sync.log 2>&1
/etc/init.d/ntp start
date -u

}

os_name=$(lsb_release -si)
os_name1=$(cat /etc/redhat-release | awk '{print $1}')
net_time_sync() {
if [ "$os_name" = "openSUSE" ];then
echo "OS is $os_name $(date) verify time now..." >> /var/log/ntp-sync.log
net_time_SuSE
elif [ "$os_name1" = "CentOS" ];then
echo "OS is $os_name1 $(date) verify time now ..." >> /var/log/ntp-sync.log
net_time_CentOS
elif [ "$os_name" = "Ubuntu" ];then
echo "OS is $os_name $(date) verify time now..." >> /var/log/ntp-sync.log
net_time_Ubuntu
fi
}


Action() {

if [ "$(whoami)" = "root" ];then
net_time_sync
else
echo "need root"
fi
}

Action

proxy

1
2
3
#!/usr/bin/env bash
export http_proxy=socks5://127.0.0.1:1080
export https_proxy=$http_proxy

备份vps

1
2
3
4
#!/bin/sh

### 备份指定目录 --delete-exclude 必须配合 --exclude=使用才行
rsync -avrz --log-file=/path/logs/tengxunyun.log --delete-excluded -e "sshpass -p aaabbbcccdde ssh -p 123456" uuu@1.4.2.3:/uuu/golang/nongli /path/nfs_share/
1
2
3
4
5
6
#!/bin/sh

echo "普通用户身份备份..."

rsync -e "ssh -p 123456" -aptgovrlHAXzP --log-file=/path/logs/rsync_vps_usr.log --delete-excluded --exclude={"/swap","/media/*","/sys/*","/proc/*","/mnt/*","/tmp/*","/dev/*","/other/*","/var/run/*","/var/tmp/*"} user@2.3.4.5:/ /path/path/data/rsync-vps-backup/

qt中文输入

1
2
3
4
#!/bin/bash
echo "以下命令解决 Qt Creator 4.2.0 (4.2.0)无法输入中文"
cd /opt/Qt/Tools/QtCreator/lib/Qt/plugins/platforminputcontexts/
sudo cp /usr/lib64/qt5/plugins/platforminputcontexts/libfcitxplatforminputcontextplugin.so .

rclone

1
2
3
4
5
6
7
8
9
10
#!/bin/sh

#为crontab添加的环境变量
# source /etc/profile
# source /path/.profile

# 使用rclone同步Documents到onedrive...
#参数说明: https://rclone.org/filtering/ https://forum.rclone.org/

/usr/bin/rclone -Luv --log-file=/path/logs/rclone_sync_Documents_to_disk.log --delete-excluded sync /path/Documents/local-disk:remoteName && echo "$(date):local-disk同步脚本运行完毕..." >> /path/logs/message-rclone.log 2>&1

rclone

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/bin/sh

# echo "导入代理环境..."
export https_proxy=socks5://127.0.0.1:1080
export http_proxy=socks5://127.0.0.1:1080

sleep 2
sudo mount /dev/sdd6 /path && echo "/dev/sdd6挂载到/path" >> /path/logs/message-rclone.log
SDD6=$(cat /proc/mounts | grep ^/dev/sdd6 | cut -b 1-9)

if [ "$SDD6" == "/dev/sdd6" ]
then
rclone -Luv --log-file=/path/logs/rclone_diskName.log --exclude MyLife/_book/** sync /path/remoteDisk: && echo "$(date):diskName同步脚本运行完毕..." >> /path/logs/message-rclone.log 2>&1
else
echo "/dev/sdd6挂载失败" >> /path/logs/message-rclone.log 2>&1
fi

sleep 10
sudo umount /dev/sdd6

rdp

1
2
3
#!/bin/bash

rdesktop -g 1440x900 -P -z -x l -r sound:off -u userName 192.168.6.104:3389

sed

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# "在文件name-only的每个行后面添加 \n"
sed -i 's/$/&\\n/g' name-only

# "在文件test-i的每个行前面面添加 find -inum"
sed -i 's/^/find -inum &/g' test-i

# 在每行的头添加字符,比如"HEAD"
sed 's/^/HEAD&/g' test.file

# 在每行的行尾添加字符,比如“TAIL”
sed 's/$/&TAIL/g' test.file

# 去除空行
# "切换到要转换的目录"
sed -i '/^\s*$/d'

sed -i '7s/\/\*//g' *.go
sed -i '12s/\*\///g' *.go

sed -i '/^$/d' *.go

heic2jpeg

heic2jpeg

1
2
3
4
5
6
7
8
9
10
#!/bin/sh

for f in `ls *.heic`
do

# echo ${f%.*} #去掉文件后缀名

heic2jpeg $f ${f%.*}.jpeg
# mv $f ${f%.*}.jpeg
done

rsync

  • 备份home

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    #!/bin/sh

    echo "......删除回收站 清理缓存......"
    sudo rm -rf $HOME/.local/share/Trash/files/*
    /bin/sh /path/bin/clean-cache-dir.sh
    #
    sudo mount /dev/sdd4 /mnt/sdd4/
    #
    sudo rsync -avR --delete-excluded /path/mnt/sdd4/ --exclude={"OSX-KVM/*","Downloads/*","vmware/","VirtualBox\ VMs/*","桌面/*",".cache/*",".nuget/*","go_work/pkg/mod/cache/","/path/.wine/*"} #> /dev/null 2>&1 &
    # -aptgovrlHAXzP
    sleep 10
    sudo umount /dev/sdd4

  • 备份 /

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    #!/bin/sh

    echo " " > /path/logs/rsync-system-backup-info.log
    echo "**********$(date)开始备份**********" >> /path/logs/rsync-system-backup-info.log 2>&1

    ### -v參數去掉 避免在/var/spool/mail/root中輸出和log file重複信息
    # -a 存档模式 等于-rlptgoD(没有-H,-A,-X);
    # -X 保留扩展属性;
    # -A 保留ACL(暗示--perms);
    # -z 在传输过程中压缩文件数据
    # -p 保留权限
    # -t 保留修改时间
    # -g 保留组
    # -o 保留所有者(仅限超级用户)
    # -r 递归目录
    # -l 将符号链接复制为符号链接
    # -H 保留硬链接
    # -z 传输过程压缩
    # -R 使用相对路径名称(从源目录的起始位置 保留路径 备份到目标目录)
    sudo mount /dev/sdd5 /mnt/sdd5/
    sudo rsync -aptgovrlHAX --delete-excluded --partial --log-file=/path/logs/rsync-system-backup.log / /mnt/sdd5/system-backup/ --exclude={"/root/.cache/*","/usr/src/*","/media/*","/sys/*","/proc/*","/mnt/*","/tmp/*","/run/*","/dev/*","/*","/var/tmp/*","/var/run/*","/var/log/*","/var/adm/*","/var/cache/*","/usr/share/doc/*","root/.npm/_cacache/*"}&& echo "**********$(date):系统备份完毕**********" >> /path/logs/rsync-system-backup-info.log 2>&1
    sleep 10
    sudo umount /dev/sdd5

shell clock

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
### http://www.bkjia.com/xtzh/647316.html

#!/bin/bash
tput civis
while [ 1 ]
do
tput clear
tput cup 3 10
tput setb 0
tput setf 2
echo $(date "+%Y--%m--%d %H:%M:%S %A")
sleep 1

done

原文如下:

#!/bin/bash
tput civis
while [ 1 ]
do
nonth=$(date +%B)
case "$nonth" in
January) nonth=1;;
February) nonth=2;;
March) nonth=3;;
April) nonth=4;;
May) nonth=5;;
June) nonth=6;;
July) nonth=7;;
August) nonth=8;;
September) nonth=9;;
October) nonth=10;;
November) nonth=11;;
December) nonth=12;;
esac
tput clear
tput cup 3 10
echo $(date +%Y)--$nonth--$(date +%d) $(date +%H):$(date +%M):$(date +%S) $(date +%A)
sleep 1

done

notifyd

1
2
### xfce4的启动通知
systemctl --user start xfce4-notifyd

history

  • 更详细的历史记录
    export HISTTIMEFORMAT=’%Y.%m.%d-%T :: ‘ HISTFILESIZE=90000 HISTSIZE=90000
1
2
3
4
5
6

history|cut -c 8-|sed 's/|/\n/g'|awk '{if ($1=="sudo") $1="";print $0}'|awk '{print $1}'|sort|uniq -c|sort -gr|awk '{if($1>=5) print$0}'

echo "参数适用于记录详细历史命令的设置 如果不是需要修改CMD[\$4]为[\$2]"

history | awk '{CMD[$4]++;count++;} END { for (a in CMD )print CMD[ a ]" " CMD[ a ]/count*100 "% " a }' | grep -v "./" | column -c3 -s " " -t |sort -nr | nl | head -n20

usbmux

1
2
3
4
#!/bin/sh

echo "Starting usbmuxd ... "
sudo /usr/local/sbin/usbmuxd --user usbmux --systemd >> /path/logs/usbmuxd.log 2>&1 &

bashrc

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
### 终端记录器并输出到指定目录
# /usr/bin/script -qa /path/logs/bash-history.log

#-设定PS1对当前登录用户环境生效
# export PS1="\w\n\d|\A >"
export PS1="\w\n\h@\u \# \A >"

# Plan9
# PLAN9=/usr/local/plan9
# export PLAN9
# PATH=$PATH:$PLAN9/bin
# export PATH

# GO环境变量()
export GOROOT=/usr/local/go
export PATH=$GOROOT/bin:$PATH
export GOPATH=$HOME/go_work
export PATH=$GOPATH/bin:$PATH
# export GOPROXY=https://goproxy.io

# GoLand
export PATH=/usr/local/GoLand/bin:$PATH


# Android Studio
export PATH=/opt/android-studio/bin:$PATH

# Android SDK
# export ANDROID_HOME=$HOME/Android/Sdk
# export PATH=$PATH:$ANDROID_HOME/tools
# export PATH=$PATH:$ANDROID_HOME/tools/bin
# export PATH=$PATH:$ANDROID_HOME/platform-tools
# export PATH=$PATH:$ANDROID_HOME/emulator
# export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

######################gioui apk
export ANDROID_SDK_ROOT=$HOME/Android/Sdk
export PATH=$PATH:$ANDROID_SDK_ROOT/tools
export PATH=$PATH:$ANDROID_SDK_ROOT/tools/bin
export PATH=$PATH:$ANDROID_SDK_ROOT/platform-tools
export PATH=$PATH:$ANDROID_SDK_ROOT/emulator
# export PATH=$PATH:/user/Android/Sdk/ndk/21.3.6528147
# export ANDROID_NDK_HOME=$ANDROID_SDK_ROOT/ndk/21.3.6528147


export PATH=/path/.local/bin:$PATH

### dotnet
export DOTNET_ROOT=$HOME/dotnet
export PATH=$PATH:$HOME/dotnet
export PATH="$PATH:/path/.dotnet/tools"


# 查看本机公网IP
alias pubip='curl ifconfig.me'
# 按照大小排序目录(仅限目录)

alias sortDirBySize='du -h --time --max-depth=1 | sort -hr '

# 只列出目录
alias listdir='find * -type d -maxdepth 0'

#找出“当前目录下”最大的5个文件
alias listFilesTop5='find . -type f -exec ls -s {} \; | sort -n -r | head -5'

# 显示可执行文件
alias showExecutable-files='ls -F | grep '*$''

# 列出tcp链接
alias listTcpLink='sudo lsof -i -n -P | grep TCP'

#把当前目录下面的GBK编码转换为UTF-8编码
alias gbk2utf-8='convmv -f GBK -t utf8 --notest -r .'

# 自定义ls ps cpu
alias l='ls -ltr'
alias pscpu='ps -e --sort=-%cpu'

#逐行显示环境变量
alias path='echo -e ${PATH//:/\\n}'

# 删除日志仅保留最近5天的内容
alias journal-rm_5daily='sudo journalctl --vacuum-time=5d'

# 更详细的历史记录
export HISTTIMEFORMAT='%Y.%m.%d-%T :: ' HISTFILESIZE=90000 HISTSIZE=90000

# unset HISTFILE
alias nongli='python3 /path/bin/nongli.py'

### dotnet自动补全 https://docs.microsoft.com/zh-cn/dotnet/core/tools/enable-tab-autocomplete
_dotnet_bash_complete()
{
local word=${COMP_WORDS[COMP_CWORD]}

local completions
completions="$(dotnet complete --position "${COMP_POINT}" "${COMP_LINE}")"

COMPREPLY=( $(compgen -W "$completions" -- "$word") )
}

complete -f -F _dotnet_bash_complete dotnet

export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"

profile

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#自定义交互式shell别名
alias l='ls -ltr'
alias ps='ps aux'
alias pscpu='ps -e --sort=-%cpu'

### rust
export PATH="$HOME/.cargo/bin:$PATH"
### 国内镜像用于更新
### 需要同步配置$HOME/.cargo/config
### https://github.com/RustChina/rust-wiki/blob/master/%E5%9B%BD%E5%86%85%E9%95%9C%E5%83%8F.page

# export RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static
# export RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup

### exercism.io
if [ -f ~/.config/exercism/exercism_completion.bash ]; then
source ~/.config/exercism/exercism_completion.bash
fi

mkswap

1
2
3
4
5
6
7
8
#Here, 1M * 2000 ~= 2GB of swap memory
dd if=/dev/zero of=swapfile bs=1M count=2000
mkswap swapfile
swapon swapfile
chmod 600 swapfile
echo "/var/_swap_/swapfile none swap sw 0 0" >> /etc/fstab
#cat /proc/meminfo
free -m

python开启网络服务

simplehttpserver

1
2
3
4
5
# 2.x
python -m SimpleHTTPServer 8000

### 3.x
python -m http.server 8000

自动登录telnet并执行命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/bin/expect --
set SERVER "192.168.1.100"
set USER "root"
set PASSWD "passwd"
if { $argc } {
spawn telnet $SERVER.$argv
} else {
spawn telnet $SERVER
}
expect "login:"
send "$USER\n"
expect "Password:"
send "$PASSWD\n"
expect "#"
send "ls -ltr\n"
interact

浏览器使用代理上网

  • 适用Linux系统

chromium.org-socks-proxy

1
2
cd /opt/google/chrome/
./google-chrome --proxy-server="socks5://127.0.0.1:1080" --host-resolver-rules="MAP* ~NOTFOUND , EXCLUDE 127.0.0.1"

推荐文章