国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Linux > 正文

Linux下鏈接文件使用RM無法刪除的解決辦法

2024-08-27 23:57:42
字體:
供稿:網(wǎng)友

在進行U-boot開發(fā)的時候,遇到一個小問題。網(wǎng)友wanglida79前幾天剛遇到過,我當(dāng)時沒有模擬出來,現(xiàn)在自己倒是遇上了。不過我想出了解決的辦法,只不過原因不明確,或許使用方法不對,或許有bug。 

現(xiàn)象描述:進行U-boot移植的開發(fā),為了patch方便,將源碼的名字命名為.orig,這樣以示區(qū)分。但是名字太長,在命令行下操作不太方便,所以想法就是建立軟鏈接。

  1. [armlinux@lqm bootloader]$ tree -L 1 
  2. |-- patch 
  3. |-- u-boot-1.1.3 
  4. |-- u-boot-1.2.0 
  5. |-- u-boot-1.2.0.orig 
  6. |-- vivi 
  7. `-- vivi_origin 
  8. 6 directories, 0 files 

上面是目錄下的主要文件夾,現(xiàn)在將源碼鏈接為orig,將開發(fā)部分鏈接為develop。

  1. [armlinux@lqm bootloader]$ ln -s u-boot-1.2.0.orig/ orig 
  2. [armlinux@lqm bootloader]$ ln -s u-boot-1.2.0 develop 
  3. [armlinux@lqm bootloader]$ ls 
  4. develop orig patch u-boot-1.1.3 u-boot-1.2.0 u-boot-1.2.0.orig vivi vivi_origin 

如上,現(xiàn)在想要刪除develop和orig,出現(xiàn)意外情況:

  1. [armlinux@lqm bootloader]$ rm develop/ 
  2. rm: cannot remove `develop/': Not a directory 
  3. [armlinux@lqm bootloader]$ rm -f develop/ 
  4. rm: cannot remove `develop/': Not a directory 
  5. [armlinux@lqm bootloader]$ unlink develop/ 
  6. unlink: cannot unlink `develop/ 

看來刪不掉,刪除orig也同樣如此,轉(zhuǎn)念又實驗了利用find來刪除:

  1. [armlinux@lqm bootloader]$ find . -type l | xargs rm -f 
  2. [armlinux@lqm bootloader]$ ls 
  3. patch u-boot-1.1.3 u-boot-1.2.0 u-boot-1.2.0.orig vivi vivi_origin 

看來能夠成功。

現(xiàn)象分析與解決:上面提供的find and xargs的刪除方法可以實現(xiàn),但是只用rm為什么不能刪除呢,我想應(yīng)該是使用的方法上有問題,必須查閱rm和ln的用法,經(jīng)過man查閱,ln的使用和rm的使用并沒有問題,推翻了前面的想法,我想從rm直接刪除和find刪除的不同入手找到原因。

  1. [armlinux@lqm bootloader]$ find . -type l 
  2. ./develop 
  3. ./orig 

看來原因找到了,我在使用rm的時候總是習(xí)慣使用TAB鍵補全命令,但是TAB補全命令的時候,最后是以“/”結(jié)尾的,很明顯的原因,rm也好,unlink也好,并不能很好的處理這種情況,這算是一處bug,我在前面寫shell腳本來實現(xiàn)autozip時的時候,自己遇到過這個問題,采用了awk解決,原有的腳本如下:

  1. [armlinux@lqm bin]$ cat autozip 
  2. #!/bin/bash 
  3. # Copyright 2007 (c), Shandong University 
  4. # All rights reserved. 
  5. # 
  6. # Filename : autozip 
  7. # Description: Compress files, and print "OK" out if the file 
  8. # can be compressed successfully. 
  9. # Syntax : autozip [filename | directory name] 
  10. # Author : Liu Qingmin 
  11. # Version : 1.0 
  12. # Date : 07-04-29 
  13. # 
  14. # Func: get_target() 
  15. # Desc: Obtain the name of target file 
  16. # Para: $1 -- file name that will be compressed 
  17. # Ret : TARGET -- current file name  
  18. get_target()  
  19. TARGET=`echo $1 |  
  20. awk -F/ '{if ($NF == "") print $(NF-1);  
  21. else print $(NF)}'` 
  22. # Handle Parameters 
  23. if [ $# != 1 ];then 
  24. echo "Usage: `basename $0` " 
  25. exit 1 
  26. fi 
  27. # Assign the parameter to the Macro OPT 
  28. OPT=$1 
  29. # Uncompress files 
  30. if [ -d $OPT ]; then 
  31. get_target $OPT 
  32. tar zcvf ${TARGET}.tar.gz $OPT && echo "OK" 
  33. elif [ -f $OPT ]; then 
  34. get_target $OPT 
  35. cp $OPT tmp 
  36. gzip tmp 
  37. cp tmp.gz ${TARGET}.gz 
  38. rm tmp.gz 
  39. if [ -x ${TARGET}.gz ]; then  
  40. chmod -x ${TARGET}.gz 
  41. fi 
  42. echo "OK" 
  43. fi 

上面的get_target就是對這個情況的處理,不過沒有想到rm也無法處理這種情況,要知道,使用TAB鍵提高效率是經(jīng)常用的手段啊。

找到了bug,還沒有看rm的源代碼,倒是可以利用上面的腳本的思路來解決這個小bug,寫了一個腳本rmlink,如下:

  1. [armlinux@lqm bin]$ cat rmlink 
  2. #!/bin/sh 
  3. # Copyright 2007 (c), Shandong University 
  4. # All rights reserved. 
  5. # Filename : rmlink 
  6. # Description : solve the bug of "rm" and "unlink" 
  7. # Syntax : rmlink <linkfile name> 
  8. # Author : Liu Qingmin 
  9. # Version : 1.0 
  10. # Date : 07-09-19 
  11. # Func: get_target() 
  12. # Desc: Obtain the name of target file 
  13. # Para: $1 -- file name that will be compressed 
  14. # Ret : TARGET -- current file name  
  15. get_target()  
  16. TARGET=`echo $1 |  
  17. awk -F/ '{if ($NF == "") print $(NF-1);  
  18. else print $(NF)}'` 
  19. # Handle Parameters 
  20. if [ $# != 1 ];then 
  21. echo "Usage: `basename $0` " 
  22. exit 1 
  23. fi 
  24. # Assign the parameter to the Macro OPT 
  25. OPT=$1 
  26. # Uncompress files 
  27. if [ -d $OPT ]; then 
  28. # eliminate the "/" at the ending 
  29. get_target $OPT 
  30. # you also can use "unlink" instead of "rm" 
  31. rm ${TARGET} 
  32. fi 
  33. # OK 
  34. exit 0 
  35. //測試: 
  36. [armlinux@lqm bootloader]$ ls 
  37. develop orig patch u-boot-1.1.3 u-boot-1.2.0 u-boot-1.2.0.orig vivi vivi_origin 
  38. [armlinux@lqm bootloader]$ rmlink develop 
  39. [armlinux@lqm bootloader]$ rmlink orig 
  40. [armlinux@lqm bootloader]$ ls 
  41. patch u-boot-1.1.3 u-boot-1.2.0 u-boot-1.2.0.orig vivi vivi_origin 

可見測試正常,rmlink可以正常使用,至此,問題最終解決。

附:vmware崩潰,導(dǎo)致關(guān)心查閱磁盤空間和文件大小,現(xiàn)在附幾個常用的小命令,備查閱。

·查看文件的大小

[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

關(guān)于選項-h,在ls等等的命令中都有,具體的含義是一致的,如下:

-h, --human-readable

with -l, print sizes in human readable format (e.g., 1K 234M 2G)

從上面的顯示,可以看出,如果不加-h,那么大小是以字節(jié)顯示的,如果加入-h,那么就以很明顯的K,或者M來顯示,也就明確的多了。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 九龙县| 榆树市| 南昌市| 宝鸡市| 若尔盖县| 北辰区| 乌鲁木齐县| 天长市| 泸定县| 特克斯县| 大宁县| 徐州市| 阿瓦提县| 两当县| 资溪县| 布尔津县| 肥西县| 潜山县| 绵竹市| 辽阳县| 雷州市| 灵武市| 芜湖县| 大石桥市| 垣曲县| 临澧县| 济南市| 石柱| 哈巴河县| 南宁市| 中超| 石楼县| 昌江| 和顺县| 年辖:市辖区| 建水县| 鹤庆县| 鹤峰县| 湘乡市| 建宁县| 财经|