Path to vim and sudo executables - linux

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

Related

I set .bashrc but my promt looks still the same

i'm quite new with linux and I want to tweak my terminal prompt. The default is user#user - Thinkpad- T420 ~$. That pretty annoying long.
I searched google and I tried my best but it didn't show any difference.
What i have done:
echo $PS1
\[\e]0;\u#\h \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u#\h\[\033[00m\] \[\033[01;34m\]\w \$\[\033[00m\]
locate bashrc
/etc/bash.bashrc
/etc/skel/#.bashrc#
/etc/skel/.bashrc
/etc/skel/.bashrc~
/usr/share/base-files/dot.bashrc
/usr/share/doc/adduser/examples/adduser.local.conf.examples/bash.bashrc
/usr/share/doc/adduser/examples/adduser.local.conf.examples/skel/dot.bashrc
sudo -s Atom /directory
I changed in all files PS1="...." to PS1="hallo". Terminal prompt shows no difference.
Linux Kernel
Mint
4.8.0-53-generic
greetings ! B
source ~/.bashrc
Your terminal only reads the .bashrc on opening, or when you explicitly source it.
I fixed it by editing the .bashrc file in my /home/myusername directory. Don't edit the files here /src/skel

Sudo command not found when change PATH

I have problem with sudo command when i changed $PATH
Problem:
-bash: id: command not found
-bash: tty: command not found
-bash: uname: command not found
[root#ol6 ~]# sudo
-bash: sudo: command not found
And echo $PATH
[root#ol6 ~]# echo $PATH
/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/sbin:/sbin:$PATH:/opt/jdk1.8.0_66/bin:/opt/jdk1.8.0_66/jre/bin
Could you tell me solve this problem.
thanks sm.
sudo is located in /usr/bin on RedHat, but I think your real problem is that you single-quoted $PATH when you altered your PATH and got a literal $PATH in it instead of what you intended!
You somehow got the literal string $PATH in your PATH variable, when you probably meant to add some stuff before and after it. I imagine you did this by using single quotes when assigning:
PATH='/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/sbin:/sbin:$PATH:/opt/jdk1.8.0_66/bin:/opt/jdk1.8.0_66/jre/bin'
when you should have used double quotes
PATH="/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/sbin:/sbin:$PATH:/opt/jdk1.8.0_66/bin:/opt/jdk1.8.0_66/jre/bin"
so the $PATH would expand to its current value (though it's too late for that in your current shell).
Anyway, for me, sudo is in /usr/bin so if you don't have that in your path you won't be able to run it without specifying the full path.

Why still says no GOPATH though i've set it?

Both GoSublime and vim-go tells me that GOPATH isn't set, however I've already done this.
my ~/.bashrc:
export GOPATH=$HOME/gopath
export PATH="$PATH:$GOPATH/bin"
and I can use go get to install gocode to my ~/gopath/bin
but it prints that: ...:/home/myusrname/gopath/bin: No such file or directory
for
~$ $PATH
~$ $PATH
is trying to execute your $PATH string, i.e. it's equivalent to writing the contents of the $PATH variable into the console and pressing enter. That results in the error you're seeing.
What you want is
~$ echo $PATH
finally i got it: i have to open gvim through shell with $GOPATH set - -!
You can try to start gvim with the command:
bash -lc gvim
It then starts gvim with the settings in your .bashrc file.
This is from https://github.com/fatih/vim-go/issues/468
In my case, I added GOPATH in my .profile
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
And restart my Unbuntu 16.04
Then for my vim-go, I installed the vim-go by the following command in gvim
:GoInstallBinaries

Bash: Invalidated commands

I've incurred a worrisome issue with my bash shell. I was editing my bash_profile and accidentally exported an incomplete command (export PATH=/usr/local/bin). After I had reloaded my terminal, nearly all of my bash commands fail to work properly. When I try to run any one of them, the errors state: command not found.
How do I fix this? Is there an alternate way to open or find my bash_profile?
I would appreciate any immediate input I can get on this issue. Thank you in advance.
You can execute commands if you can give the directory name. Almost all the basic Unix commands are under the /bin or /usr/bin directory. For example, /bin/mv.
Fortunately, builtin commands are still recognizable.
Move your .bash_profile and .bashrc file out of the way for now, and see what the system default is.
You can manually edit your PATH on the command line to:
$ PATH="/bin:/usr/bin"
$ cd
$ mv .bash_profile .bash_profile.bak
$ mv .bashrc .bashrc.bak
$ mv .profile .profile.bak
$ mv .bash_login .bash_login.bak
NOTE: Some of these mv command may fail simply because that particular file may not exist.
which will give you access to most of the basic Unix commands. Or you can specify the commands with their full directory names:
$ PATH="/bin:/usr/bin"
$ cd
$ /bin/mv .bash_profile .bash_profile.bak
$ /bin/mv .bashrc .bashrc.bak
$ /bin/mv .profile .profile.bak
$ /bin/mv .bash_login .bash_login.bak
Now, log in again and see what your default $PATH is set to. This is set by the /etc/profile. You might find that's just fine, and remove setting PATH in your startup script.
The standard for PATH is something like this:
/usr/share/bin or /usr/local/bin - These contain non-standard Unix/Linux commands. For example, if you install Maven on your system, the mvn command will usually be located in one of these directories (maybe as a symbolic link). This directory is a place where commands not found in the /bin and /usr/bin directory are stored. This directory is first, so you can replace the version which came with your system with more recent versions. For example, I might have VIM 6.4 installed, but I want to use version 7.3 instead.
/bin:/usr/bin - The standard directories where 99% of the Unix commands live.
$HOME/bin - These are executables you wrote -- either scripts or binaries. This is at the end of the PATH list because it makes sure that you don't accidentally execute the wrong version of the command. Imagine if some joker wrote a shell script called cp that executed /bin/rm instead and placed it in your $HOME/bin directory.
Other directories you'll see may include /sbin/ and /usr/sbin which are administrator commands (ping and ifconfig are sometimes in one of these directories.) /opt/bin/X11 (or wherever the X11 binaries are stored). Sometimes other commands will futz around with your PATH, for example Perlbrew.
#fedorqui's comment provides a quick fix.
The OP could also have used the following to quickly get to a shell with default values for $PATH:
To create a bash shell with a pristine default environment:
without running profile/initialization scripts
without inheriting any environment variables from the current shell
run:
/usr/bin/env -i bash --norc
Note:
Due to use of env's -i option, many environment variables that are normally set will NOT be set in the resulting shell , such as USER, HOME and LANG.
Similarly, the $PATH value you'll get is presumably one hard-coded into bash itself, but it should provide access to at least the standard utilities.
--norc suppresses loading of ~/.bashrc, which normally happens by default for interactive non-login bash shells (bash also supports the --noprofile option to suppress loading of /etc/profile and ~/.bash_profile, but it doesn't apply here, since the shell created is a non-login shell).
If env is in the current shell's $PATH, env -i bash --norc will do.
env is in /usr/bin/ on at least Linux and on FreeBSD/OSX, probably also on other platforms.

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

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

Resources