Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

not found [No such file or directory] error, even though the file present in that directory on RH Linux 6.2

Tags:

linux

shell

When I’m executing a script from Linux (RH Linux 6.2), it is giving not found [No such file or directory] error, even though the file is present in that directory (checked the permissions and they are fine).

Example:

md1silinux04:/data/upgrade> /data/upgrade/upgrade_db.ksh
-ksh: /data/upgrade/upgrade_db.ksh: not found [No such file or directory]

md1silinux04:/data/RAIL/rpo402/db/upgrade> ls /data/upgrade/upgrade_db.ksh
/data/upgrade/upgrade_db.ksh

Could anybody please help on this ?

like image 236
Naga Avatar asked Aug 08 '13 12:08

Naga


People also ask

How do I resolve No such file or directory in Linux?

We can use Linux commands such as objdump, ldd, and readelf to check all the libraries that the binary needs and to check if our system has the program interpreter to run the binary.

Can't open No such file or directory Linux?

First, make sure you execute the program with the correct path. If you make a typo on the directory or file name, you will get this error or give the wrong path. If you are executing the file with a relative path ( ../../file ), try executing with the absolute path ( /path/to/file ) instead.

Why does it say no file or directory?

The error "FileNotFoundError: [Errno 2] No such file or directory" is telling you that there is no file of that name in the working directory. So, try using the exact, or absolute path. In the above code, all of the information needed to locate the file is contained in the path string - absolute path.

How do I resolve No such file or directory error?

In some cases, this error could be shown when the path of the specified file or folders exceeds 258 characters in length. The way to solve this is to reduce the length of the full path to the items specified, either by moving or renaming the file(s) and/or containing folders.


1 Answers

Perhaps you have ctrl-M (carriage returns) at the end of each line in your file.

To view: cat -v /data/upgrade/upgrade_db.ksh

To fix: perl -p -i -e "s/\r//g" /data/upgrade/upgrade_db.ksh

like image 87
user2966631 Avatar answered Nov 15 '22 19:11

user2966631