Shell (Bash) programming instance to get all file names (including folders) in a folder)

Source: Internet
Author: User

The Shell (Bash) programming instance obtains all the file names (including folders) in a folder. Many of them do not understand it, so they record all the files they actually use, I hope the experts will give you more valuable comments. Thank you www.2cto.com [plain] #! /Bin/sh #============= get the file name ============= Folder_A = "/home/youname/ shell/gotfilename/bin "for file_a in $ {Folder_A }/*; do temp_file = 'basename $ file_a 'echo $ temp_file done can also be redirected to a file to be output to [plain] #! /Bin/sh #============= get the file name ============= Folder_A = "/home/Neo/ shell/gotfilename/bin "Output_file =" output.txt "# Use this command to clear the original output file, feeling: this symbol is very useful. It is www.2cto.com:> $ Output_file for file_a in $ {Folder_A}/* To learn more about shell }/*; do temp_file = 'basename $ file_a 'echo $ temp_file> $ Output_file done Update (20130222) -------- added interactivity [html] #! /Bin/sh #============= get the file name ============= echo-e "Enter read folder path \ n current path $ {PWD} "read InputDir echo" Your Input Folder path is $ {InputDir} "echo-e" Please input the data you want to output saved file path n current path $ {PWD} "read OutputFile echo" output saved file path $ {OutputFile} ":> $ OutputFile # Clear OutputFile # loop read folder name for file_a in $ {InputDir }/*; do temp_file = 'basename $ file_a 'echo $ temp_file> $ OutputFile done seems to be better achieved by using command lines in combination with regular expressions
 

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.