如何确定文件是别名还是符号链接?


13

我正在使用旧版系统,并且有一堆文件引用了其他文件夹中的图像。

lrwxrwxrwx  1 user nobody      56 Feb 10  2010 t100x100.jpg -> /home/www/virtual/categories/swm/24/m/00012/t100x100.jpg
lrwxrwxrwx  1 user nobody      56 Feb 10  2010 t100x133.jpg -> /home/www/virtual/categories/swm/24/m/00012/t100x133.jpg
lrwxrwxrwx  1 user nobody      56 Feb 10  2010 t125x150.jpg -> /home/www/virtual/categories/swm/24/m/00012/t125x150.jpg
lrwxrwxrwx  1 user nobody      56 Feb 10  2010 t150x200.jpg -> /home/www/virtual/categories/swm/24/m/00012/t150x200.jpg

我怎么知道这些是符号链接还是别名?


3
符号链接是引用另一个文件的文件条目。在Linux中,别名是命令语法的替换。别名是什么意思?还是只是问问如何识别哪些文件是符号链接?find folder -type l将在“文件夹”下列出所有符号链接。
StarNamer 2012年

您是在问Mac OS X Finder中的别名还是shell命令别名?
丹尼尔·贝克

我想我有点困惑。有问题的文件只是符号链接,我想我对Os X Finder别名感到困惑。
马丁

Answers:


16

符号链接:

lrwxrwxrwx  1 user nobody      56 Feb 10  2010 t100x100.jpg -> /home/www/virtual/categories/swm/24/m/00012/t100x100.jpg
^
 ` Here it is, l for symbolic link.

如果您的文件是硬链接,则它们会像其他文件一样显示。例如,每个目录都有一个名为.hardlink的目录。

来自$ man find

普通Unix文件系统上的每个目录至少有2个硬链接:名称和.' entry. Additionally, its subdirectories (if any) each have a链接到该目录的..'条目。

硬链接:

-rw-r--r--  3 root root   60 2012-06-25 12:17 File
-rw-r--r--  3 root root   60 2012-06-25 12:17 HardLinkToFile
-rw-r--r--  3 root root   60 2012-06-25 12:17 HardLinkToFile2
lrwxrwxrwx  1 user nobody      56 Feb 10  2010 t100x100.jpg -> /home/www/virtual/categories/swm/24/m/00012/t100x100.jpg
            ^
             ` This number is hard link (reference) count.

11

filestat命令会告诉你一个文件是什么:

$ ln -s /home this_is_a_link
$ touch this_is_not_a_link
$ file this_*
this_is_a_link:     symbolic link to `/home'
this_is_not_a_link: empty
$ stat this_*
  File: `this_is_a_link' -> `/home'
  Size: 5               Blocks: 0          IO Block: 4096   symbolic link
Device: ca00h/51712d    Inode: 106983      Links: 1
Access: (0777/lrwxrwxrwx)  Uid: ( 1000/    andy)   Gid: ( 1000/    andy)
Access: 2012-07-29 23:28:17.000000000 +0000
Modify: 2012-07-29 23:28:17.000000000 +0000
Change: 2012-07-29 23:28:17.000000000 +0000
  File: `this_is_not_a_link'
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: ca00h/51712d    Inode: 106992      Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/    andy)   Gid: ( 1000/    andy)
Access: 2012-07-29 23:28:27.000000000 +0000
Modify: 2012-07-29 23:28:27.000000000 +0000
Change: 2012-07-29 23:28:27.000000000 +0000

如果编写脚本,则该test命令可能更有用:

   -h FILE
         FILE exists and is a symbolic link (same as -L)
$ for f in this_*; do if test -h "$f"; then echo "$f is a symlink"; else echo "$f is not a symlink"; fi; done
this_is_a_link is a symlink
this_is_not_a_link is not a symlink
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.