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 :D) 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!

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;


kedit somefile.txt

Say a jpg file to edit with gimp;


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.

To list files, use

ls

To see the contents of a text file, use

less <filename>

To run a program, just enter the program name followed by any file you want it to open, for example,

nano mytextfile.txt

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

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,

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

konsole /home/*user*/Documents/*filename* 

HTH,
TSU

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

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.

It is possible to open a file in the (desktop’s) associated application via xdg-open though.
E.g.:

xdg-open textfile.txt

should open the textfile.txt in your preferred text editor, similar to clicking on it in dolphin.

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

konsole --help

HTH,
TSU

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)

Looking at the other replies to this question, only ‘hcvv’ seems to have picked up a basic issue with respect to the “Konsole” application:

  • It’s a *NIX Command Line Interface {or Interpreter} (CLI) in a GUI window.

@rhya:
Any Linux system has it’s roots in UNIX® – with all the history which UNIX® has accumulated since it’s inception in 1969 – when there were no Graphical User Interfaces (GUI) as we know them today – which is where the CLI comes in.

The CLI is a “command shell” which a human being uses to communicate with the operating system – in the case of *NIX systems, “below” {“underneath”} the GUI – quite close to the operating system.

There are more than a few *NIX command shells but, as a Linux user, the one you can initially concentrate on is, “bash” – the “Bourne Again Shell”.

Documentation:

And to add to dcurtisfra’s extensive start information: Yes, it looks much, it is much and it is a steep, very steep learning curve.

Create a second user on your system where you can try out things without destroying important data that belongs to your “normal working” user (that may do banking, etc.). Unix/Linux is very good in protecting users from each others stupidities.

Wishing all the best. And hey, when you, during learning and trying, want to ask questions, you are welcome here (as long as you show that you really tried to find the answer yourself).

dcurtisfra wrote:

>
> Documentation:
>
> - As mentioned below, search the web but, a good starting place is
> Wikipedia: <https://en.wikipedia.org/wiki/Bash_(Unix_shell)>;
> - Even better, there’s the openSUSE documentation:
> <http://tinyurl.com/y7last26> (it’s a chapter within the “Startup
> Guide”: <http://tinyurl.com/zcw6q2j>);
> - The publisher O’Reilly has several books which explain *NIX shells
> – including ‘bash’;
> - There are “manual pages” available from the CLI prompt: simply type
> ‘man bash’; ‘man ls’; and so-on;
> - If you aren’t sure of what’s available, simply type ‘apropos <the
> subject I’m interested in>’ at the CLI prompt: for example ‘apropos
> file’ (not a good example – the list is long – you’ll need to pipe
> the output through a “perusal filter” such as ‘more’ {or ‘less’}); the
> output of ‘apropos edit’ is shorter and, possibly a better example;
> - The reference documentation for ‘bash’ is available from the GNU
> project web site: <https://www.gnu.org/software/bash/>.
>
>
In addition to the documentation listed above, there is

https://www.codecademy.com/articles/command-line-commands

This takes you step by step through the command line interface

Thank you guys so much, really appreciate it!
I’m definitely gonna look into it for the future - for now I was just suddenly forced to use ssh (since I failed installing some software myself…) and couldn’t really start learning all that stuff about the shell first.

From a CLI, it’s really quite easy: ‘apropos ssh’; ‘ssh --help’; ‘man ssh’.(Heavy CLI users are actually quite lazy when it comes to typing . . . ;))

Um . . . er . . . maybe, especially if you’re using that Redmond thing but, not here in the *NIX world.

  • The only people who install applications on *NIX systems are, usually, the system administrators – with the exception of stand-alone-do-it-yourself systems where the system’s user has to execute the SysAdmin role.

I must admit that, I didn’t take the use of the command ‘dir’ by rhya very seriously – mainly because I never use the thing on *NIX systems and, because, in the past, it was a CLI “hack” to redefine the ‘ls’ command.

Be that as it may, I see that ‘dir’ was written by Richard M. Stallman and David MacKenzie and, it’s a GNU core utility to “List information about the FILEs (the current directory by default).” and, ‘dir’ is equivalent to ‘ls -C -b’ (sort of, but not really on current Linux systems).Interestingly, ‘vdir’ is equivalent to ‘ls -l -b’.

There may be (and there is) a:

henk@boven:~> which dir
/usr/bin/dir
henk@boven:~>

Bit it is overruled by:

henk@boven:~> alias dir
alias dir='ls -l'
henk@boven:~>

which is in a default user’s environment.

Hi,

apropos = man -k
type -a dir

Thanks. I was trying to remember yesterday: what was that command that told you if it was what would be started. And you enlightend my memory :slight_smile:

henk@boven:~> type -a dir
dir is een alias voor 'ls -l'
dir is /usr/bin/dir
dir is /usr/bin/X11/dir
henk@boven:~>

I hope I will remember next time it is needed.

Hi,

You are welcome hcvv,

Anyways for those of you who are too drunk or too wasted (like me atm) to scroll and read the bash manual, i have exactly what you need…

while read -rn1 -u9; do printf '%s' "${REPLY:-$'
'}"; sleep .04; done 9< <(man bash)

HAPPY NEW YEAR YA’LL!!! rotfl!

PS. Change the sleep time to whatever floats your boat…