- How to Open HTML File From a Terminal?
- Method 1: Open HTML File in Browser
- Using open Command
- Syntax:
- Using a Browser
- Method 2: Open HTML File Using lynx
- Syntax:
- Bonus Tip: How to Edit the Content of the HTML File?
- Syntax:
- Conclusion
- Как я могу запустить HTML-файл из терминала?
- 10 ответов
- How can I preview HTML documents from the command line?
- 5 Answers 5
- Better:
- How to open a file in a browser?
- 3 Answers 3
- If you want a quick and dirty one-line command, use python SimpleHTTPServer
- No webserver
- How can I run a html file from terminal? [closed]
- 9 Answers 9
How to Open HTML File From a Terminal?
Html file is a combination of symbols and text which displays the content of the web page. These files have .html extensions. In Linux, various methods exist to open Html files using the terminal or a graphical user interface. In this post, you will learn how to open Html files using the terminal in Linux. The content of the post is:
Method 1: Open HTML File in Browser
In Linux, you can open any Html file in your browser. There are two ways available for opening any Html file through the terminal. Let’s discuss these two functions one by one.
Using open Command
The “open” is a built-in utility to open any files or directories in Linux. The syntax to open any file using the “open” command is given below:
Syntax:
Write the “open” keyword and then type your Html file name.
Let’s move and check how it works. We have an index.html file in our home directory, which can be seen below:
Let’s open it in the browser using the “open command”.
To open any Html file using the “open” command is obtained as follows:
After executing the above command, it will automatically open the Html in your browser:
The index.html file is opened in the Firefox browser.
Using a Browser
You can open any Html file using a browser as well, and for that, you need to follow the below-mentioned syntax:
Type any browser name and then type your Html file name.
To open any Html file using the browser name, execute the following command in the terminal:
Once the above command is executed, the file will be opened in the browser. In our scenario, we have opened it in the chromium browser as shown in the below image:
The index.html file has been opened in the chromium browser.
Note: You can also use the bash script to open Html files in the browser. Just type in the bash script file and save it:
Once you save it, run the bash script file in the terminal:
The execution of the above command will give you the same output.
Let’s move towards method 2 to open Html files.
Method 2: Open HTML File Using lynx
Another method that can be used to open an Html file is using the “lynx”. “lynx” is a terminal-based web browser that prints the output of the file as plain text in the terminal. In simple words, it’s a non-graphical web browser that shows the web pages on the terminal. It is not pre-installed in Linux distributions; user can install it manually by executing the below command:
For Ubuntu/Debian:
For Fedora/CentOS/RHEL:
The syntax for using the “lynx” is shown below:
Syntax:
Type the “lynx” keyword, “options” for different modes and then file name.
To open an HTML file using “lynx”, use the “dump” option. “dump” option represents the standard output (stdout). Run the following command to see the results:
The content of the Html has been displayed as plain text.
Note: lynx will only print the Html content of the file. However, if you put any javascript content in an Html file, the javascript content will not be printed.
Using lynx, users can also open the Html file in its editor. To do so, use the lynx without option:
Once you type the command, press Enter:
An Html file is opened in the lynx text editor.
These are the possible methods to open an Html file using the terminal.
Bonus Tip: How to Edit the Content of the HTML File?
There are different commands available to open and edit the files in the text editor, such as pico, nano, vi, and much more. In our case, we are using the “nano” editor to open the Html file. The syntax for the nano editor command is shown below:
Syntax:
Write the “nano” keyword and then type the file name.
To open any Html file using the “nano” command is obtained as follows:
Once you execute the above command, it will open the Html file in the nano text editor from where you can edit the content of that HTML file.
Conclusion
To open any HTML file using the terminal, there are three methods. The first method is to open an HTML file in the browser using the “open” command or use any browser name along with the file name. The second method is to open an HTML file in text editors such as nano, while the third is to open an HTML file using lynx. This post has demonstrated all the possible ways to open an HTML file through a terminal in Linux.
Как я могу запустить HTML-файл из терминала?
как вы можете видеть, когда файл загружен, он автоматически нажимает кнопку отправки и перенаправляет его на http://xxxxxx как я могу запустить этот html файл с терминала? Я использую это на openwrt с установленным на нем веб-сервером.
Начните исследование безголовых браузеров. Выбор одного для вас и проведение его установки выходит за рамки этого сайта.
Кроме того, вы, вероятно, не хотите этого делать. Вы должны описать вашу реальную проблему для нас, потому что написание всего HTML-документа со встроенным JavaScript для автоматической отправки формы, просто для программной выдачи POST-запросов из командной строки, является худшим решением этой проблемы. Вероятно, есть команда CURL в одну строку, которая может сделать это для вас.
10 ответов
Для таких, как я, которые достигли этой темы, потому что они хотят обслуживать html файл с терминала linux или хотят просмотреть его с помощью команды терминала, выполните следующие действия:
1) Если вы хотите просмотреть свой html с помощью браузера:
Перейдите в каталог, содержащий html файл
Если у вас установлен хром, используйте: —
2) Если вы хотите обслуживать html файл и просматривать его с помощью браузера
Перейдите в каталог, содержащий html файл
И просто напечатайте на терминале следующее:
Затем щелкните IP-адрес 0.0.0.0:9999 или localhost: 9999 (независимо от результата после выполнения вышеуказанных команд). Или введите на терминал: —
Используя второй метод, любой, кто подключен к одной и той же сети, также может просматривать ваш файл с помощью URL-адреса: — «0.0.0.0:9999»,
How can I preview HTML documents from the command line?
I use catdoc to preview Word documents from the command line. Is there something similar for HTML? In other words I would like to do cathtml Webpage.html | less and get more or less a man page look output.
5 Answers 5
One solution is to use lynx -dump , as in
echo "this is a div" | lynx -dump -stdin
Better:
Use w3m -dump , it respects the page layout. It is awesome.
sudo aptitude install w3m w3m -dump file.html echo "x" | w3m -dump -T text/html
You can set the number of columns of the terminal for getting the better layout, for example, if you are using a full-window terminal, 200 can be a good try:
w3m -dump -cols 200 file.html
You can use html2text to look into an HTML document from command line.
sudo apt-get install html2text html2text Webpage.html | less
but not exactly a look similar to man pages, it depends on the html input, of course.
You could use w3m which should already installed — if however it isn’t
An example command syntax:
w3m -dump askubuntu.com | less
It can be used with both URL’s as well as file-based html files
There are these so-called text html browsers, of which I have successfully tested Lynks and eLinks. Of which elinks has became my favorite.
Anyway, they are different than a «web page previewers» as you suggest in your question. They are more like active real time browsers, which carries on lots of useful features for an easy web browsing and of course, you can also use it for local/remote web pages preview.
Information about Lynks is in the wikipedia and can be reached clicking here. The information related to the elinks is here.
My elinks screenshot for you to see elinks in action:
How to open a file in a browser?
To use your public IP address (i.e. your IP address on the WAN) you’ll probably need some kind of DNS service also, to take care of the possible disconnections / reconnections of your server from your ISP (unless you have a static IP). Do you just want to access the file locally or over the internet?
@kos, Yes, over the internet. I’m connecting my Linux from Windows 8.1 using PuTTY. But want to access index.html on Linux over the internet.
@DKBose: look at the answers first (excellent) and then edit out the off-topic part before VTC. (done already)
3 Answers 3
If you want a quick and dirty one-line command, use python SimpleHTTPServer
python -m SimpleHTTPServer
How to use it example for your case:
$ cd /var/www $ python -m SimpleHTTPServer
Thats it! This will be serving current directory /var/www . Default port is 8000, so your website will be accessible from http://ip-address:8000 or at your local machine http://localhost:8000
To access other files not named index.html , use their name http://ip-address:8000/other-name.html , if there is no index.html, you will see a directory listing with all the files in your folder.
To change port, you need to have sudo priviliges:
$ sudo python -m SimpleHTTPServer 80
This command will be serving your directory on port 80, if you have apache2 already installed, you can change this port to 81, so it does not have a port conflict and you will access your website from http://ip-address:81 , don’t forget to allow these ports in your firewall, to allow port 80 use:
No webserver
Another way is not to use any web-server, just install your favorite desktop environment and browser on your server and connect to it with remote desktop of your choice. Then your website will be available from the browser as you are used to at file:///var/www/index.html
How can I run a html file from terminal? [closed]
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
KIRIM SMS GRATIS
Nomer HP:
Isi Pesan:
as you can see when the file is loaded it automatically clicks the submit button, and redirects it to http://xxxxxx how can I run this html file from terminal? I’m using this on openwrt with webserver installed on it.
Start researching headless browsers. Picking one for you and walking you through installing one up is out-of-scope for this site.
Also, you probably don’t want to do this. You should describe your actual problem for us, because writing an entire HTML document with embedded JavaScript for automatically submitting the form, just to programatically issue POST requests from the command line, is the worst solution to that problem. There’s probably a one-line CURL command that can do this for you.
9 Answers 9
For those like me, who have reached this thread because they want to serve an html file from linux terminal or want to view it using a terminal command, use these steps:-
Navigate to the directory containing the html file
If you have chrome installed,
google-chrome <filename>.html
Navigate to the directory containing the html file
And Simply type the following on the Terminal:-
pushd <filename>.html; python3 -m http.server 9999; popd;
Then click the I.P. address 0.0.0.0:9999 OR localhost:9999 (Whatever is the result after executing the above commands). Or type on the terminal :-
Using the second method, anyone else connected to the same network can also view your file by using the URL: 0.0.0.0:9999
Other users in the network can access said webpage if they navigate to