运维

如果我们运行下面的语句,并且源文件不存在。

ln -sf not_exists symbol_link
readlink -f symbol_link

在RHEL4上的readlink不会打印任何输出,而在RHEL5上readlink会在标准输出打印not_exists的路径。这两个系统上readlink的版本分别是:

  • RHEL4: readlink (coreutils) 5.2.1
  • RHEL5: readlink (GNU coreutils) 5.97
No votes yet

阅读find命令的手册,在描述“-type l”的章节里发现了这样一段话

symbolic link; this is never true if the -L option or the -follow option is in effect, unless the symbolic link is broken. If you want to search for symbolic links when -L is in effect, use -xtype.

这段话说明,当“-L”打开后只有当符号链接损坏时“-type l”才会返回真。我们可以利用这个特性来寻找损坏的符号链接。例如:

find -L . -type l # 查找所有损坏的符号链接
find -L . -type l -exec rm -rf {} \; # 删除损坏的符号链接

No votes yet

mac-gen

#!/bin/sh
exec 2>/dev/null
dd if=/dev/urandom bs=1 count=6 | od -t x1 | sed ’2d;s/^0\+ //;s/ /:/g’

运行效果

dell:/etc/xen $ mac-gen
e2:5b:d2:7c:08:d3

No votes yet