【Bash 檔案處理 #1】Linux terminal 取得 (資料夾內) 所有的檔案名稱 (bash get all file, bash glob, parse file)

前言

我們在 python 裡面有類似 glob 或 os.walk 的方式,
能夠快速取得「在一個特定資料夾底下的所有檔案路徑」,
我們現在想要用單純的 bash script 來實現這一件事情,
我們這裡來示範如何達成。

利用 bash 達成,對指定目標路徑底下的檔案搜索

#!/bin/bash
TARGET="/home/ubuntu/Desktop"

for each_file in "$search_dir"$TARGET/*
do
    echo "$each_file" 
done

利用 bash 達成,類似 glob 效果的正規表達式

#!/bin/bash
TARGET="/home/ubuntu/Desktop"

for each_file in "$search_dir"$TARGET/*
do
    echo "$each_file" 
done

Reference