Determine if the file location is an alias in bash scripts

Symbols are different from aliases, although they seem to serve the same purpose (more or less / I think). I need to determine if the file is an alias, and

if [ -h /path/to/file ]

does not work. Is there something similar for aliases? Google was the most useless as aliases appear to be the name of something else in bash in general.

Thank!

0
source share
2 answers

Finder stores information that the file is an alias in the ResourceFork file. To read this metadata, I would use spotlight to determine the type of file; the following command will return the file type, so you can compare it in an if-statement.

 mdls -raw -name kMDItemKind /path/to/test.pdf          returns  PDF (Portable Document Format)
 mdls -raw -name kMDItemKind /path/to/test.pdf\ Alias   returns  Alias

Applescript, osascript. , :

tell application "Finder" to get kind of ((POSIX file "/path/to/test.pdf\ Alias") as alias)
+3

, :

  • aliases ( - )
  • symlink ( )
  • ( , )

, :

if [ -h /path/to/file ]

, , :

$ touch newfile
$ ln -s newfile newlink
$ for f in newfile newlink; do
    if [ -h "$f" ]; then
        echo "$f is a symlink"
    else
        echo "$f is not a symlink"
    fi
done
newfile is not a symlink
newlink is a symlink

: " , - ", type alias, .

$ type ls
ls is aliased to `ls --color=auto --format=across'

$ type less
less is /usr/bin/less

, find -inum ls -i , .

0

Source: https://habr.com/ru/post/1793995/


All Articles