For files in directory, ignoring folders For files in directory, ignoring folders shell shell

For files in directory, ignoring folders


for filename in /home/user/*do    if [ ! -d "$filename" ]; then        echo $filename    fidone

Or, use the find command:

find /home/user ! -type d -maxdepth 1


As in my previous answer you really want to use find. What you're trying to do on 7-10 of lines scripting can just be done with this:

find /home/user -type f -printf "%f\n"


You can use -d operator to check whether $filename refers to a directory:

for filename in /home/user/*do  if [ ! -d "${filename}" ]  then    echo $filename  fidone;

See test manpage for details and other available operators.

You can also use the find command:

find /home/user -not -type d -maxdepth 1