How to add a program that can be run from CMD line? - linux

I am using Bash in a linux system, and right now I can do stuff like: "gedit 1.txt" in my terminal.
I want to do it with Sublime text 2, instead of going to my Sublime directory and manually open the program first.
Thanks

what's problem with you it works for sublime also. Also which system you use?
Your PATH might be not contain path to sublime executable.So first you can locate it by
$ locate sublime
And add path of this executable to your $PATH
Or if not want to search and add process then please remove sublime from your system and install as follows so it will added to your default path
Remove steps:
sudo rm -r /opt/Sublime\ Text\ 2
sudo rm /usr/bin/sublime
sudo rm /usr/share/applications/sublime.desktop
sudo sed -i 's/sublime\.desktop/gedit.desktop/g' /usr/share/applications/defaults.list
Installation steps:
sudo add-apt-repository ppa:webupd8team/sublime-text-2
sudo apt-get update
sudo apt-get install sublime-text
After installing go to terminal and type name starting with sub or press TAB then it will automiticaly give hint for sub line like
sysadmin:~/Desktop$ subl //after entering some first char then Pressed enter
subl sublime-text
and you will be now able to open sublime via terminal as follows
sysadmin:~/Desktop$ sublime-text file1.txt

Related

bash: /home/x/.bash_profile: Permission denied. How to fix this issue?

I am trying to open the bash_profile file but it gives the following result
~/.bash_profile
bash: /home/x/.bash_profile: Permission denied
After searching I found this solution on the internet
source ~/.bash_profile
But this command gives the following output
The program 'the' is currently not installed. You can install it by typing:
sudo apt install the
when I typed it gives this result
sudo apt install
[sudo] password for x:
Reading package lists... Done
Building dependency tree
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove, and 0 not upgraded.
x#ubuntu:~$ source ~/.bash_profile
The program 'the' is currently not installed. You can install it by typing:
sudo apt install the
please help me how to fix it.
Thank you All.
For viewing the bash_profile:
cat ~/.bash_profile
For editing:
vi ~/.bash_profile
If you get a permission denied, use sudo before cat or vi commands.
Hello
And for only creating your own without editing it...
set -x && $(type -p touch) ${HOME}"/.bash_profile"; set +x
... if already exists then only the modification time is changing.
I wrote the simple command cryptic because set -x shows what going on and set +x exits the debug mode.
After the clarifications, let me tell you what is happening.
The ~/.bash_profile file is a configuration file for configuring user environments. The users can modify the default settings and add any extra configurations on it. In your case, the file is empty and it is throwing an error because inside the file you have the word "the".
You Linux Server is trying to run the command "the", so the reason for the error you are getting is that you have no execution privileges over it. I've never ever heard of a program called "the", but giving your error perhaps the program is there. If the program did not exist, you would have gotten "No such file or directory".
Replace the content of the .bash_profile with the minimum content you need for this kind of file:
$ cat ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
export PATH=.:$PATH:$HOME/.local/bin:$HOME/bin

Unable to prepare context: path ".\r" not found

I have created build_docker.sh file in windows machine which has below contents.
#!/usr/bin/env bash
#This script build docker image
docker build -t hello-world .
Where I try to run above file using command sudo sh build_docker.sh
It fails with an error, Unable to prepare context: path ".\r" not found
I am using 4.2.46(2)-release Bash version
What I am missing here?
There is an utility to convert file to unix EOL, it helped me.
dos2unix build_docker.sh
… using :set fileformat=unix and sudo bash build_docker.sh solved my problem
– Mayur
changing file name from filename.sh to .bash solved my issue.
This will also work.
1. Open all files using vim *
2. Press "qq" to start recording
3. :set ff=unix
4. :wn
5. Press again "q" to stop recording
6. :wq!

Path to vim and sudo executables

I've messed up my PATH variable by editing /etc/environment, I don't have rm, sudo or many commands. Can someone tell me the path to the vim and sudo executables so I can fix this
The path to vim can possibly vary, for vi it's /usr/bin/vi.
You can still fix your PATH by exporting it manually in shell as below:
Ubuntu default:
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
CentOS default (tested on VM):
export PATH=/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:$HOME/.local/bin:$HOME/bin
You can also look for the binaries by the following commands (if you run sudo updatedb before):
locate vim | grep -w "vim$"
or:
type -a vim
The best would be to fix your PATH by adding the right values into the right rc file. Normally you set that in ~/.profile for the current user, or adding new as part of /etc/init.d scripts:
$ grep -R PATH /etc/init.d
/etc/init.d/functions:PATH="/sbin:/usr/sbin:/bin:/usr/bin"
/etc/init.d/functions:export PATH
/etc/init.d/netconsole:PATH=/sbin:/usr/sbin:$PATH
/etc/init.d/vboxadd:PATH=$PATH:/bin:/sbin:/usr/sbin
/etc/init.d/vboxadd-service:PATH=$PATH:/bin:/sbin:/usr/sbin
/etc/init.d/vboxadd-x11:PATH=$PATH:/bin:/sbin:/usr/sbin
Vim:
$ which vim
/usr/bin/vim
sudo:
$ which sudo
/usr/bin/sudo

How to make terminal recognize command "gvim" or "mvim"?

I am not sure I understand correctly from the readme file how to install vim onto my mac. After installation, I still cannot seem to open files while typing gvim HelloWorld.c into terminal. How can I permanently fix the gvim command for terminal to recognize all the time?
Mac OS X already ships with a slightly underpowered but perfectly working vim build so you only have to issue that command in your terminal:
$ vim filename
MacVim is a more featureful version that comes with a GUI and a CLI executable. Is that what you installed?
The archive you downloaded contains MacVim.app and a shell script called mvim.
If you don't plan to use Vim in or from your terminal, you don't need that mvim script at all.
If you do, the simplest solution is to put that script somewhere in your $PATH. To do so, check the value of $PATH with the following command:
$ echo $PATH
and copy the script into one of the listed directories:
$ cp /path/to/mvim /some/directory/mvim
After that's done, you can call the MacVim GUI from your terminal with:
$ mvim filename
or the MacVim CLI with:
$ mvim -v filename

bash: __vte_prompt_command: command not found

bash: __vte_prompt_command: command not found
Whenever I open a terminal, I am greeted with this line. Also, this is printed each time I enter a command in the terminal.
I am a linux-noob, and would be happy to read up, if someone can point me to some resource, or hint at a possible solution. I tried google-ing, but was unable to turn up with any useful results.
I did not do anything specific just before this started popping up.
Thanks in advance :)
Additional Info:
The terminal I used is the default gnome-terminal
Fedora 20
It sounds like a program named VTE has set your bash environment variable PROMPT_COMMAND to invoke a function called __vte_prompt_command.
The PROMPT_COMMAND environment variable defines a command that is executed before every new prompt is displayed to the screen. It can be very annoying when this command produces unexpected output.
You can temporarily get rid of the annoying messages by entering this command in the terminal:
__vte_prompt_command() { true; }
This creates a dummy function that does nothing - you can confirm by looking at the output of this command:
type __vte_prompt_command
After applying the hack to my system I see this:
__vte_prompt_command is a function
__vte_prompt_command ()
{
true
}
However, this is an indication that VTE may not be installed properly and/or may be broken. You might want to try to reinstall VTE, if possible. I would not recommend putting this permanently into your ~/.bashrc file.
I am running Ubuntu 18.04 with the default gnome-terminal and ran into the same problem but wanted a definitive solution.
After trying the solutions suggested previously, I still had the message:
__vte_prompt_command: command not found
comming up after starting a new terminal and after each command terminated.
I searched for a file in for instance .bashrc, .profile that would be doing a source /etc/profile.d/vte-2.91.sh with no luck.
Than I remembered that a long time ago I added the following line in my ~/.bashrc:
export PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND$'\n'}history -a; history -c; history -r"
in order to append command line histories to all opened terminals. I figured out that commenting it solved the problem.
#export PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND$'\n'}history -a; history -c; history -r"
than
$ source ~/.bashrc
Thought I would share this for anyone having the same problem.
You can disable the corresponding code by editing your ~/.bashrc by using sudo gedit ~/.bashrc, searching for the string "vte" with STRG+F and outcommenting the line with a #.
On my system, the line looked like this, I guess an old installation of Ubuntu Budgie put it there:
if [ $TILIX_ID ] || [ $VTE_VERSION ] ; then source /etc/profile.d/vte.sh; fi # Ubuntu Budgie END
And if it looks like this, the line in your terminal will not appear anymore:
#if [ $TILIX_ID ] || [ $VTE_VERSION ] ; then source /etc/profile.d/vte.sh; fi # Ubuntu Budgie END
For CentOS7 (64 bit):
Try installing using yum command.
sudo yum update -y
sudo yum install -y terminator
sudo yum install -y epel-release
sudo yum install -y terminator #again
Resart the command prompt terminal, This worked for me (:
Reference: http://bytefreaks.net/gnulinux/install-terminator-in-centos-7-64bit
set +v
I think you may somehow made: set -v (Prints shell input lines as they are read.)
so set i

Resources