Linux shell gets the file name under the folder

article author: Tyan
blog: noahsnail.com | 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:

#!/bin/bash
# get all filename in specified path

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

Read More: