在進行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 <linkfile name>
# 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,在ls等等的命令中都有,具體的含義是一致的,如下:-h, --human-readable
with -l, print sizes in human readable format (e.g., 1K 234M 2G)