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?
23 Answers
It seems like your PATH environment variable was corrupted.
You can find vim in /usr/bin/vim
$ which vim
/usr/bin/vimIn /usr/bin you should find also vi and gedit
nano can be found in /bin
$ which nano
/bin/nanosudo can be found in /usr/bin
$ which sudo
/usr/bin/sudoNotes:
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.
6
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.
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:/binthen 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/environmentThen 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/.bashrcHope this helps!
1Using 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.740sYou 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/vimNotes:
/etc/alternatives/vimis the alternative system in play/usr/bin/X11/vimappears because/usr/bin/X11is 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, zcatYep, that includes vi.