not found No such file or directory Linux

not found No such file or directory Linux

This is very annoying and command problem while working with Linux box and to fix it will take very long time as it happened to me. You will get below exception:

not found [No such file or directory]

ksh: ./run-script.sh: not found [No such file or directory]

While this file is available with proper permission.

  • Solution: This happens if you have file and have ctrl-M (carriage returns) at the end of each line in your file as shown below:

Use this command to see if ctrl-M is there in the file:

$ cat -v fileName

  • Example if your file name is run-script.sh

$ cat -v run-script.sh

not found No such file or directory Linux

  • As you see above many carriage return character are there in the file. To remove this character please use below command:

$ perl -p -i -e “s/\r//g” fileName.sh
$ perl -p -i -e “s/\r//g” * –> (If you want to do all file inside current folder)

Example if your file name is run-script.sh

$ perl -p -i -e “s/\r//g” run-script.sh

  • After executing this command view file again using

$ cat -v fileName

  • You will see below clean file without any ctrl-M (carriage returns):

not found No such file or directory Linux

Leave a Reply

Your email address will not be published. Required fields are marked *