Skip to content

Instantly share code, notes, and snippets.

@shellexy
Created July 23, 2013 10:14
Show Gist options
  • Save shellexy/6061351 to your computer and use it in GitHub Desktop.
Save shellexy/6061351 to your computer and use it in GitHub Desktop.
RT @o_lll 给大家讲个笑话,有个 ~ 的目录于是想都没想就 rm -rf ~ 了。。。 13:09:10 发自: Echofon
#!/bin/bash
# 防止删除过浅目录(浅的可能比较重要
args=()
for i in "$@"
do
fn=$(readlink -m -- "$i" 2>/dev/null)
[ -z "${fn##/*/*/*/*}" -o ! -a "$fn" ] && args=("${args[@]}" "$i")
done
/bin/rm "${args[@]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment