how to run file associated application from console linux - linux

on windows exist command:
start myfile.mp3
start myfile.txt
on mac:
open myfile.mp3
open myfile.txt
Are there analogue command under Ubuntu?

xdg-open if you have a freedesktop.org-compatible environment.

There are several commands in Linux that help you open application associated files. If you know the application to open the file, then this may work . I am not sure if you are looking for this
env DISPLAY=:0.0 firefox "google.com"
opens Firefox with google.com opened in it. You can replace the application name and file name and use this command.

Try "gnome-open", for Gnome powered distros.
gnome-open random-file.torrent will open my torrent app.

Related

"Couldn't find a file descriptor referring to the console" on Ubuntu bash on Windows

I have a problem with Bash on Ubuntu on Windows. If I type "open (filename)" on Mac terminal, it opens the file with the right program but if I try to use it on Windows bash, it says: "Couldn't find a file descriptor referring to the console".
I have also tried xdg-open and gnome-open but none of them works. How can the issue be fixed, and how does the open command work?
Instead of open u can use xdg-open which does the same thing, independently of application i.e. pdf, image, etc. It will open a new virtual terminal (I have tried this on Linux)
Example:
xdg-open ~/Pictures/Wallpapers/myPic.jpg
xdg-open ~/Docs/holidays.pdf
For linux, use xdg-open. open is for Mac OS. open in linux is an name alias of openvt (open virtual terminal).
To simplify it, you can append the following line to ~/.bashrc or ~/.zshrc depends on the shell you are using.
alias o="xdg-open" # o stands for open
Then next time you can just type like the following to reduce some keyboard strokes.
o file_name.pdf
That's because open is a Mac specific command, it is not available under Linux (ubuntu), Mac open can execute a file (if the file is executable), or open the file into a text editor (if it is a document or text file) or open a directory.
For opening a file to write in Ubuntu on Windows bash, you can type -:
nano filename.txt
The above command will allow you to write/edit in the file after which, you can use ctrl+x and then press 'y' to save. Check/view the file content using -:
cat filename.txt

Search linux log files using mac terminal or script

I want to search my access logs for traffic going to a directory on a Linux. I have a mac which I know I can do this with my terminal but I can't find an example how to do this.
Do you have the log locally on your Mac? Or are you asking how you would use a Mac to administer a Linux OS?
Open terminal, either change directory to the dir that contains the log or adjust the command to suit. Depending on what you want to search for, you'd use grep.
grep -i "dir name" logfile.log
It's a bit of a wide empty question so I don't know what you want to search for.
If it's remote, you'd open terminal and ssh to the server which has the log and do something similar to the above. Or, if you're asking how you would do it in one command, you could use ssh too.
ssh user#linux "grep something /var/log/apache/access.log"

Open Cygwin command in specified directory on windows

I use phpstorm and it's terminal facility.
In terminal section I typed F:\Projects\cygwin64\bin\mintty.exe -i /Cygwin-Terminal.ico - so it uses Cygwin as terminal. But it opens it in home folder. Is it possible to open it in different folder? By typing a command or by doing something else.
Because I have a folder called F:\Projects\Local in this folder I have vagrant and I want to open phpstorm, open terminal within php storm and just type vagran up. I don't want to open cgywin again.
thanks
If you just want to open Cygwin with Mintty in the project directory then you can execute the command:
F:\Projects\cygwin64\bin\mintty.exe /bin/env CHERE_INVOKING=1 /bin/bash -l
This will avoid automatically changing to the home directory. See https://code.google.com/p/mintty/wiki/Tips#Starting_in_a_particular_directory for more information on this command.
If you want to use the embedded PhpStorm terminal, then you can modify the Shell path in the terminal settings. Open File > Settings... > Tools > Terminal. Replace the shell path with F:\Projects\cygwin64\bin\env.exe CHERE_INVOKING=1 /bin/bash -l. You may need to restart PhpStorm after this change.
Note: this is assuming that your Cygwin Root Directory is F:\Projects\cygwin64\.
For whome the above way ain't work anymore, like in PhpStorm v. 2016.3. The shell path have to be enclosed in quotes
"C:\Users\MyUser\.babun\cygwin\bin\env.exe" CHERE_INVOKING=1 /bin/zsh.exe
For the PhpStorm that I'am using (v10.0.4) in Windows 10 I use this command works:
D:\tools\.babun\cygwin\bin\env.exe CHERE_INVOKING=1 /bin/bash.exe
I'm using Babun which installs the Cygwin in D:\tools\.babun\cygwin.

SHELL to TXT, Is It Possible?

I created a .sh file in Linux Server and would like to convert it into a text file for windows or Linux mint. Is that possible of doing?
Thank You!!!
In windows right click on it and click "Open with..." and choose notepad.
In mint go to terminal and use either vi or nano to edit the file:
vi /path/to/file/file.sh
Well, not sure if it is what you wanted, but if you have i.e. file named script.sh, you can simply redirect it to another file by executing
cat script.sh > script.txt
However, be aware that EOF in linux is different than in Windows, so you can use this.
just copy the contents from sh file into another file within linux or run this command
cp file.sh file.txt

telnet Unix/Linux and download the file to local Windows system

Is it possible to do so:
I am on Windows system and telnet Unix/Linux remotely. Then I would like to download file from telnet mode and download to Windows system. Any Unix/Linux command are able to do so? like rcp or ftp. How to do so? Does it require any configuration on both system?
i try to write the shell script on Unix/linux side. and i telnet Unix/linux system remotely from local Windows machine and log in to Unix/linux system, run the script on Unix/linux side. some files will be transfered or download automatically to my windows system.
assume permission is not a problem
You can use x/y/zmodem to transfer file if both ends support that.
On Linux/Unix, you can use sz command to send file via zmodem.
On Windows, both Secure CRT (commercial) or Le Putty (open source) are capable of zmodem.
I think you want PSCP (command line) or WinSCP (GUI).
Usually people use ftp session to transfer files. If permissions is not a problem why don't you run ftp from your Windows computer?
You can create a windows batch script to load your file. Try something like
ftp hostname
user
password
cd /path/to/file
get myfile
quit
If you must do it through the existing connection, look at protocols such as ZMODEM and the rz and sz commands for them on Linux. You will need a terminal program on Windows that supports that protocol though.
For small files, I just uuencode (or gzip -c | uuencode name.gz) on the command line over the telnet session, then cut and paste to uudecode on my local windows computer (using cygwin).
You can use this:
telnet hostname 80 > filename_to_download_in
GET /path/to/file HTTP/1.0

Resources