Linux which analog windows

Команды type, which, whereis, whatis и locate

Команда type позволяет выяснить, содержится ли некоторая команда в системе, и определить тип данной команды. Команда также сообщает, является ли название команды действительным и где именно в системе находится эта команда:

$ type echo echo встроена в оболочку $ type ls ls является алиасом для 'ls --color=auto' $ type rm rm является /bin/rm $ type wc wc является /usr/bin/wc

Команда which

Команда which выводит полный путь до команды, если она находится в пути поиска $PATH . Команда which показывает первую найденную команду в переменной $PATH . Если надо проверить существование нескольких совпадений, используется опция -a :

$ which echo /bin/echo $ which ls /bin/ls $ which wc /usr/bin/wc

Команда whereis

Команда whereis позволяет найти не только исполняемые файлы, но и файлы документации и конфигурации. Выполняет поиск в ограниченном количестве каталогов, например в каталогах стандартных двоичных файлов, каталогах библиотек и в каталогах man .

$ whereis awk /usr/bin/awk /usr/share/man/man1/awk.1.gz $ whereis sed /bin/sed /usr/share/man/man1/sed.1.gz /usr/share/info/sed.info.gz

Команда whatis

Команда whatis показывает краткую информацию о команде из ее man-страницы.

$ whatis rm rm (1) - remove files or directories $ whatis awk awk (1) - pattern scanning and text processing language

Команда locate

Команда locate выполняет поиск по базе данных имен файлов, хранящейся в Linux. Для получения актуальных результатов, необходимо регулярно обновлять базу данных со списком имен файлов. Чаще всего ОС настроена таким образом, что обновление будет выполняться автоматически. Если обновление по умолчанию отключено, можно обновить базу данных вручную:

  • -q — позволяет скрыть сообщения об ошибках (например, нет доступа к файлу)
  • -n — позволяет ограничить количество возвращаемых результатов
  • -c — позволяет узнать количество файлов, соответствующих заданному критерию поиска
  • -i — позволяет провести поиск файлов без учета регистра
$ locate .php -n 10 # первые 10 файлов с расширением .php $ locate .html -i # поиск html-файлов без учета регистра

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Читайте также:  Linux limits conf open files

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

  • 1С:Предприятие (31)
  • API (29)
  • Bash (43)
  • CLI (99)
  • CMS (139)
  • CSS (50)
  • Frontend (75)
  • HTML (66)
  • JavaScript (150)
  • Laravel (72)
  • Linux (143)
  • MySQL (76)
  • PHP (125)
  • React.js (66)
  • SSH (27)
  • Ubuntu (66)
  • Web-разработка (509)
  • WordPress (73)
  • Yii2 (69)
  • БазаДанных (95)
  • Битрикс (66)
  • Блог (29)
  • Верстка (43)
  • ИнтернетМагаз… (84)
  • КаталогТоваров (87)
  • Класс (30)
  • Клиент (27)
  • Ключ (28)
  • Команда (68)
  • Компонент (60)
  • Конфигурация (59)
  • Корзина (32)
  • ЛокальнаяСеть (28)
  • Модуль (34)
  • Навигация (31)
  • Настройка (137)
  • ПанельУправле… (29)
  • Плагин (33)
  • Пользователь (26)
  • Практика (99)
  • Сервер (74)
  • Событие (27)
  • Теория (104)
  • Установка (65)
  • Файл (47)
  • Форма (58)
  • Фреймворк (192)
  • Функция (36)
  • ШаблонСайта (68)

Источник

What is Windows’ equivalent of the «which» command in Unix? Is there an equivalent PowerShell command?

In Linux, we have the «which» command to find out the path of an executable.
What is its Windows equivalent? Is there any PowerShell command for doing that?

6 Answers 6

Newer versions of Windows (I think Windows 2003 and up) have the where command:

C:\>where ping C:\Windows\System32\PING.EXE 

And for PowerShell, explicitly add the .exe suffix:

PS C:\>where.exe ping C:\Windows\System32\PING.EXE 

where /r c:\ fileName adding the /r c:\ allowed me to perform a recursive search starting at the root of the C drive using Windows 7 Professional it seems to not be in access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/…

in Powershell you should say where.exe ping because where is by default aliased to Where-Object cmdlet which is completely different story

Читайте также:  Simply linux от альтов

Yes, Get-Command will find all commands including executables:

If you want to limit the commands to just executables:

PS\> Get-Command -CommandType Application 

Will find all exes in your path. There is an alias for interactive use:

PS\> gcm net* -CommandType Application 

To get the path of an executable, you can use the Path property of the returned object. For example:

PS\> (Get-Command notepad.exe).Path 

For more info, run man Get-Command -full .

where.exe explicitly rather than where works for me in PowerShell:

PS C:\Users\birdc> where ping PS C:\Users\birdc> where.exe ping C:\Windows\System32\PING.EXE 

In addition to user10404, the help command will work on aliases, so you can use the same command name (gcm) for help and interactive use:

help gcm -Parameter * # or man gcm -Par * 

If you want to make it short, create a one line which.cmd file with the content

This will search the first parameter (%1) fed to the script and display the full path of found file. Good place to put this script in windows 10 is %LOCALAPPDATA%\Microsoft\WindowsApps\which.cmd

And you get your which command in path.

c:\>which cmd.exe c:\>echo C:\Windows\System32\cmd.exe C:\Windows\System32\cmd.exe 

Источник

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