简体   繁体   中英

How to list files on directory shell script

I need to list the files on Directory. But only true files, not the folders. Just couldn't find a way to test if the file is a folder or a directory....

Could some one provide a pice o script for that?

Thanks

How about using find ?

To find regular files in the current directory and output a sorted list:

$ find -maxdepth 1 -type f | sort

To find anything that is not a directory (Note: there are more things than just regular files and directories in Unix-like systems):

$ find -maxdepth 1 ! -type d | sort

bash shell中, test -f $file会告诉你$ file是否是一个文件:

if test -f $file; then echo "File"; fi

You can use ls -l | grep ^d -v ls -l | grep ^d -v to realize what you want. I tested it in Redhat 9.0, it lists only the true files, including the Hidden Files.

If u want to get a list the folders on Directory. But only folders, not the true files. You can use ls -l | grep ^d ls -l | grep ^d

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM