theshell.ch/site/pages/cmd/basic/5-open.html

70 lines
2.0 KiB
HTML

---
layout: page
category-page: basic
category-title: Basic commands
tags: open
author: Gianmarco De Vita
title: open
previous-page: pages/cmd/basic/4-man.html
next-page: pages/cmd/basic/6-more-less.html
---
You can open files and folder as new windows through the terminal.
The command is <code>open</code>. By writing the command open followed by the
path and the name of the file (remember that you can omit the path if
the file is in the current position), a new window in the common user
interface opens. Now you can work on the opened file.
<pre>
open path/name-file
</pre>
<h3>Open a file with a specific application</h3>
Adding the flag <code>-a</code> to the command permit you to decide with
which specific application open the file. Just write the flag followed by the
name of the application.
<pre>
open -a application-name path/name-file
</pre>
Assume that you want to open the file <i>abc.pdf</i> on my Desktop using the program "preview".
<pre>
open -a preview Desktop/abc.pdf
</pre>
As result, a new <i>Preview</i> window appears showing the content of the
chosen file.<br>
<h3>Open the folder which contains the file</h3>
If you want to open the folder that contains a specific file, just use
the flag <code>-R</code> and write the path and the name of the file you want to open.
<pre>
open -R Desktop/text.txt
</pre>
As result, a new <i>Finder</i> window opens the folder displaying its content.<br><br>
<h3>Open a file with an editor</h3>
If you want to open a file with your default editor,
just use the flag <code>-t</code> and write the path and the name of
the file you want to open.
<pre>
open -t Desktop/text.txt
</pre>
<h3>Visit a Website</h3>
You can use this tool not only to open files and folders, but also webpages.
Just write the command <code>open</code> followed by the <i>URL</i> of the page
you want to visit.
<pre>
open http://www.google.com
</pre>
A new page of your default browser will open on the indicated page (in this
example, the main page of the Google Search Engine).