{"id":3241,"date":"2026-07-07T14:34:47","date_gmt":"2026-07-07T12:34:47","guid":{"rendered":"https:\/\/artheodoc.fr\/?page_id=3241"},"modified":"2026-07-07T16:23:48","modified_gmt":"2026-07-07T14:23:48","slug":"localiser-lemplacement-du-fichier-executable-dune-commande-avec-which","status":"publish","type":"page","link":"https:\/\/artheodoc.fr\/index.php\/localiser-lemplacement-du-fichier-executable-dune-commande-avec-which\/","title":{"rendered":"Localiser l\u2019emplacement du fichier ex\u00e9cutable d\u2019une commande avec which"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\"><strong>Description<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">La commande <strong><code>which<\/code><\/strong> permet de <strong>localiser l\u2019emplacement du fichier ex\u00e9cutable<\/strong> d\u2019une commande donn\u00e9e dans les r\u00e9pertoires list\u00e9s dans la variable d\u2019environnement <strong><code>$PATH<\/code><\/strong>.<br>Elle affiche le <strong>chemin absolu<\/strong> de l\u2019ex\u00e9cutable appel\u00e9 quand vous tapez une commande dans le terminal.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\u26a0\ufe0f <strong><code>which<\/code> ne fonctionne que pour les ex\u00e9cutables<\/strong> (binaires, scripts) et <strong>non pour les alias, fonctions shell, ou commandes internes<\/strong> (comme <code>cd<\/code>, <code>echo<\/code>, etc.).<\/p>\n<\/blockquote>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\ud83d\udccc Syntaxe<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>which &#91;OPTIONS] &#91;--] COMMANDE...<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\ud83c\udf9b\ufe0f Options principales<\/strong><\/h4>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Option<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><strong><code>-a<\/code><\/strong><\/td><td>Affiche <strong>toutes<\/strong> les correspondances dans <code>$PATH<\/code> (et non seulement la premi\u00e8re).<\/td><\/tr><tr><td><strong><code>--skip-alias<\/code><\/strong><\/td><td>Ignore les alias (par d\u00e9faut, <code>which<\/code> peut les afficher).<\/td><\/tr><tr><td><strong><code>--skip-dot<\/code><\/strong><\/td><td>Ignore les r\u00e9pertoires <code>.<\/code> (courant) dans <code>$PATH<\/code>.<\/td><\/tr><tr><td><strong><code>--skip-tilde<\/code><\/strong><\/td><td>Ignore les r\u00e9pertoires <code>~<\/code> (home) dans <code>$PATH<\/code>.<\/td><\/tr><tr><td><strong><code>--show-dot<\/code><\/strong><\/td><td>Affiche explicitement <code>.<\/code> si la commande est trouv\u00e9e dans le r\u00e9pertoire courant.<\/td><\/tr><tr><td><strong><code>--show-tilde<\/code><\/strong><\/td><td>Affiche explicitement <code>~<\/code> si la commande est trouv\u00e9e dans le r\u00e9pertoire home.<\/td><\/tr><tr><td><strong><code>-v<\/code>, <code>--version<\/code><\/strong><\/td><td>Affiche la version de <code>which<\/code>.<\/td><\/tr><tr><td><strong><code>--help<\/code><\/strong><\/td><td>Affiche l\u2019aide.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\ud83d\udca1 Exemples d\u2019utilisation<\/strong><\/h4>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>1. Localiser une commande simple<\/strong><\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>which ls<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Sortie possible :<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/bin\/ls<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>2. Trouver toutes les occurrences d\u2019une commande<\/strong><\/h5>\n\n\n\n<pre class=\"wp-block-preformatted\"><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>which -a python<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Sortie possible :<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/usr\/bin\/python\n\/usr\/local\/bin\/python<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>3. V\u00e9rifier si une commande existe<\/strong><\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>which nonexistent_command<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Sortie possible :<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>which: no nonexistent_command in (\/usr\/local\/bin:\/usr\/bin:\/bin:\/usr\/local\/sbin:\/usr\/sbin)<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\u274c <strong>Aucun chemin affich\u00e9<\/strong> = la commande n\u2019est pas dans <code>$PATH<\/code>.<\/p>\n<\/blockquote>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>4. Utiliser avec plusieurs commandes<\/strong><\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>which ls cp mv<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Sortie possible :<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/bin\/ls\n\/bin\/cp\n\/bin\/mv<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\ud83d\udd0d Cas d\u2019usage typiques<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u2705 <strong>V\u00e9rifier o\u00f9 est install\u00e9 un programme<\/strong> (ex: <code>node<\/code>, <code>python<\/code>, <code>git<\/code>).<br>\u2705 <strong>D\u00e9boguer des probl\u00e8mes de <code>PATH<\/code><\/strong> (ex: pourquoi une commande n\u2019est pas trouv\u00e9e).<br>\u2705 <strong>V\u00e9rifier les conflits de versions<\/strong> (ex: <code>\/usr\/bin\/python<\/code> vs <code>\/usr\/local\/bin\/python<\/code>).<br>\u2705 <strong>Automatiser des scripts<\/strong> (ex: v\u00e9rifier qu\u2019une d\u00e9pendance est install\u00e9e).<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u26a0\ufe0f Limitations et alternatives<\/strong><\/h4>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Probl\u00e8me<\/th><th>Solution<\/th><\/tr><\/thead><tbody><tr><td><strong><code>which<\/code> ne trouve pas les alias ou fonctions shell<\/strong><\/td><td>Utilisez <strong><code>type<\/code><\/strong> ou <strong><code>command -v<\/code><\/strong> (built-in Bash).<\/td><\/tr><tr><td><strong><code>which<\/code> ne cherche que dans <code>$PATH<\/code><\/strong><\/td><td>Utilisez <strong><code>whereis<\/code><\/strong> pour chercher aussi dans <code>\/usr\/share\/man<\/code>, <code>\/usr\/share\/info<\/code>, etc.<\/td><\/tr><tr><td><strong>Besoin de plus de d\u00e9tails (permissions, type de fichier)<\/strong><\/td><td>Utilisez <strong><code>command -V<\/code><\/strong> ou <strong><code>file $(which COMMANDE)<\/code><\/strong>.<\/td><\/tr><tr><td><strong>Rechercher dans des r\u00e9pertoires non standard<\/strong><\/td><td>Modifiez <code>$PATH<\/code> ou utilisez <code>find<\/code>\/<code>locate<\/code>.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>\ud83d\udd04 Alternatives \u00e0 <code>which<\/code><\/strong><\/h5>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Commande<\/th><th>Description<\/th><th>Exemple<\/th><\/tr><\/thead><tbody><tr><td><strong><code>type<\/code><\/strong><\/td><td>Affiche le type (alias, fonction, fichier) <strong>et le chemin<\/strong> si ex\u00e9cutable.<\/td><td><code>type ls<\/code> \u2192 <code>ls is aliased to 'ls --color=auto'<\/code><\/td><\/tr><tr><td><strong><code>command -v<\/code><\/strong><\/td><td>Similaire \u00e0 <code>type -P<\/code> (affiche le chemin ou rien).<\/td><td><code>command -v python<\/code> \u2192 <code>\/usr\/bin\/python<\/code><\/td><\/tr><tr><td><strong><code>whereis<\/code><\/strong><\/td><td>Cherche dans <code>$PATH<\/code>, <code>\/usr\/share\/man<\/code>, <code>\/usr\/share\/info<\/code>.<\/td><td><code>whereis python<\/code> \u2192 <code>python: \/usr\/bin\/python \/usr\/share\/man\/man1\/python.1.gz<\/code><\/td><\/tr><tr><td><strong><code>which -a<\/code><\/strong><\/td><td>Affiche toutes les occurrences dans <code>$PATH<\/code>.<\/td><td><code>which -a gcc<\/code> \u2192 <code>\/usr\/bin\/gcc<\/code><\/td><\/tr><tr><td><strong><code>readlink -f $(which COMMANDE)<\/code><\/strong><\/td><td>Affiche le <strong>chemin absolu r\u00e9solu<\/strong> (sans liens symboliques).<\/td><td><code>readlink -f $(which python)<\/code> \u2192 <code>\/usr\/bin\/python3.10<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\ud83d\udcdd Notes importantes<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>which<\/code> est une commande externe<\/strong> (g\u00e9n\u00e9ralement <code>\/usr\/bin\/which<\/code> ou <code>\/bin\/which<\/code>).<\/li>\n\n\n\n<li><strong>Elle d\u00e9pend de <code>$PATH<\/code><\/strong> : Si un r\u00e9pertoire n\u2019est pas dans <code>$PATH<\/code>, <code>which<\/code> ne le cherchera pas.<\/li>\n\n\n\n<li><strong>Elle ignore les commandes internes du shell<\/strong> (comme <code>cd<\/code>, <code>echo<\/code>, <code>exit<\/code>).<br>\u2192 Utilisez <code>type<\/code> ou <code>help<\/code> pour ces cas.<\/li>\n\n\n\n<li><strong>Sous Linux, <code>which<\/code> peut \u00eatre remplac\u00e9 par <code>command -v<\/code><\/strong> (plus portable et int\u00e9gr\u00e9e \u00e0 Bash).<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\ud83d\udee0\ufe0f Exemple avanc\u00e9 : V\u00e9rifier si une commande existe dans un script<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>if command -v git &gt;\/dev\/null 2&gt;&amp;1; then\n    echo \"Git est install\u00e9 en : $(command -v git)\"\nelse\n    echo \"Git n'est pas install\u00e9 ou n'est pas dans \\$PATH.\"\nfi<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\u2705 <strong><code>command -v<\/code> est plus fiable que <code>which<\/code> dans les scripts<\/strong> (\u00e9vite les probl\u00e8mes de portabilit\u00e9).<\/p>\n<\/blockquote>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\ud83d\udcda Pour aller plus loin<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Man page<\/strong> : <code>man which<\/code> (Linux\/macOS).<\/li>\n\n\n\n<li><strong>Documentation GNU<\/strong> : <a href=\"https:\/\/www.gnu.org\/software\/which\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/www.gnu.org\/software\/which\/<\/a><\/li>\n\n\n\n<li><strong>Variable <code>$PATH<\/code><\/strong> : <code>echo $PATH<\/code> pour voir les r\u00e9pertoires recherch\u00e9s.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Voir \u00e9galement<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/artheodoc.fr\/index.php\/la-commande-ldd-list-dynamic-dependencies-sous-bash\/\" data-type=\"page\" data-id=\"3247\" target=\"_blank\" rel=\"noreferrer noopener\">La commande ldd (List Dynamic Dependencies) sous Bash<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Description La commande which permet de localiser l\u2019emplacement du fichier ex\u00e9cutable d\u2019une commande donn\u00e9e dans les r\u00e9pertoires list\u00e9s dans la variable d\u2019environnement $PATH.Elle affiche le chemin absolu de l\u2019ex\u00e9cutable appel\u00e9 quand vous tapez une commande dans le terminal. \u26a0\ufe0f which ne fonctionne que pour les ex\u00e9cutables (binaires, scripts) et non pour les alias, fonctions shell, [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"class_list":["post-3241","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/artheodoc.fr\/index.php\/wp-json\/wp\/v2\/pages\/3241","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/artheodoc.fr\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/artheodoc.fr\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/artheodoc.fr\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/artheodoc.fr\/index.php\/wp-json\/wp\/v2\/comments?post=3241"}],"version-history":[{"count":4,"href":"https:\/\/artheodoc.fr\/index.php\/wp-json\/wp\/v2\/pages\/3241\/revisions"}],"predecessor-version":[{"id":3254,"href":"https:\/\/artheodoc.fr\/index.php\/wp-json\/wp\/v2\/pages\/3241\/revisions\/3254"}],"wp:attachment":[{"href":"https:\/\/artheodoc.fr\/index.php\/wp-json\/wp\/v2\/media?parent=3241"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}