mirror of https://github.com/tLDP/LDP
46 lines
1.3 KiB
Bash
46 lines
1.3 KiB
Bash
#!/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 links
|
|
do
|
|
echo "$file"
|
|
done | sort # Otherwise file list is unsorted.
|
|
|
|
# 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=$IFS
|
|
IFS=:
|
|
|
|
for file in $(find $directory -type l -printf "%p$IFS")
|
|
do # ^^^^^^^^^^^^^^^^
|
|
echo "$file"
|
|
done|sort
|