Blogs

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

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

我们用“&”把进程放入后台以后,如果需要了解进程的执行情况,可以使用wait函数。默认情况下wait会等待任意子进程结束但是不会返回子进程的返回值。而以子进程的pid作为参数调用wait时,wait便能够返回该子进程的退出状态了。具体操作如下:

#!/bin/bash
command1 &
command2 &
command3 &
for pid in $(jobs -p)
do
  wait $pid
  [ "x$?" == "x0" ] && ((count++))
done

这里我们借助了“jobs -p“来获得所有后台进程的pid。

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