这篇文章对Lost+found这个知识点分析得非常的透。
谢谢楼主!
下面我也转发一下另外一位大师的perl脚本,就是为了避免产生文件被误转移到Lost+found这个目录做的脚本。大家可以参考一下,提示的地方我用中文替代了,可能不是很准确,以下为代码:
****************************************************************
############################################################
#
# WARN_LOST_AND_FOUND.pl
#
# Directory uncheckouts are checked to see if the resulting
# uncheckout will send any child elements to lost+found. If
# so then any elements are listed for the user and the user
# is then given the option to continue the uncheckout or
# cancel.
#
# Note:
#
# Arguments: None
#
# Author: A Better Solution, Inc.
# email:
support@abs-consulting.com
# URL:
http://www.abs-consulting.com
# Date: Oct. 01, 2005
############################################################
# History: 10/01/2005 : Created for A Better Solution, Inc.
############################################################
############################################################
###################################
######## Site Static Data ########
###################################
$MAX_SHOW = 10;
$OS = "$ENV{'OS'}";
if ($OS =~ /[Ww]indows/)
{
$CLEARTOOL = "cleartool";
$CLEARPROMPT = "clearprompt";
}
else
{
$CLEARTOOL = "/usr/atria/bin/cleartool";
$CLEARPROMPT = "/usr/atria/bin/clearprompt";
}
#################################
######## Passed In Data ########
#################################
# NONE #
##################################
######## Calculated Data ########
##################################
$dir = $ENV{CLEARCASE_PN};
@my_children = `$CLEARTOOL ls -nxname -s -vob_only "$dir"`;
$pred_version = `$CLEARTOOL desc -fmt %PSn "$dir"`;
$pred_dir = "$dir\@\@$pred_version";
@my_preds_children = `$CLEARTOOL ls -nxname -s -vob_only "$pred_dir"`;
############################
######## Test Data ########
############################
# NONE #
#############################
######## PROCEDURES ########
#############################
# NONE #
########################
######## MAIN ########----------------------------------------------------------------
########################
@my_kids=();
@my_preds_kids=();
printf ("检查该目录下的元素... \n ($dir)\n这些元素有可能会成为孤儿被扔到lost+found中 ...");
##################################################
# Get a list of the current directories children #
##################################################
foreach $child (@my_children)
{
chomp ($child);
@components = split (/[\\\/]/, $child);
push ( @my_kids, $components[$#components]);
}
###################################################
# Get a list of the previous directories children #
###################################################
foreach $child (@my_preds_children)
{
chomp ($child);
@components = split (/[\\\/]/, $child);
push ( @my_preds_kids, $components[$#components]);
}
#################################################################
# Get a list of children added in this version of the directory #
#################################################################
@orphans_to_be = ();
foreach $child (@my_kids)
{
$found = 0;
###########################################################################
# This loop below could be replaced with $found = grep (child, @my_kids); #
# in most versions of perl, but not ccperl. #
###########################################################################
foreach $preds_child (@my_preds_kids)
{
if ($child eq $preds_child)
{ $found = 1 ; last; }
}
if ($found == 0)
{
push ( @orphans_to_be, " $child\n");
}
}
##############################
# If none found then bail OK #
##############################
if ($#orphans_to_be == -1)
{
printf (" OK,没有发现...\n");
exit 0;
}
############################################################################
# Display elements that will goto lost+found if the uncheckout is allowed. #
############################################################################
$num = $#orphans_to_be+1;
printf (" $num found...\n");
if ($num == 1)
{
$msg = "如果你不checkout该目录 ($dir)\\n那么以下元素:\\n\\n $orphans_to_be[0]\\n\\n将由于父目录不存在而被扔到lost+found中.\\n";
}
else
{
$msg = "如果你不checkout该目录那么将有 ($dir)\\n$num 元素由于父目录不存在而被扔到lost+found中.\\n它们是:\\n";
$i = 1;
################################################################
# List the more than 1 elements but show no more than MAX_SHOW #
################################################################
foreach $child (@orphans_to_be)
{
chomp ($child);
$list = $list.$child."\\n";
if ($i == $MAX_SHOW)
{ $list = $list."..."."\\n"; }
last if ($i == $MAX_SHOW);
$i++;
}
$msg = "$msg\\n$list";
}
####################################################################
# The operator has a choice to continue or not with the uncheckout #
####################################################################
$final_msg = "$msg\\n你真的希望不checkout吗?";
$rc = system ("$CLEARPROMPT yes_no -def no -mask no,yes -pre -newline -pro \"$final_msg\" ");
if ($rc == 0)
{ exit 0; }
else
{ exit 1; }
**********************************************************