⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 symlinks.sh

📁 Shall高级编程
💻 SH
字号:
#!/bin/bash# symlinks.sh: Lists symbolic links in a directory.directory=${1-`pwd`}#  Defaults to current working directory,#+ if not otherwise specified.#  Equivalent to code block below.# ----------------------------------------------------------# ARGS=1                 # Expect one command-line argument.## if [ $# -ne "$ARGS" ]  # If not 1 arg...# then#   directory=`pwd`      # current working directory# else#   directory=$1# fi# ----------------------------------------------------------echo "symbolic links in directory \"$directory\""for file in "$( find $directory -type l )"   # -type l = symbolic linksdo  echo "$file"done | sort                                  # Otherwise file list is unsorted.#  Strictly speaking, a loop isn't really necessary here,#+ since the output of the "find" command is expanded into a single word.#  However, it's easy to understand and illustrative this way.#  As Dominik 'Aeneas' Schnitzer points out,#+ failing to quote  $( find $directory -type l )#+ will choke on filenames with embedded whitespace.#  Even this will only pick up the first field of each argument.exit 0# --------------------------------------------------------# Jean Helou proposes the following alternative:echo "symbolic links in directory \"$directory\""# Backup of the current IFS. One can never be too cautious.OLDIFS=$IFSIFS=:for file in $(find $directory -type l -printf "%p$IFS")do     #                              ^^^^^^^^^^^^^^^^       echo "$file"       done|sort# And, James "Mike" Conley suggests modifying Helou's code thusly:OLDIFS=$IFSIFS='' # Null IFS means no word breaksfor file in $( find $directory -type l )do  echo $file  done | sort#  This works in the "pathological" case of a directory name having#+ an embedded colon.#  "This also fixes the pathological case of the directory name having#+  a colon (or space in earlier example) as well."

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -