Page 1 of 3 123 LastLast
Results 1 to 10 of 22

Thread: open file via terminal

  1. #1
    Join Date
    Jan 2017
    Posts
    10

    Default open file via terminal

    I am very sorry for this question, I already feel so stupid...

    I'm new to using a terminal (instead of dolphin ) and all I wanna do is open a file using Konsole - so I'm in the right directory and when I type "dir" the file I want is listed. So I thought the command to opening it was "open filename" but all I get is "If 'open' is not a typo you can use command-not-found to lookup the package that contains it".
    So what must I actually do? Or is it supposed to work this way?

    Thanks a lot!

  2. #2
    Join Date
    Jun 2008
    Location
    Podunk
    Posts
    27,253
    Blog Entries
    15

    Default Re: open file via terminal

    Hi
    That depends on what the file is.... for example if you want to open a text file then it's the apllication then the filename, eg;
    Code:
    kedit somefile.txt
    Say a jpg file to edit with gimp;
    Code:
    gimp somepic.jpg
    So it's the application to run then the filename. You need to know this first....

    <some_application> <some_filename>

    With the desktop GUI application it will have the file mime type stored, so it knows what application to open with what file.
    Cheers Malcolm °¿° SUSE Knowledge Partner (Linux Counter #276890)
    SUSE SLE, openSUSE Leap/Tumbleweed (x86_64) | GNOME DE
    If you find this post helpful and are logged into the web interface,
    please show your appreciation and click on the star below... Thanks!

  3. #3
    Join Date
    Jun 2008
    Location
    West Yorkshire, UK
    Posts
    3,454

    Default Re: open file via terminal

    To list files, use
    Code:
    ls
    To see the contents of a text file, use
    Code:
    less <filename>
    To run a program, just enter the program name followed by any file you want it to open, for example,
    Code:
    nano mytextfile.txt

  4. #4
    Join Date
    Nov 2009
    Location
    West Virginia Sector 13
    Posts
    15,769

    Default Re: open file via terminal

    use the app you want to open the file with with. File associations are part of the GUI not the command line.

  5. #5
    Join Date
    Jun 2008
    Location
    San Diego, Ca, USA
    Posts
    11,499
    Blog Entries
    2

    Default Re: open file via terminal

    The previous posts are all true, but to apply them specifically to your question
    If your console prompt is in the location where your file is,
    Code:
    konsole filename 
    Else, you have to describe the path (full or relative) to your file as part of the filename.
    For example, no matter where your console prompt might be, the following will open a file in your Documents directory where "user" is your Username
    Code:
    konsole /home/user/Documents/filename

    HTH,
    TSU
    Beginner Wiki Quickstart - https://en.opensuse.org/User:Tsu2/Quickstart_Wiki
    Solved a problem recently? Create a wiki page for future personal reference!
    Learn something new?
    Attended a computing event?
    Post and Share!

  6. #6
    Join Date
    Jan 2017
    Posts
    10

    Default Re: open file via terminal

    Quote Originally Posted by malcolmlewis View Post
    So it's the application to run then the filename. You need to know this first....

    <some_application> <some_filename>

    With the desktop GUI application it will have the file mime type stored, so it knows what application to open with what file.
    Thank you so so much!

    Now how do I find out what command to use in order to avoid asking questions like this again? Of course I tried google but I obviously failed

  7. #7
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,402

    Default Re: open file via terminal

    Quote Originally Posted by rhya View Post
    Thank you so so much!

    Now how do I find out what command to use in order to avoid asking questions like this again? Of course I tried google but I obviously failed
    From your questions and reactions I assume that you are quite new to using a terminal with a shell.

    Try to find information about what a shell (and special bash) is and a basic tutorial about using bash. There must be plenty on the Internet.
    Henk van Velden

  8. #8

    Default Re: open file via terminal

    It is possible to open a file in the (desktop's) associated application via xdg-open though.
    E.g.:
    Code:
    xdg-open textfile.txt
    should open the textfile.txt in your preferred text editor, similar to clicking on it in dolphin.
    Last edited by wolfi323; 27-Dec-2017 at 09:58.

  9. #9
    Join Date
    Jun 2008
    Location
    San Diego, Ca, USA
    Posts
    11,499
    Blog Entries
    2

    Default Re: open file via terminal

    Quote Originally Posted by rhya View Post
    Thank you so so much!

    Now how do I find out what command to use in order to avoid asking questions like this again? Of course I tried google but I obviously failed
    For this specific situation which is how to open a file with an application,
    You should know that in almost 100% of all cases the common application name is the same as the application command...
    So, for instance in this case when you know there is a Konsole application in your menu, you should also be able to guess that you can launch that same application from a console (windowed text command line) by typing in that same name(all lower case) and then hit <Enter>.

    But, just the above will only open the application, not launch that application <and> open a file.
    To know how to do this, you can follow any command with "--help" to display what you you can do with the command (The technical term is the required syntax).

    So,
    In your original post you asked how to do something (open a file) with a specific application (Konsole).
    To display how to do this, and it will work with other applications as well, type the following in your console
    Code:
    konsole --help
    HTH,
    TSU
    Beginner Wiki Quickstart - https://en.opensuse.org/User:Tsu2/Quickstart_Wiki
    Solved a problem recently? Create a wiki page for future personal reference!
    Learn something new?
    Attended a computing event?
    Post and Share!

  10. #10
    Join Date
    Jun 2008
    Location
    San Diego, Ca, USA
    Posts
    11,499
    Blog Entries
    2

    Default Re: open file via terminal

    Actually,
    Forgive me but I've been posting a bit of nonsense in this thread, suggesting that the Konsole app can open a text file by itself.

    Of course, within a terminal you have to invoke a "viewer" app capable of opening the type of file (like less which was suggested).

    TSU
    (Gotta get my head straight.. no excuses)
    Beginner Wiki Quickstart - https://en.opensuse.org/User:Tsu2/Quickstart_Wiki
    Solved a problem recently? Create a wiki page for future personal reference!
    Learn something new?
    Attended a computing event?
    Post and Share!

Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •