1. List the directory under the current directory (only one level is required)
1 #!/bin/bash 2 for f in ' LS ' 3 do 4 if [-D $f] 5 then 6 echo $f 7 fi 8 done
2, the current directory of files (only need a level) listed
1 #!/bin/bash 2 for f in ' LS ' 3 do 4 if [-F $f] 5 then 6 echo $f 7 fi 8 done
[[Email protected] ~]# date +%f "%T" 2016-02-17 15:54:13
Knowledge points : In a shell script, if also often judge about the file attributes, such as whether it is a normal file or directory, to determine if the files have read and write execution permissions. There are several options that are commonly used:
-E: Determine if a file or directory exists
-D: Determine if the directory is not present and whether it exists
-F: Determine if the file is normal and exists
-R: Determine if the document has Read permissions
-W: Determine if Write permission is available
-X: Determine if executable
This article is from the "Boyhack" blog, make sure to keep this source http://461205160.blog.51cto.com/274918/1742703
Shell Scripting Exercises