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.
find $directory -type f
that will find all the files in that directory including any sub directories
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.
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