sh 增加inotify观察者的数量

script.sh
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

sh Ledger Nano S udev贴片

Ledger Nano S udev贴片

README.md
Appends `, MODE="0660", GROUP="plugdev"` to the subsystem udev rules from [github/LedgerHQ/udev-rules](https://github.com/LedgerHQ/udev-rules).

Solution found at [github/LedgerHQ/udev-rules/issues/#4](https://github.com/LedgerHQ/udev-rules/issues/4#issuecomment-511144888).
update-ledger-udev.sh
cat <<EOF > /etc/udev/rules.d/20-hw1.rules
# HW.1 / Nano
SUBSYSTEMS=="usb", ATTRS{idVendor}=="2581", ATTRS{idProduct}=="1b7c|2b7c|3b7c|4b7c", TAG+="uaccess", TAG+="udev-acl"
# Blue
SUBSYSTEMS=="usb", ATTRS{idVendor}=="2c97", ATTRS{idProduct}=="0000|0000|0001|0002|0003|0004|0005|0006|0007|0008|0009|000a|000b|000c|000d|000e|000f|0010|0011|0012|0013|0014|0015|0016|0017|0018|0019|001a|001b|001c|001d|001e|001f", TAG+="uaccess", TAG+="udev-acl", MODE="0660", GROUP="plugdev"
# Nano S
SUBSYSTEMS=="usb", ATTRS{idVendor}=="2c97", ATTRS{idProduct}=="0001|1000|1001|1002|1003|1004|1005|1006|1007|1008|1009|100a|100b|100c|100d|100e|100f|1010|1011|1012|1013|1014|1015|1016|1017|1018|1019|101a|101b|101c|101d|101e|101f", TAG+="uaccess", TAG+="udev-acl", MODE="0660", GROUP="plugdev"
# Aramis
SUBSYSTEMS=="usb", ATTRS{idVendor}=="2c97", ATTRS{idProduct}=="0002|2000|2001|2002|2003|2004|2005|2006|2007|2008|2009|200a|200b|200c|200d|200e|200f|2010|2011|2012|2013|2014|2015|2016|2017|2018|2019|201a|201b|201c|201d|201e|201f", TAG+="uaccess", TAG+="udev-acl", MODE="0660", GROUP="plugdev"
# HW2
SUBSYSTEMS=="usb", ATTRS{idVendor}=="2c97", ATTRS{idProduct}=="0003|3000|3001|3002|3003|3004|3005|3006|3007|3008|3009|300a|300b|300c|300d|300e|300f|3010|3011|3012|3013|3014|3015|3016|3017|3018|3019|301a|301b|301c|301d|301e|301f", TAG+="uaccess", TAG+="udev-acl", MODE="0660", GROUP="plugdev"
# Nano X
SUBSYSTEMS=="usb", ATTRS{idVendor}=="2c97", ATTRS{idProduct}=="0004|4000|4001|4002|4003|4004|4005|4006|4007|4008|4009|400a|400b|400c|400d|400e|400f|4010|4011|4012|4013|4014|4015|4016|4017|4018|4019|401a|401b|401c|401d|401e|401f", TAG+="uaccess", TAG+="udev-acl", MODE="0660", GROUP="plugdev"
EOF

udevadm trigger
udevadm control --reload-rules

sh Docker构建和部署

build_dockerfile.sh
docker build -t nameofimage .
docker_run.sh
docker run -d -p 80:80 --name container_name nameofimage

sh 远程运行linux bash命令

run_command.sh
ssh username@hostname command

sh 哦,我的zsh

.zshrc
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH

# Path to your oh-my-zsh installation.
export ZSH=/Users/$USER/.oh-my-zsh

# Set name of the theme to load. Optionally, if you set this to "random"
# it'll load a random theme each time that oh-my-zsh is loaded.
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
ZSH_THEME="robbyrussell"

# Set list of themes to load
# Setting this variable when ZSH_THEME=random
# cause zsh load theme from this variable instead of
# looking in ~/.oh-my-zsh/themes/
# An empty array have no effect
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )

# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"

# Uncomment the following line to use hyphen-insensitive completion. Case
# sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"

# Uncomment the following line to disable bi-weekly auto-update checks.
# DISABLE_AUTO_UPDATE="true"

# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13

# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"

# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"

# Uncomment the following line to enable command auto-correction.
#ENABLE_CORRECTION="true"

# Uncomment the following line to display red dots whilst waiting for completion.
COMPLETION_WAITING_DOTS="true"

# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"

# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# The optional three formats: "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# HIST_STAMPS="mm/dd/yyyy"

# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder

# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(vi-mode docker jump osx git github svn history-substring-search)

source $ZSH/oh-my-zsh.sh

# User configuration

# export MANPATH="/usr/local/man:$MANPATH"

# You may need to manually set your language environment
# export LANG=en_US.UTF-8

# Preferred editor for local and remote sessions
if [[ -n $SSH_CONNECTION ]]; then
 export EDITOR='vim'
else
 export EDITOR='vim'
fi

# Compilation flags
# export ARCHFLAGS="-arch x86_64"

# ssh
# export SSH_KEY_PATH="~/.ssh/rsa_id"

# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"

# Get the .bashrc
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi

# Get the .bash_profile
if [ -f ~/.bash_profile ]; then
    . ~/.bash_profile
fi

# Get the .bash_aliases
if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

# Updates editor information when the keymap changes.
function zle-keymap-select() {
  zle reset-prompt
  zle -R
}

zle -N zle-keymap-select

function vi_mode_prompt_info() {
  echo "${${KEYMAP/vicmd/[% NORMAL]%}/(main|viins)/[% INSERT]%}"
}

# define right prompt, regardless of whether the theme defined it
RPS1='$(vi_mode_prompt_info)'
RPS2=$RPS1

bindkey '^K' history-substring-search-up
bindkey '^J' history-substring-search-down

sh MySQL CLI Snippets

// Casey Lee <br/> <br/>用于处理MySQL数据库的一些有用的片段。

mysql-utils
# Export and gzip a MySQL Database
mysqldump -u username -p databasename | gzip > databasename.filename.sql.gz

# Import a gzipped MySQL Database
gunzip < databasename.filename.sql.gz | mysql -u username -p databasename

# Export a WordPress database in compatibility mode
wp db export --compatible=mysql40,no_table_options

# Create a database
CREATE DATABASE db_name;
CREATE USER 'db_user'@localhost IDENTIFIED BY 'xxPASSWORDxx';
GRANT ALL PRIVILEGES ON db_name.* TO 'db_user'@localhost;
flush privileges;

sh 文件传输

// Casey Lee <br/> <br/>用于跨服务器移动文件的CLI命令。

file-utils
# Copy a file from remote server (infodev) to local machine
scp infodev:/var/www/infomedia-dev.com/subdomains/CLIENTFOLDER/public_html/FILENAME.txt /Sites/CLIENTFOLDER.dev/public_html

# Copy a file from local machine to remote server (infodev)
scp /Sites/CLIENTFOLDER.dev/public_html/FILENAME.txt infodev:/var/www/infomedia-dev.com/subdomains/CLIENTFOLDER/public_html


#===========================================================================

# Use rsync to syncronize local and staging environment user uploads
# Usage: rsync [options] [source] [destination]
 
# -c, --checksum              skip based on checksum, not mod-time & size
# -h, --human-readable        output numbers in a human-readable format
# -a, --archive               archive mode; equals -rlptgoD (no -H,-A,-X)
# -v, --verbose               increase verbosity
# -z, --compress              compress file data during the transfer
# -P                          output a change-summary for all updates
#
# To ignore permissions use flags: --no-perms --no-owner --no-group

#===========================================================================


# Rsync ⇣ DOWN remote directory (infodev) to local directory (wp-content/uploads)
rsync -chavzP --stats "infodev:/var/www/infomedia-dev.com/subdomains/CLIENTFOLDER/public_html/wp-content/uploads/*" /Sites/CLIENTFOLDER/public_html/wp-content/uploads

# Rsync ⇡ UP local directory to remote directory (infodev)
rsync -chavzP --stats "/Sites/CLIENTFOLDER/public_html/wp-content/uploads/*" infodev:/var/www/infomedia-dev.com/subdomains/CLIENTFOLDER/public_html/wp-content/uploads

sh 找到CPU /内存的顶级进程

top_cpu_memory_processes.sh
# sorted by memory
ps -c -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head

# sorted by cpu
ps -c -eo pid,ppid,cmd,%mem,%cpu --sort=-%cpu | head

# memory in KiB
ps -c -eo cmd,vsz --sort=-vsz | head

sh 确保ssh-agent正在运行并且您设置了正确的env变量(如果可能,请重新使用)

要使用,请从shell rc文件(bashrc,zshrc等)“获取”它

ensure-ssh-agent.sh
AGENT_SCRIPT=${HOME}/load-agent.sh

while true; do
    [ -r ${AGENT_SCRIPT} ] && source ${AGENT_SCRIPT}
    if [ -n "$SSH_AGENT_PID" ]; then 
        # ensure the variable actually reflects a running ssh-agent process
        ps -p $SSH_AGENT_PID | grep -q ssh-agent$ && break
    fi
    # SSH_AGENT_PID is either not set or has stale PID
    echo "Running ssh-agent"
    ssh-agent > ${AGENT_SCRIPT}
    sleep 1
done

sh 根据文件名获取文件的类型(文件后缀)

根据文件名获取文件的类型(文件后缀)

get_file_type.sh
FILE_PATH="/root/download/test.pdf"
echo "${FILE_PATH##*.}"