Linux find executable location

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

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

Для создания *.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.

Источник

Читайте также:  Где хранятся настройки пользователя linux

Use “which” in Linux to find the Location of an Exetable

Linux comes with the which command to locate a given executable. Executables are commands you type into your terminal, like git , node , touch , or vim .

Sometimes, you want to find the location of an executable on your filesystem. That’s where the which command comes handy. Read on to find out how to use which !

Ubuntu/Debian Series Overview

  1. Fix “sudo command not found”
  2. Install a Specific Version with apt-get on Ubuntu/Debian
  3. Fix Ubuntu/Debian apt-get “KEYEXPIRED: The following signatures were invalid”
  4. How to Test a Cron Job
  5. How to Unzip Into a Folder
  6. How to Show Your Elasticsearch Version on Ubuntu/Debian
  7. Use “which” in Linux to find the Location of an Exetable
  8. Sort “ls” by Last Changed Date
  9. How to Shutdown a Machine

Locate an Executable in Linux With which

Using which parses the PATH environment variable to find all locations to search for a program.

How to use the which command

The which command has the following syntax:

For example, you may locate the git program like this:

You can also locate more than one program in a single call by adding all programs separated by a space:

$ which git node vim /usr/bin/git /usr/local/bin/node /usr/bin/vim 

Using Options

The which command supports two options:

-a List all instances of executables found (instead of just the first one of each). -s No output, just return 0 if all of the executables are found, or 1 if some were not found. 

If a command is present in multiple locations, you can find all occurrences using the -a option.

Using -s changes the output of which when programs are not found. Let’s say you don’t have MongoDB installed. Trying to locate the mongod executable results in different outputs depending on whether you append the -s option:

$ which mongod # no output at all # and with the “-s” option $ which mongod mongod not found 

The -s option allows you to retrieve expressive results. This is helpful when you as a human runs the command. In shell scripts, you may want to check for empty outputs to determine whether an executable is missing.

Читайте также:  Bluetooth usb adapter linux

Get Notified on New Future Studio
Content and Platform Updates

Get your weekly push notification about new and trending
Future Studio content and recent platform enhancements

Источник

Find out where Unix/Linux executable binary is located

There are two commands that may help you to find where executable binary is located regardless it’s Unix or Linux system. They are whereis and type. First locates source/binary and manuals sections for specified files and second tells what exactly shell executes when you type a certain command.

The next picture shows examples of these commands work.

Find out where Unix/Linux executable binary is located

My name is Stefan, I’m the admin of LinuxScrew. I am a full-time Linux/Unix sysadmin, a hobby Python programmer, and a part-time blogger. I post useful guides, tips, and tutorials on common Linux and Programming issues. Feel free to reach out in the comment section.

1 thought on “Find out where Unix/Linux executable binary is located”

Leave a Comment Cancel reply

SHARE:

RECENT ARTICLES

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.

Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.

Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.

Читайте также:  Arch linux нет русского языка

Источник

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.

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