Skip to content

Instantly share code, notes, and snippets.

@light0x00
Last active February 28, 2020 07:39
Show Gist options
  • Save light0x00/a882c298b379b5aa53d0d4ddfb004509 to your computer and use it in GitHub Desktop.
Save light0x00/a882c298b379b5aa53d0d4ddfb004509 to your computer and use it in GitHub Desktop.
shell 备忘

移除除指定文件外的文件

ls | grep -v logs | xargs rm -rf

模糊匹配的方式批量终止进程

# the match keyword to match processs which need be killed
keyword='ssh-agent'
IFS_OLD=$IFS
IFS=$'\n'
for pid in $(ps -e | grep $keyword | awk '{print $1}')
do
    if ps -f $pid &> /dev/null ; then
        echo "kill $pid"
        kill $pid
    fi
done
IFS=$IFS_OLD

查看目录下的文件全路径

ls | gawk '{ "pwd" | getline dir;  print dir"/"$0  }'

移除所有容器

docker container ls -a | gawk 'NR>1 {printf " " $1}' | xargs docker container rm

移除所有没有tag (<none>) 的image

docker images | gawk 'BEGIN{FS=" "; } NR>1 {if($1=="<none>") {print $3}}' | xargs docker image rm

git add ignore everything except a few files

//it will execlue src and test,and add other files
git add ':!src' ':!test' 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment