1

I want the files of a given directory and use the following script:

echo "give name of directory: "
read directory
if  [ -d "$directory"   ]
then 
echo "thanks again"
else exit
fi
find  /-type f $directory

Unfortunately this does not work.

0

The find command is wrongly written:

find  /-type f $directory

Should be:

find "$directory" -type f

Note that the find command is recursive. If you are only interested in files in the exactly given directory use:

find "$directory" -maxdepth 1 -type f

And finally to add a little simpler version:

echo "give name of directory: "
read directory
if  [ -d "$directory" ]
then 
    echo "thanks again"
    find  "$directory" -maxdepth 1 -type f
fi
  • i was trying with an emty directory xD – ted Jan 7 '16 at 14:21
1

find $directory -type f

that will find all the files in that directory including any sub directories

1

I'm guessing here, but this might be what you want:

echo "give name of directory: " 
read directory 
if [ -d "$directory" ]
then 
    echo "thanks again" 
else 
    exit 
fi 
find $directory -type f

You had find looking in /, the root directory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.