{"id":2230,"date":"2022-06-08T20:11:22","date_gmt":"2022-06-08T17:11:22","guid":{"rendered":"https:\/\/artem.services\/?p=2228"},"modified":"2022-06-08T20:25:29","modified_gmt":"2022-06-08T17:25:29","slug":"2230","status":"publish","type":"post","link":"https:\/\/artem.services\/?p=2230&lang=en","title":{"rendered":"\u00a0Linux &#8212; Get path and filename from full path"},"content":{"rendered":"<p><img loading=\"lazy\" class=\"size-medium wp-image-568 aligncenter\" src=\"https:\/\/artem.services\/wp-content\/uploads\/2019\/01\/BASH-Logo-300x127.png\" alt=\"\" width=\"300\" height=\"127\" srcset=\"https:\/\/artem.services\/wp-content\/uploads\/2019\/01\/BASH-Logo-300x127.png 300w, https:\/\/artem.services\/wp-content\/uploads\/2019\/01\/BASH-Logo.png 376w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>To extract a file path or filename from a full path, you can use various utilities like <strong>grep<\/strong>, <strong>sed<\/strong>, <strong>awk<\/strong>, <strong>etc<\/strong>. If it&#8217;s not a list from a file or variable, you can use <strong>find<\/strong>, but there&#8217;s an easier way:<\/p>\n<ul>\n<li><strong>basename<\/strong> &#8212; returns the filename<\/li>\n<li><strong>dirname<\/strong> &#8212; returns the path to the file<\/li>\n<\/ul>\n<h3>Example:<\/h3>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nbasename \/home\/artem\/file.txt\r\nfile.txt\r\n\r\ndirname \/home\/artem\/file.txt\r\n\/home\/artem\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>These two utilities are included in the <strong>coreutils<\/strong> package<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; To extract a file path or filename from a full path, you can use various utilities like grep, sed, awk, etc. If it&#8217;s not a list from a file or variable, you can use find, but there&#8217;s an easier way: basename &#8212; returns the filename dirname &#8212; returns the path to the file Example: &hellip; <a href=\"https:\/\/artem.services\/?p=2230&#038;lang=en\" class=\"more-link\">\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u0447\u0438\u0442\u0430\u0442\u044c<span class=\"screen-reader-text\"> &quot;\u00a0Linux &#8212; Get path and filename from full path&quot;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[415,341],"tags":[1799,427,1801,1803,371,1557],"_links":{"self":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/2230"}],"collection":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2230"}],"version-history":[{"count":3,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/2230\/revisions"}],"predecessor-version":[{"id":2235,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/2230\/revisions\/2235"}],"wp:attachment":[{"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2230"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2230"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2230"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}