snippets/old_snippets/bash-extract-file-name.en.md

38 lines
902 B
Markdown

---
title: "bash extract file name"
seo_description: "How to use basename command to extract just file name from full path"
date: 2022-03-17T15:08:43+01:00
draft: false
snippet_types:
- sh
- bash
---
Comparing the following shows how to use basename to extract just the file name from a full path.
```shell
$ for file in ./content/**/*.md ; do echo $file ; done | head -10
./content/_index.de.md
./content/_index.en.md
./content/_index.ru.md
./content/blog/_index.de.md
./content/blog/_index.en.md
./content/blog/ahrn-valley/index.en.md
./content/blog/archiving-corona-cal/index.en.md
./content/blog/arco/index.de.md
./content/blog/arco/index.en.md
./content/blog/armycookbot/index.de.md
$ for file in ./content/**/*.md ; do file=$(basename $file) && echo $file ; done
_index.de.md
_index.en.md
_index.ru.md
_index.de.md
_index.en.md
index.en.md
index.en.md
index.de.md
index.en.md
index.de.md
```