I am new to Unix and I want to know how to check if a file is present in a particular directory in Unix? Please help me through this.
Thank you.
CodePudding user response:
We can make use of [ls] and [$?] command to do this. Use below command :
ls -l filename.txt
Followed by,
echo $?
If the file exists, the [ls] command will be successful.Hence [echo $?] will print 0.
If the file does not exists, then [ls] command will fail and hence [echo $?] will print 1.