{"id":2747,"date":"2025-12-23T11:37:03","date_gmt":"2025-12-23T10:37:03","guid":{"rendered":"https:\/\/artheodoc.fr\/?page_id=2747"},"modified":"2025-12-23T11:37:03","modified_gmt":"2025-12-23T10:37:03","slug":"rechercher-des-fichiers-avec-locate","status":"publish","type":"page","link":"https:\/\/artheodoc.fr\/index.php\/rechercher-des-fichiers-avec-locate\/","title":{"rendered":"Rechercher des fichiers avec locate"},"content":{"rendered":"\n<p>Utilisation : Recherche rapide de fichiers en utilisant une base de donn\u00e9es pr\u00e9-index\u00e9e (plus rapide que find, mais moins flexible).<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Syntaxe de base<\/h1>\n\n\n\n<p>locate [option] \u00ab\u00a0motif\u00a0\u00bb<\/p>\n\n\n\n<p>Rechercher un fichier par son nom&nbsp;:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">locate \"nom_du_fichier.txt\"<\/pre>\n\n\n\n<p>Pour rechercher tous les fichiers .pdf dans \/home\/dominique, de mani\u00e8re insensible \u00e0 la casse&nbsp;:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">locate -i \"\/home\/dominique\/*.pdf\"<\/pre>\n\n\n\n<p><strong>Remarques importantes<\/strong><\/p>\n\n\n\n<p>Base de donn\u00e9es&nbsp;: locate utilise une base de donn\u00e9es mise \u00e0 jour p\u00e9riodiquement (g\u00e9n\u00e9ralement via cron). Pour forcer une mise \u00e0 jour manuelle&nbsp;:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo updatedb<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">Tableau r\u00e9capitulatif<\/h1>\n\n\n\n<p>Voici un tableau r\u00e9capitulatif des options les plus utiles de la commande locate en Bash, avec des exemples d&rsquo;utilisation&nbsp;:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th><strong>Option<\/strong><\/th><th><strong>Description<\/strong><\/th><th><strong>Exemple<\/strong><\/th><\/tr><\/thead><tbody><tr><td>(aucune option)<\/td><td>Recherche un fichier ou dossier dans la base de donn\u00e9es.<\/td><td>locate \u00ab\u00a0fichier.txt\u00a0\u00bb<\/td><\/tr><tr><td><code>-i<\/code><\/td><td>Recherche insensible \u00e0 la casse.<\/td><td>locate -i \u00ab\u00a0fichier.TXT\u00a0\u00bb<\/td><\/tr><tr><td><code>-b<\/code><\/td><td>Ne recherche que les chemins existants (ignore les liens symboliques cass\u00e9s).<\/td><td>locate -b \u00ab\u00a0\/chemin\/valide\u00a0\u00bb<\/td><\/tr><tr><td><code>-c<\/code><\/td><td>Compte le nombre de r\u00e9sultats trouv\u00e9s.<\/td><td>locate -c \u00ab\u00a0*.pdf\u00a0\u00bb<\/td><\/tr><tr><td><code>-l N<\/code><\/td><td>Limite le nombre de r\u00e9sultats \u00e0 N.<\/td><td>locate -l 10 \u00ab\u00a0fichier\u00a0\u00bb<\/td><\/tr><tr><td><\/td><td>Utilise une expression r\u00e9guli\u00e8re pour la recherche.<\/td><td>locate fichier[0-9].txt<\/td><\/tr><tr><td><code>-e<\/code><\/td><td>N&rsquo;affiche que les fichiers existants (v\u00e9rifie en temps r\u00e9el).<\/td><td>locate -e \u00ab\u00a0fichier_important\u00a0\u00bb<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">les Jockers<\/h1>\n\n\n\n<p>La commande locate sous Linux n&rsquo;utilise pas directement les expressions r\u00e9guli\u00e8res (ni BRE ni ERE). Elle est con\u00e7ue pour rechercher des fichiers ou des r\u00e9pertoires dans une base de donn\u00e9es pr\u00e9-construite, en se basant sur des motifs de noms de fichiers.<\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Fonctionnement de locate<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Base de donn\u00e9es\u00a0: locate utilise une base de donn\u00e9es mise \u00e0 jour r\u00e9guli\u00e8rement (via updatedb), ce qui la rend tr\u00e8s rapide.<\/li>\n\n\n\n<li>Recherche par motif\u00a0: Elle utilise des jokers (wildcards) similaires \u00e0 ceux du shell, et non des expressions r\u00e9guli\u00e8res.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Syntaxe des motifs avec locate<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th><strong>Joker<\/strong><\/th><th><strong>Signification<\/strong><\/th><\/tr><\/thead><tbody><tr><td>*<\/td><td>Correspond \u00e0 n&rsquo;importe quelle cha\u00eene de caract\u00e8res (y compris vide).<\/td><\/tr><tr><td>?<\/td><td>Correspond \u00e0 un seul caract\u00e8re (n&rsquo;importe lequel).<\/td><\/tr><tr><td>[&#8230;]<\/td><td>Correspond \u00e0 un caract\u00e8re parmi ceux list\u00e9s (ex: [abc]).<\/td><\/tr><tr><td>[!&#8230;]<\/td><td>Correspond \u00e0 un caract\u00e8re non list\u00e9 (ex: [!abc]).<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Exemples d&rsquo;utilisation<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th><strong>Besoin<\/strong><\/th><th><strong>Commande avec locate<\/strong><\/th><\/tr><\/thead><tbody><tr><td>Trouver tous les fichiers contenant \u00ab\u00a0test\u00a0\u00bb<\/td><td>locate \u00ab\u00a0*test*\u00a0\u00bb<\/td><\/tr><tr><td>Trouver les fichiers commen\u00e7ant par \u00ab\u00a0doc\u00a0\u00bb<\/td><td>locate \u00ab\u00a0doc*\u00a0\u00bb<\/td><\/tr><tr><td>Trouver les fichiers se terminant par \u00ab\u00a0.txt\u00a0\u00bb<\/td><td>locate \u00ab\u00a0*.txt\u00a0\u00bb<\/td><\/tr><tr><td>Trouver les fichiers avec un caract\u00e8re inconnu<\/td><td>locate fichier?.txt (ex: \u00ab\u00a0fichier1.txt\u00a0\u00bb)<\/td><\/tr><tr><td>Trouver les fichiers avec un caract\u00e8re dans une liste<\/td><td>locate fichier[1-3].txt (ex: fichier1.txt, fichier2.txt)<\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Utilisation : Recherche rapide de fichiers en utilisant une base de donn\u00e9es pr\u00e9-index\u00e9e (plus rapide que find, mais moins flexible). Syntaxe de base locate [option] \u00ab\u00a0motif\u00a0\u00bb Rechercher un fichier par son nom&nbsp;: locate \u00ab\u00a0nom_du_fichier.txt\u00a0\u00bb Pour rechercher tous les fichiers .pdf dans \/home\/dominique, de mani\u00e8re insensible \u00e0 la casse&nbsp;: locate -i \u00ab\u00a0\/home\/dominique\/*.pdf\u00a0\u00bb Remarques importantes Base de [&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-2747","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/artheodoc.fr\/index.php\/wp-json\/wp\/v2\/pages\/2747","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=2747"}],"version-history":[{"count":1,"href":"https:\/\/artheodoc.fr\/index.php\/wp-json\/wp\/v2\/pages\/2747\/revisions"}],"predecessor-version":[{"id":2748,"href":"https:\/\/artheodoc.fr\/index.php\/wp-json\/wp\/v2\/pages\/2747\/revisions\/2748"}],"wp:attachment":[{"href":"https:\/\/artheodoc.fr\/index.php\/wp-json\/wp\/v2\/media?parent=2747"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}