Shell Scripting Exercises

Source: Internet
Author: User

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

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.