Linux get path to executable

How can I find the system PATH in linux for any executable? (ubuntu distro) [duplicate]

I have tried using the command: echo $PATH, but I get a path that I do not recognize as an actual directory on my machine: «/home/user_name/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games» If I want to install a new program into the correct directory, how can I find the system PATH using the Terminal?

2 Answers 2

Well, these are the paths. Executables (Binary or Scripts with executable bit and valid bang-path) need to be placed there to be able to be executed without prepending a specific location.

Your problem is that you do not understand UNIX paths at all.

/home/user_name/bin /usr/local/sbin /usr/local/bin 

The colon : is used to separate paths when concatenating them within a string! So, in contrast to «windows» C:foo would mean: two paths (C and foo in the Unix/Linux world)

And I am pretty sure that all these different paths exist on your system.

And for that other implied question: determining the correct directory for a new executable might very much depend on your that new thing.

When you wrote a little script for yourself, you would typically put it into ~/bin. But things that should be used by other users might go to /usr/local/bin for example. For more details on that part; turn to the «duplicated» question suggested to you

Источник

Как узнать путь до исполняемого файла в Linux?

Как в Linux узнать путь до исполняемого файла? В виндовс, например, на ярлыке или в bin/app.exe можно через свойство посмотреть Интересуюсь с целью создавать *.desktop ярлыки для заполнениями ими рабочего стола 🗔, так как способ «добавить в избранное» мне не подходит и получается рабочий стол пустой 😔

Читайте также:  Системное программное обеспечение операционные системы windows linux mac os

Для создания *.desktop нет необходимости указывать полный путь. Посмотрите примеры в /usr/share/applications

3 ответа 3

Я по факту могу найти приложение в диспетчере приложений, можно ли как-то оттуда взять этот путь? Или лучше и правильнее поискать путь к .exe в папках типа как в Windows —> C/Program FIles/app_folder/bin/app.exe ?

Внизу слева есть кнопка «Показать приложения», я про это имел в виду, оттуда бы как-то брать пути, там же ярлыки и их на рабочий стол хочу закидывать : )

Если вы знаете имя исполняемого файла, который выполняется в текущий момент, то полный путь к исполняемому можно узнать вот так:

pgrep | while read pid; do echo -ne "$pid\t"; readlink -f /proc/$pid/exe; done 

Например, вывод для исполняемого процесса gopls (сервер go для VS Code):

pgrep gopls | while read pid; do echo -ne "$pid\t"; readlink -f /proc/$pid/exe; done 30880 /mnt/drive2/home2/user/go/bin/gopls 

Набрав в командной строке

whereis locates the binary, source and manual files for the specified command names. The supplied names are first stripped of leading pathname components and any (single) trailing extension of the form .ext (for example: .c) Prefixes of s. resulting from use of source code control are also dealt with. whereis then attempts to locate the desired program in the standard Linux places, and in the places specified by $PATH and $MANPATH.

Источник

How to find application’s path from command line?

For example, I have git installed on my system. But I don’t remember where I installed it, so which command is fit to find this out?

Just in case, command -v and which worked in Linux Alpine 3.16.2 (Docker image). whereis and locate did not — not installed.

Читайте также:  Linux scripting if exist

5 Answers 5

If it is in your path, then you can run either type git or which git . The which command has had problems getting the proper path (confusion between environment and dot files). For type , you can get just the path with the -p argument.

If it is not in your path, then it’s best to look for it with locate -b git It will find anything named ‘git’. It’ll be a long list, so might be good to qualify it with locate -b git | fgrep -w bin .

I use locate endlessly (it is very fast), but for those unaware of it, locate is only as up to date as its most recent database update, which is automatically run daily on my Ubuntu. The refresh command is sudo updatedb . Also locate has built-in regex capability, so commands like this works: locate -br «^git$» . -b` means restrict the search to just the basename . or without the -b , it searches the full pathname .. Also, it only searches paths you have configured it to search.. there is no command-line control of this other than your regex filters.

@Gilles, that’s funny for me the behavior is exactly the opposite: type is a shell builtin that tells me aliases and such, and which is an external program that shows me the path to an executable. although if there’s a builtin that gets in the way that executable won’t get called.

@quodlibetor The problems with which are that it doesn’t know about shell built-ins and functions (which is relevant when you’re wondering what typing the command will do), and it uses a different $PATH on some systems.

Читайте также:  Узнать версию криптопро линукс

Источник

Оцените статью
Adblock
detector