How can I open a file when I do not know what command opens it? [duplicate]
Ubuntu noob here. How do I open a file in a working directory? I have already tried
./MyFile.jpg
And it replies with
bash: ./MyFile.jpg: Permission denied
Now, that got me thinking that I had to go and change the permissions. So I used chmod to make the file permission "rwx" (I'm not sure if making executable permissible is going to do what I want, it just seemed logical) and tried
./MyFile.jpg
But this returned
bash: ./MyFile.jpg: cannot execute binary file
Which makes me think the chmod was not the right way to go. So I changed the permission back so that it was not "rwx", but just "rw-". Now I'm stuck feeling pretty foolish because I can't open a simple file in Terminal. I can open it by not using Terminal and double clicking on the file while on the Desktop, but I want to teach myself how to navigate using the Terminal. I also tried
sudo ./MyFile.jpg
but that didn't work either. Any help?
If you want to use the default program for opening a file you can use
gnome-open YourFile
or (as Florian Diesch mentioned in a comment) you can use the following command which also works on every XDG-compliant desktop environment (including KDE, LXDE, and XFCE):
xdg-open YourFile
You have to use a command to open a file. In your case you could use
eog MyFile.jpg
No need to mess with permissions. Eog is the eye of gnome. Type man eog
for more information. It can open the following image files: ani, bmp, gif, ico, jpeg, pcx, png, pnm, ras, svg, tga, tiff, wbmp, xbm, and xpm.
For other file types you need other commands. For example:
- A pdf file called YourMajesty.pdf can be opened with
evince YourMajesty.pdf
. - A text file named MyFile.txt can be opened using
gedit MyFile.txt
and that also holds for many other files containing text (but not having a .txt extension).
If you add a &
at the end of your command (for instance, eog MyPhoto.jpg &
) you can still continue using the same terminal for other commands.
If you want to open a file, use gnome-open
. Think of it as equivalent to double-clicking on the file in Nautilus.
gnome-open MyFile.jpg
If you want to execute a script or a program, then make its execute permission is set, and type the filename prefixed with the path: (You would never do this with a JPG image, because it is not an executable program.)
./executable-name
In the command line it is not possible to just mention a file and have automatically start the appropriate program with that file.
So you must invoke that program (in this case you can use "Eye of Gnome" hence eog
).
Try
eog Myfile.jpg
You can also get back the control of your terminal immediately if you tell eog to launch "in the background" by invoking it with eog Myfile.jpg &
.
Another hint: use tab to let the terminal autocomplete your input.