A small problem occurs during U-boot development. The netizen wanglida79 met me a few days ago. I didn't simulate it at the time. now I have met myself. But I figured out a solution.
A small problem occurs during U-boot development. The netizen wanglida79 met me a few days ago. I didn't simulate it at the time. now I have met myself. However, I have come up with a solution, but the reason is not clear. maybe the method is incorrect or there may be bugs.
Symptom description:For the convenience of patch, the source code is named. orig for the development of U-boot porting. However, the name is too long and it is not convenient to operate in the command line, so the idea is to create a soft link.
- [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
The above is the main folder under the Directory, now link the source code to orig, link the development part to develop.
- [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
As shown above, if you want to delete develop and orig, an exception occurs:
- [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/
It seems that it cannot be deleted, and the same is true for deleting orig. the conversion experiment uses find to delete:
- [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
It seems to be successful.
Symptom analysis and solution:The deletion method of the find and xargs provided above can be implemented, but why can't it be deleted only by using rm? I think there should be a problem with the method used. I must check the usage of rm and ln, according to man's query, the use of ln is no problem with the use of rm, which overwrites the previous idea. I want to find the reason from the difference between rm direct deletion and find deletion.
- [Armlinux @ lqm bootloader] $ find.-type l
- ./Develop
- ./Orig
It seems that the reason is found. I always use the TAB key to complete the command when using rm, but the TAB completion command ends with a slash, rm, unlink, and cannot handle this situation well. this is a bug. I encountered this problem when I wrote a shell script to implement autozip, the awk solution is used. The original script is as follows:
- [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 implements target).tar.gz $ OPT & echo "OK"
- Elif [-f $ OPT]; then
- Get_target $ OPT
- Cp $ OPT tmp
- Gzip tmp
- Cp tmp.gz running successfully target).gz
- Rm tmp.gz
- If [-x ${target).gz]; then
- Chmod-x specify target).gz
- Fi
- Echo "OK"
- Fi
The above get_target is used to handle this situation, but it is not possible for rm to handle this situation. you must know that it is often used to improve efficiency by using the TAB key.
After finding the bug and looking at the rm source code, we can use the above script idea to solve this small bug and write a script rmlink, as shown below:
- [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
- // Test:
- [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
It can be seen that the test is normal and rmlink can be used normally. at this point, the problem is finally solved.
Appendix:Vmware crashes, causing concern about viewing disk space and file size. now we have a few frequently used commands for secondary check.
· View the file size
[Armlinux @ lqm bootloader] $ ls-hl
· If you only want to see the size but not other information, run the following command:
[Armlinux @ lqm bootloader] $ ls-hl | awk '{print $5 "t" $ NF }'
· View the space occupied by a single directory
[Armlinux @ lqm bootloader] $ du-hs u-boot-1.2.0
U-boot-1.2.0 71 M
· View the remaining disk space
[Armlinux @ lqm bootloader] $ df-hl
Options-h are available in ls and other commands. the specific meanings are the same, as shown below:
-H, -- human-readable
With-l, print sizes in human readable format (e.g., 1 K 234 M 2G)
As shown in the preceding figure, if-h is not added, the size is displayed in bytes. if-h is added, it is displayed in K or M, it is much clearer.