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.

3 Answers 3

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.

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
1
  • i was trying with an emty directory xD Commented Jan 7, 2016 at 14:21

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.