Why do we use
./filename to execute a file in linux?
Why not just enter it like other commands
You need the
You can use
The literal answer is as others have given: because the current directory isn't in your
But why? In short, it's for security. If you're looking in someone else's home directory (or /tmp), and type just
If you mean, why do you need ./ at the start - that's because (unlike in Windows), the current directory isn't part of your path by default. If you run:
your shell looks for
the shell will do likewise - but it probably won't find an executable called a.out. You need to tell the shell where a.out is - it it's in the current directory (.) then the path is
If you're asking why it's called "a.out", that's just the default output file name for gcc. You can change it with the -o command line arg. For example:
You can try to add
Try ALT+F2 and type:
HOWEVER, I strongly advise you NOT to do that. It's bad bad bad and bad.
You know, that kind of things work like this since 1970. There is a reason why the current directory isn't included in the $PATH.