Linux下链接文件使用RM无法删除的解决办法
在进行U-boot开发的时候,遇到一个小问题。网友wanglida79前几天刚遇到过,我当时没有模拟出来,现在自己倒是遇上了。不过我想出了解决的办法,只不过原因不明确,或许使用方法不对,或许有bug。 现象描述: 我进行U-boot移植的开发,为了patch方便,将源码的名字命名为.orig,这样以示区分。但是名字太长,在命令行下操作不太方便,所以想法就是建立软链接。
[armlinux@lqm bootloader]$ tree -L 1
.
|-- patch
|-- u-boot-1.1.3
|-- u-boot-1.2.0
|-- u-boot-1.2.0.orig
|-- vivi
`-- vivi_origin
6 directories, 0 files
[armlinux@lqm bootloader]$ ln -s u-boot-1.2.0.orig/ orig
[armlinux@lqm bootloader]$ ln -s u-boot-1.2.0 develop
[armlinux@lqm bootloader]$ ls
develop orig patch u-boot-1.1.3 u-boot-1.2.0 u-boot-1.2.0.orig vivi vivi_origin
[armlinux@lqm bootloader]$ rm develop/
rm: cannot remove `develop/': Not a directory
[armlinux@lqm bootloader]$ rm -f develop/
rm: cannot remove `develop/': Not a directory
[armlinux@lqm bootloader]$ unlink develop/
unlink: cannot unlink `develop/
[armlinux@lqm bootloader]$ find . -type l | xargs rm -f
[armlinux@lqm bootloader]$ ls
patch u-boot-1.1.3 u-boot-1.2.0 u-boot-1.2.0.orig vivi vivi_origin
[armlinux@lqm bootloader]$ find . -type l
./develop
./orig
[armlinux@lqm bin]$ cat autozip
#!/bin/bash
# Copyright 2007 (c), Shandong University
# All rights reserved.
#
# Filename : autozip
# Description: Compress files, and print "OK" out if the file
# can be compressed successfully.
# Syntax : autozip [filename | directory name]
# Author : Liu Qingmin
# Version : 1.0
# Date : 07-04-29
#
# Func: get_target()
# Desc: Obtain the name of target file
# Para: $1 -- file name that will be compressed
# Ret : TARGET -- current file name
get_target()
{
TARGET=`echo $1 | /
awk -F/ '{if ($NF == "") print $(NF-1); /
else print $(NF)}'`
}
# Handle Parameters
if [ $# != 1 ];then
echo "Usage: `basename $0`
exit 1
fi
# Assign the parameter to the Macro OPT
OPT=$1
# Uncompress files
if [ -d $OPT ]; then
get_target $OPT
tar zcvf ${TARGET}.tar.gz $OPT && echo "OK"
elif [ -f $OPT ]; then
get_target $OPT
cp $OPT tmp
gzip tmp
cp tmp.gz ${TARGET}.gz
rm tmp.gz
if [ -x ${TARGET}.gz ]; then
chmod -x ${TARGET}.gz
fi
echo "OK"
fi
[armlinux@lqm bin]$ cat rmlink
#!/bin/sh
# Copyright 2007 (c), Shandong University
# All rights reserved.
#
# Filename : rmlink
# Description : solve the bug of "rm" and "unlink"
# Syntax : rmlink
# Author : Liu Qingmin
# Version : 1.0
# Date : 07-09-19
#
# Func: get_target()
# Desc: Obtain the name of target file
# Para: $1 -- file name that will be compressed
# Ret : TARGET -- current file name
get_target()
{
TARGET=`echo $1 | /
awk -F/ '{if ($NF == "") print $(NF-1); /
else print $(NF)}'`
}
# Handle Parameters
if [ $# != 1 ];then
echo "Usage: `basename $0`
exit 1
fi
# Assign the parameter to the Macro OPT
OPT=$1
# Uncompress files
if [ -d $OPT ]; then
# eliminate the "/" at the ending
get_target $OPT
# you also can use "unlink" instead of "rm"
rm ${TARGET}
fi
# OK
exit 0
[armlinux@lqm bootloader]$ ls
develop orig patch u-boot-1.1.3 u-boot-1.2.0 u-boot-1.2.0.orig vivi vivi_origin
[armlinux@lqm bootloader]$ rmlink develop
[armlinux@lqm bootloader]$ rmlink orig
[armlinux@lqm bootloader]$ ls
patch u-boot-1.1.3 u-boot-1.2.0 u-boot-1.2.0.orig vivi vivi_origin
[armlinux@lqm bootloader]$ ls -hl
[armlinux@lqm bootloader]$ ls -hl | awk '{print $5 "/t" $NF}'
[armlinux@lqm bootloader]$ du -hs u-boot-1.2.0
71M u-boot-1.2.0
[armlinux@lqm bootloader]$ df -hl
-h, --human-readable
with -l, print sizes in human readable format (e.g., 1K 234M 2G)
(责任编辑:云子)