系统相关
首页 > 系统相关> > shell: list_executable_file - 列出可执行文件的名称(linux)

shell: list_executable_file - 列出可执行文件的名称(linux)

作者:互联网

shell: list_executable_file - 列出可执行文件的名称(linux)

 

 

 

 

一、shell: list_executable_file

 

 1 #!/usr/bin/bash
 2 
 3 
 4 # file_name=list_executable_file
 5 # function: list executable files in the current directory.
 6 
 7 
 8 function list_executable_file()
 9 {
10         count=0
11         echo
12         for file in $(ls)
13         do
14                 if [ -x $file ]
15                 then
16                         echo "EXECUTABLE_FILE_$count: " $file
17                         count=$(($count+1))
18                 fi
19         done
20         echo
21 }
22 
23 
24 list_executable_file

 

 

 

 

二、应用示例

 

 1 [root@rockylinux tmp]# cat list_executable_file 
 2 #!/usr/bin/bash
 3 
 4 
 5 # file_name=list_executable_file
 6 # function: list executable files in the current directory.
 7 
 8 
 9 function list_executable_file()
10 {
11         count=0
12         echo
13         for file in $(ls)
14         do
15                 if [ -x $file ]
16                 then
17                         echo "EXECUTABLE_FILE_$count: " $file
18                         count=$(($count+1))
19                 fi
20         done
21         echo
22 }
23 
24 
25 list_executable_file
26 [root@rockylinux tmp]# 
27 [root@rockylinux tmp]# 
28 [root@rockylinux tmp]# ls -l
29 total 268
30 -rwxr-xr-x 1 root root 23336 Sep  3 01:12 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   349 Sep  3 00:59 delete_exe
36 -rw-r--r-- 1 root root   349 Sep  3 00:59 delete_exe_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:12 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:12 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 -rwx--x--x 1 root root   316 Sep  3 01:18 list_executable_file
44 -rw-r--r-- 1 root root  1129 Jul  3 12:47 macro_define.c
45 -rw-r--r-- 1 root root    20 Jul 11 15:34 minimal-test.c
46 -rw-r--r-- 1 root root  2932 Aug 30 17:42 mix_data_structure.cpp
47 -rw-r--r-- 1 root root   814 Sep  2 19:26 multiple_pointer.c
48 -rw-r--r-- 1 root root   825 Sep  2 18:45 multiple_pointer.cpp
49 -rwxr-xr-x 1 root root 28608 Sep  3 01:12 multiple_time_pointer
50 -rw-r--r-- 1 root root  1399 Sep  2 22:25 multiple_time_pointer.cpp
51 -rw-r--r-- 1 root root 41230 Jun 29 08:23 mysql_h.txt
52 -rw-r--r-- 1 root root  1592 Aug 31 02:14 object_overload_operator.cpp
53 -rwxr-xr-x 1 root root 23112 Sep  3 01:12 parameter_function
54 -rw-r--r-- 1 root root  1131 Aug 30 14:46 parameter_function.cpp
55 -rw-r--r-- 1 root root   605 Jul 11 13:20 pid_test.c
56 -rw-r--r-- 1 root root  2605 Jul  1 14:47 pointer_array.c
57 -rw-r--r-- 1 root root   539 Jun 29 08:54 pointer_charactor_array_test.c
58 -rw-r--r-- 1 root root   553 Sep  1 17:32 pointer_double.c
59 -rw-r--r-- 1 root root   592 Sep  1 17:42 pointer_double.cpp
60 -rw-r--r-- 1 root root   446 Jul 11 13:41 print_test.c
61 -rw-r--r-- 1 root root   606 Jun 29 09:44 read_file.c
62 -rw-r--r-- 1 root root   731 Aug 30 18:58 reference.cpp
63 -rw-r--r-- 1 root root   337 Jul  1 14:36 setjmp.c
64 -rw-r--r-- 1 root root   868 Jun 29 09:22 string_test.cpp
65 -rw-r--r-- 1 root root   156 Jul 11 13:23 template.c
66 [root@rockylinux tmp]# 
67 [root@rockylinux tmp]# 
68 [root@rockylinux tmp]# ./list_executable_file 
69 
70 EXECUTABLE_FILE_0:  class_test
71 EXECUTABLE_FILE_1:  delete_exe
72 EXECUTABLE_FILE_2:  enumeration_structure
73 EXECUTABLE_FILE_3:  gpp
74 EXECUTABLE_FILE_4:  list_executable_file
75 EXECUTABLE_FILE_5:  multiple_time_pointer
76 EXECUTABLE_FILE_6:  parameter_function
77 
78 [root@rockylinux tmp]# 
79 [root@rockylinux tmp]# 

 

标签:executable,shell,Sep,--,list,rw,file,root
来源: https://www.cnblogs.com/lnlidawei/p/16651821.html