Linux shell gets the file name under the folder

article author: Tyan
blog: | CSDN | short book

sometimes need to get all the file names under a folder, can be implemented with the program, but open the IDE, compile and run too troublesome, in Linux server usually can not open the IDE, at this time can be implemented with a few lines of simple shell command, the result can be saved in a file.

Shell script is as follows:

# get all filename in specified path

files=$(ls $path)
for filename in $files
   echo $filename >> filename.txt

Read More: