Check if Linux bash file exists

So, I am trying to check if a file exists or not, and then the script should do something if that happens. The problem I am facing is to understand that there is actually something.

if [ -e /temp/file.txt ]; then
        echo "file found!"
        sudo cp -r temp/* extra
else
        echo "file not found! Creating new one..."
        ./create.sh
fi

Below is an example of files in the tested directory. they are clearly there, but for some reason I cannot get a script to see this. what am I doing wrong?

nima@mkt:/docs/text$ ls -a temp
.  ..  more  file.txt  file2.txt
+3
source share
3 answers

You use absolute paths in your test, while you have to use relative paths:

 if [ -e ./temp/file.txt ]; then
+11
source

/temp/file.txtvs /docs/text/temp/file.txt?

+2
source

You script look /tempwhile you look/docs/text/temp

+1
source

All Articles