How can I find where the vim executable is located when my PATH is broken?
Solution 1
It seems like your PATH
environment variable was corrupted.
You can find vim
in /usr/bin/vim
$ which vim
/usr/bin/vim
In /usr/bin
you should find also vi
and gedit
nano
can be found in /bin
$ which nano
/bin/nano
sudo
can be found in /usr/bin
$ which sudo
/usr/bin/sudo
Notes:
As mentioned by @SorenA and @PatrickMevzek search for a location of a file can also be done using whereis
As mentioned by @Terrance - whereis vim
finds all names with like vim in the name, Note that most of the results aren't the vim
executable.
man which
- locate a command - It does this by searching the PATH for executable files matching the names of the arguments.
man whereis
- whereis then attempts to locate the desired program in the standard Linux places, and in the places speci‐fied by $PATH and $MANPATH.
Solution 2
Since your PATH is corrupted the useful executables are in the /usr/bin
and /bin
folders. From a terminal type in
export PATH=/usr/bin:/bin
then you should be able to run sudo vim
without the need to type in the paths in front of the names.
The following commands will restore the /etc/environment
file and the ~/.bashrc
file.
This command will put the path statement back in /etc/environment
:
sudo bash -c 'echo "PATH=\"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games\"" > /etc/environment'
Then you can source the file so the PATH statement sets:
. /etc/environment
Then get a default .bashrc
file and put it back in your home folder:
sudo cp /etc/skel/.bashrc /home/$USER/.bashrc
sudo chown $USER:$USER /home/$USER/.bashrc
Hope this helps!
Solution 3
Using pure bash, you could run a search for things named vim
:
$ shopt -s globstar
$ time echo /**/vim
/etc/alternatives/vim /etc/vim /usr/bin/vim /usr/bin/X11/vim /usr/share/cmake-3.5/editors/vim /usr/share/vim /var/lib/dpkg/alternatives/vim /var/lib/vim
real 0m4.145s
user 0m0.740s
You could then loop over the results to see which are executable:
$ time for v in /**/vim; do [[ -x $v && -f $v ]] && echo "$v"; done
/etc/alternatives/vim
/usr/bin/vim
/usr/bin/X11/vim
Notes:
-
/etc/alternatives/vim
is the alternative system in play -
/usr/bin/X11/vim
appears because/usr/bin/X11
is a symbolic link to/usr/bin
, so everything in the latter appears in the former. Why are there infinitely many x11 subdirectories in /usr/bin/x11?
With various breakages in Ubuntu, there's a single command that can help with a lot of things: /bin/busybox
. Remembering just this one gets you access to a lot more:
$ /bin/busybox
BusyBox v1.22.1 (Ubuntu 1:1.22.0-15ubuntu1) multi-call binary.
BusyBox is copyrighted by many authors between 1998-2012.
Licensed under GPLv2. See source distribution for detailed
copyright notices.
Usage: busybox [function [arguments]...]
or: busybox --list[-full]
or: busybox --install [-s] [DIR]
or: function [arguments]...
BusyBox is a multi-call binary that combines many common Unix
utilities into a single executable. Most people will create a
link to busybox for each function they wish to use and BusyBox
will act like whatever it was invoked as.
Currently defined functions:
[, [[, acpid, adjtimex, ar, arp, arping, ash, awk, basename, blockdev,
brctl, bunzip2, bzcat, bzip2, cal, cat, chgrp, chmod, chown, chpasswd,
chroot, chvt, clear, cmp, cp, cpio, crond, crontab, cttyhack, cut,
date, dc, dd, deallocvt, depmod, devmem, df, diff, dirname, dmesg,
dnsdomainname, dos2unix, dpkg, dpkg-deb, du, dumpkmap, dumpleases,
echo, ed, egrep, env, expand, expr, false, fdisk, fgrep, find, fold,
free, freeramdisk, fstrim, ftpget, ftpput, getopt, getty, grep, groups,
gunzip, gzip, halt, head, hexdump, hostid, hostname, httpd, hwclock,
id, ifconfig, ifdown, ifup, init, insmod, ionice, ip, ipcalc, kill,
killall, klogd, last, less, ln, loadfont, loadkmap, logger, login,
logname, logread, losetup, ls, lsmod, lzcat, lzma, lzop, lzopcat,
md5sum, mdev, microcom, mkdir, mkfifo, mknod, mkswap, mktemp, modinfo,
modprobe, more, mount, mt, mv, nameif, nc, netstat, nslookup, od,
openvt, passwd, patch, pidof, ping, ping6, pivot_root, poweroff,
printf, ps, pwd, rdate, readlink, realpath, reboot, renice, reset, rev,
rm, rmdir, rmmod, route, rpm, rpm2cpio, run-parts, sed, seq,
setkeycodes, setsid, sh, sha1sum, sha256sum, sha512sum, sleep, sort,
start-stop-daemon, stat, static-sh, strings, stty, su, sulogin,
swapoff, swapon, switch_root, sync, sysctl, syslogd, tac, tail, tar,
taskset, tee, telnet, telnetd, test, tftp, time, timeout, top, touch,
tr, traceroute, traceroute6, true, tty, tunctl, udhcpc, udhcpd, umount,
uname, uncompress, unexpand, uniq, unix2dos, unlzma, unlzop, unxz,
unzip, uptime, usleep, uudecode, uuencode, vconfig, vi, watch,
watchdog, wc, wget, which, who, whoami, xargs, xz, xzcat, yes, zcat
Yep, that includes vi
.
Related videos on Youtube
vico
Updated on September 18, 2022Comments
-
vico over 1 year
Looks like I crashed my system after editing
/etc/environment
and.bashrc
files.My desktop doesn't start and I need to correct these files back. But since my system doesn't find any commands I need to use the whole path.
Where I can find the vim executable so I can run it with its full path?
-
Olorin over 6 years@pa4080 none of those commands will work with a problematic
PATH
, except maybe the one answer about aliases, and that won't help here. -
pa4080 over 6 yearsHi, @Olorin, I'm agree and retracted my suggestion. Actually
PATH= which vim
produces:-bash: which: No such file or directory
. I already saw your answer and I think it should be the accepted one.
-
-
Patrick Mevzek over 6 yearsor
whereis
that checks standard directories (which
checks directories in user's$PATH
so depending on how it is set up some locations may be missed) -
Terrance over 6 yearsDon't update your answer.
whereis
finds all names with likevim
in the name. I see one that says/etc/vim
and if you try to run it it says that it is a directory. Whereis locates where which finds the executable that is in the path. -
Soren A over 6 yearsIf
which
doesn't work, because PATH variable has been corrupted,whereis
is a usefull alternative. Start looking in /bin and /usr/bin - you find most things there, if you still hasn't found your exec, use whereis. -
vico over 6 yearsfound vim, but can't find sudo , since I need permitions. Where is sudo?
-
Zanna over 6 years
which which
... -
Olorin over 6 yearsNeither
whereis
norwhich
would be runnable without knowing their path. Both are in/usr/bin
, wherevim
resides, so ifvim
can't be found, then these can't be either. -
Olorin over 6 yearsThis is the best possible solution - reset to a sane default
PATH
for your current shell.