Ubuntu – How to open a file when I do not know what command opens it?

command line

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?

Best Answer

  • 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:

    1. A pdf file called YourMajesty.pdf can be opened with evince YourMajesty.pdf.
    2. 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.

  • Related Question