Solution to the problem that RM cannot be deleted in Linux-Linux general technology-Linux programming and kernel information. For details, refer to the following section. 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. 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.
Symptom Analysis and Solution:
The preceding find and xargs deletion methods can be implemented. But why can't I delete it with only rm. I think there is a problem with the method used. Check the usage of rm and ln. The use of ln and rm are correct after man's check. I tried to find out the reason from the difference between rm direct deletion and find deletion.
[Armlinux @ lqm bootloader] $ find.-type l
./Develop
./Orig
It seems that the cause is found. I always use the TAB key to complete the command when using rm, but the TAB completion command ends. The obvious reason is that rm or unlink cannot handle this situation well. This is a bug. When I wrote a shell script to implement autozip, I encountered this problem and used awk to solve it. 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. However, rm cannot handle this situation without thinking about it. You must know that using the TAB key to improve efficiency is a frequently used method.
After finding the bug and looking at the source code of rm, we can use the above script to solve this small bug. A script named rmlink is written as follows:
[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
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.