lnlidawei

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

shell:delete_executable_file  -   删除当前文件夹的可执行文件(linux)

 

 

 

 

一、 delete_executable_file  -   删除当前文件夹的可执行文件(linux)

 

 1 #!/usr/bin/bash
 2 
 3 
 4 # file_name = delete_executable_file
 5 # delete executable files in current directory. but it dose not delete itself.
 6 
 7 
 8 keep_file="delete_executable_file"
 9 count=0
10 
11 
12 for exe_file in $(ls)
13 do
14         if [ $exe_file != $keep_file ]
15         then
16                 if [ -x $exe_file ]
17                 then
18                         echo "DELETE_FILE_$count = " $exe_file
19                         rm -rf $exe_file
20                         count=$(($count+1))
21                 fi
22         fi
23 
24 done

 

 

 

 

 

 

二、应用实例

 

  1 [root@rockylinux tmp]# cat delete_executable_file
  2 #!/usr/bin/bash
  3 
  4 
  5 # file_name = delete_executable_file
  6 # delete executable files in current directory. but it dose not delete itself.
  7 
  8 
  9 keep_file="delete_executable_file"
 10 count=0
 11 
 12 
 13 for exe_file in $(ls)
 14 do
 15         if [ $exe_file != $keep_file ]
 16         then
 17                 if [ -x $exe_file ]
 18                 then
 19                         echo "DELETE_FILE_$count = " $exe_file
 20                         rm -rf $exe_file
 21                         count=$(($count+1))
 22                 fi
 23         fi
 24 
 25 done
 26 [root@rockylinux tmp]# 
 27 [root@rockylinux tmp]# 
 28 [root@rockylinux tmp]# ls -l
 29 total 264
 30 -rwxr-xr-x 1 root root 23336 Sep  3 01:39 class_test
 31 -rw-r--r-- 1 root root   635 Jul 10 14:25 class_test.cpp
 32 -rw-r--r-- 1 root root  1859 Aug 30 14:36 data_pointer.cpp
 33 -rw-r--r-- 1 root root  1169 Aug 25 01:17 data_structures_stack.cpp
 34 -rw-r--r-- 1 root root   254 Jul 27 17:03 define_user.c
 35 -rwx--x--x 1 root root   373 Sep  3 01:35 delete_executable_file
 36 -rw-rw-rw- 1 root root   373 Sep  3 01:35 delete_executable_file_backup
 37 -rw-r--r-- 1 root root  1366 Sep  2 16:28 embed_structure.cpp
 38 -rwxr-xr-x 1 root root 24016 Sep  3 01:40 enumeration_structure
 39 -rw-r--r-- 1 root root   672 Sep  1 16:39 enumeration_structure.cpp
 40 -rwx--x--x 1 root root   388 Sep  3 01:39 gpp
 41 -rw-rw-rw- 1 root root   388 Sep  3 00:58 gpp_backup
 42 -rw-r--r-- 1 root root   446 Jun 29 09:43 io_test.c
 43 -rw-r--r-- 1 root root  1129 Jul  3 12:47 macro_define.c
 44 -rw-r--r-- 1 root root    20 Jul 11 15:34 minimal-test.c
 45 -rw-r--r-- 1 root root  2932 Aug 30 17:42 mix_data_structure.cpp
 46 -rw-r--r-- 1 root root   814 Sep  2 19:26 multiple_pointer.c
 47 -rw-r--r-- 1 root root   825 Sep  2 18:45 multiple_pointer.cpp
 48 -rwxr-xr-x 1 root root 28608 Sep  3 01:40 multiple_time_pointer
 49 -rw-r--r-- 1 root root  1399 Sep  2 22:25 multiple_time_pointer.cpp
 50 -rw-r--r-- 1 root root 41230 Jun 29 08:23 mysql_h.txt
 51 -rw-r--r-- 1 root root  1592 Aug 31 02:14 object_overload_operator.cpp
 52 -rwxr-xr-x 1 root root 23112 Sep  3 01:40 parameter_function
 53 -rw-r--r-- 1 root root  1131 Aug 30 14:46 parameter_function.cpp
 54 -rw-r--r-- 1 root root   605 Jul 11 13:20 pid_test.c
 55 -rw-r--r-- 1 root root  2605 Jul  1 14:47 pointer_array.c
 56 -rw-r--r-- 1 root root   539 Jun 29 08:54 pointer_charactor_array_test.c
 57 -rw-r--r-- 1 root root   553 Sep  1 17:32 pointer_double.c
 58 -rw-r--r-- 1 root root   592 Sep  1 17:42 pointer_double.cpp
 59 -rw-r--r-- 1 root root   446 Jul 11 13:41 print_test.c
 60 -rw-r--r-- 1 root root   606 Jun 29 09:44 read_file.c
 61 -rw-r--r-- 1 root root   731 Aug 30 18:58 reference.cpp
 62 -rw-r--r-- 1 root root   337 Jul  1 14:36 setjmp.c
 63 -rw-r--r-- 1 root root   868 Jun 29 09:22 string_test.cpp
 64 -rw-r--r-- 1 root root   156 Jul 11 13:23 template.c
 65 [root@rockylinux tmp]# 
 66 [root@rockylinux tmp]# 
 67 [root@rockylinux tmp]# ./delete_executable_file 
 68 DELETE_FILE_0 =  class_test
 69 DELETE_FILE_1 =  enumeration_structure
 70 DELETE_FILE_2 =  gpp
 71 DELETE_FILE_3 =  multiple_time_pointer
 72 DELETE_FILE_4 =  parameter_function
 73 [root@rockylinux tmp]# 
 74 [root@rockylinux tmp]# 
 75 [root@rockylinux tmp]# ls -l
 76 total 160
 77 -rw-r--r-- 1 root root   635 Jul 10 14:25 class_test.cpp
 78 -rw-r--r-- 1 root root  1859 Aug 30 14:36 data_pointer.cpp
 79 -rw-r--r-- 1 root root  1169 Aug 25 01:17 data_structures_stack.cpp
 80 -rw-r--r-- 1 root root   254 Jul 27 17:03 define_user.c
 81 -rwx--x--x 1 root root   373 Sep  3 01:35 delete_executable_file
 82 -rw-rw-rw- 1 root root   373 Sep  3 01:35 delete_executable_file_backup
 83 -rw-r--r-- 1 root root  1366 Sep  2 16:28 embed_structure.cpp
 84 -rw-r--r-- 1 root root   672 Sep  1 16:39 enumeration_structure.cpp
 85 -rw-rw-rw- 1 root root   388 Sep  3 00:58 gpp_backup
 86 -rw-r--r-- 1 root root   446 Jun 29 09:43 io_test.c
 87 -rw-r--r-- 1 root root  1129 Jul  3 12:47 macro_define.c
 88 -rw-r--r-- 1 root root    20 Jul 11 15:34 minimal-test.c
 89 -rw-r--r-- 1 root root  2932 Aug 30 17:42 mix_data_structure.cpp
 90 -rw-r--r-- 1 root root   814 Sep  2 19:26 multiple_pointer.c
 91 -rw-r--r-- 1 root root   825 Sep  2 18:45 multiple_pointer.cpp
 92 -rw-r--r-- 1 root root  1399 Sep  2 22:25 multiple_time_pointer.cpp
 93 -rw-r--r-- 1 root root 41230 Jun 29 08:23 mysql_h.txt
 94 -rw-r--r-- 1 root root  1592 Aug 31 02:14 object_overload_operator.cpp
 95 -rw-r--r-- 1 root root  1131 Aug 30 14:46 parameter_function.cpp
 96 -rw-r--r-- 1 root root   605 Jul 11 13:20 pid_test.c
 97 -rw-r--r-- 1 root root  2605 Jul  1 14:47 pointer_array.c
 98 -rw-r--r-- 1 root root   539 Jun 29 08:54 pointer_charactor_array_test.c
 99 -rw-r--r-- 1 root root   553 Sep  1 17:32 pointer_double.c
100 -rw-r--r-- 1 root root   592 Sep  1 17:42 pointer_double.cpp
101 -rw-r--r-- 1 root root   446 Jul 11 13:41 print_test.c
102 -rw-r--r-- 1 root root   606 Jun 29 09:44 read_file.c
103 -rw-r--r-- 1 root root   731 Aug 30 18:58 reference.cpp
104 -rw-r--r-- 1 root root   337 Jul  1 14:36 setjmp.c
105 -rw-r--r-- 1 root root   868 Jun 29 09:22 string_test.cpp
106 -rw-r--r-- 1 root root   156 Jul 11 13:23 template.c
107 [root@rockylinux tmp]# 
108 [root@rockylinux tmp]# 

 

 

 

 

 

 

posted on 2022-09-02 23:26  lnlidawei  阅读(264)  评论(0编辑  收藏  举报