sh 从Linux桌面备份和还原个人文件

backup.sh
#!/bin/bash

echo -n "Starting backup... Are you sure ? y/(n) " ; read response
test ${response:-n} != "y" && exit 1

dotfiles=$(dirname $0)/dotfiles.txt
destination=$(dirname $0)/home

# create dotfiles archives or append new files to it
tar -czf $HOME/dotfiles.tar.gz -C $HOME --files-from=$dotfiles
rsync -av $HOME/dotfiles.tar.gz "$destination"

# retrieve all visible directories and dotfiles archives
dir_options="-mindepth 1 -maxdepth 1 -type d"
while IFS= read -r -d '' directory ; do
  (
    # ignore git subfolders
    find $directory -type d -name .git -exec dirname {} \; | sed -e "s;$HOME/;;" -e 's;$;/*;'
    # ignore large files  
    find $directory -type f -size +200M | sed -e "s;$HOME/;;" 
  ) > $HOME/.exclude
  test -s $HOME/.exclude && excludefrom="--exclude-from=$HOME/.exclude"
  
  rsync $excludefrom -av "$directory" "$destination"
  unset excludefrom
done < <(find $HOME $dir_options -name "[^.]*" -print0)

echo -n "Backup done. Press a key..." ; read
restore.sh
#! /bin/bash

### Restore commands
cd /run/media/$(whoami)/*
tar -xf home/dotfiles.tar.gz -C $HOME
rsync --exclude=dotfiles.tar.gz -av home/ $HOME
chown -R $(whoami): $HOME

### Software install
# sudo pacman -Syu
# sudo pacman -Sy firefox thunderbird keepassxc autorandr libvirt virt-manager
# pamac build dino spotify-dev

sh [copy rsa] copy rsa key#rsa#id_rsa.pub

[copy rsa] copy rsa key#rsa#id_rsa.pub

cp_id_rsa.pub_.sh
pbcopy < ~/.ssh/id_rsa.pub

sh S3上传

s3-upload.sh
file=
region=ap-southeast-1
bucket=
resource="/${bucket}/${file}"
contentType="application/zip"
dateValue=`date -R`
stringToSign="PUT\n\n${contentType}\n${dateValue}\n${resource}"
s3Key=
s3Secret=
signature=`echo -en ${stringToSign} | openssl sha1 -hmac ${s3Secret} -binary | base64`
curl -X PUT -T "${file}" \
  -H "Host: ${bucket}.s3.amazonaws.com" \
  -H "Date: ${dateValue}" \
  -H "Content-Type: ${contentType}" \
  -H "Authorization: AWS ${s3Key}:${signature}" \
  https://${bucket}.s3-${region}.amazonaws.com/${file}
$SHELL

sh Cassandra docker Cluster用于测试

cassCluster
docker run --name boston -p 9044:9042 -e CASSANDRA_CLUSTER_NAME=myCluster -e CASSANDRA_ENDPOINT_SNITCH=GossipingPropertyFileSnitch -e CASSANDRA_DC=datacenter1 -d cassandra

docker inspect --format='{{ .NetworkSettings.IPAddress }}' boston

docker run --name newyork -e CASSANDRA_SEEDS="$(docker inspect --format='{{ .NetworkSettings.IPAddress }}' boston)" -e CASSANDRA_CLUSTER_NAME=myCluster -e CASSANDRA_ENDPOINT_SNITCH=GossipingPropertyFileSnitch -e CASSANDRA_DC=datacenter2 -d cassandra

sh 重新启动NetworkManager

restart_NetworkManager
systemctl restart NetworkManager.service

sh 如何在本地和远程删除git标记

如何在本地和远程删除git标记

git-tag-delete-local-and-remote.sh
# delete local tag '12345'
git tag -d 12345
# delete remote tag '12345' (eg, GitHub version too)
git push origin :refs/tags/12345
# alternative approach
git push --delete origin tagName
git tag -d tagName

sh 根据目录在unix中报告空间

很容易检查分区与填充

report_space.sh
sudo du -hsx /* | sort -rh | head -n 40

# https://askubuntu.com/questions/266825/what-do-i-do-when-my-root-filesystem-is-full

# For boot partition
https://askubuntu.com/questions/345588/what-is-the-safest-way-to-clean-up-boot-partition#answer-430944

sh 更改远程网址

changing_a_remote_url.sh
git remote -v
#origin  https://github.com/USERNAME/REPOSITORY.git (fetch)
#origin  https://github.com/USERNAME/REPOSITORY.git (push)

git remote set-url origin git@github.com:USERNAME/REPOSITORY.git

git remote -v
# Verify new remote URL
#origin  git@github.com:USERNAME/REPOSITORY.git (fetch)
#origin  git@github.com:USERNAME/REPOSITORY.git (push)

sh Bash日期

来自:https://stackoverflow.com/a/15374813/5627904

date.bash
date -d "yesterday 13:00" '+%Y-%m-%d'

echo $(date -d "yesterday 13:00" +%Y_%m_%d)

sh 递归的sed

r-sed.sh
find . -type f -print0 | xargs -0 sed -i "s#TO_FIND#TO_REPLACE#g"