15.3 C
Amsterdam
angeloma
Senior Writer and partner

Open files using the terminal

Hello friends. You know we like the terminal so lately we are solving some usual problems and today we have another one. Although it is not a problem it is quite a problem for scripts or applications that we are developing. In short, in this post, you will learn how to open files from the terminal.

Why would it be useful for me to know how to open files from the terminal?

Generally, most Linux users use the graphical interface more than the terminal. But others prefer to do many tasks from the terminal because it is faster and more efficient.

On the other hand, if you are a developer, you probably need to use some system features. Some command or some process revision may become useful in the development of this application.

So, one of them can be to open a file directly from our application or script, then you have to use the command that actually executes our option. Even shortcuts can be configured so the possibilities are many.

- Advertisement -

So, let’s start

Open files using the terminal

To open a file from the terminal you can invoke the application command with the file path. For example, if I want to open an image with the program okular then you have to run

okular [file_path]

This will open the file with the okular program. Although this method is effective, because you only have to remember the program command in question, it has two drawbacks. The first is that we have to remember the command that executes the application; secondly, it will open a permanent process in the terminal that will terminate when the program is closed.

The second one can be solved in the following way:

okular [file_path] &> /dev/null &

Remember that I am using okular as an example, but it could be firefox or vlc.

There is another method that I think is even more efficient. I am talking about the xdg-open command.

What this command does is runs the default program to open the file that we pass as an argument. For example, if the file is MP3 then it will open the default program to open that type of file. With this, we don’t need to worry about knowing the name of the applications.

xdg-open [file_path]

In this way, the file will be opened with the ideal program for it. The best thing is that an independent process will be created and the terminal will be free.

So, enjoy it

Conclusion

Now you know how to get more out of the terminal and open files from the terminal which can be useful in application development or scripting.

- Advertisement -

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Donate to Osradar

Latest article