The Cookie Machine - Click here to drag window

DUMMY TEXT - Real text set in assets/js/theCookieMachine.js

If you can read me, I'm broken!

Views: 5,782β€…    Votes:  6β€…
Tags: bash   scripts  
Link: πŸ” See Original Answer on Ask Ubuntu ⧉ πŸ”—

URL: https://askubuntu.com/q/1051609
Title: Running a Bash while loop over all similar files
ID: /2018/07/02/Running-a-Bash-while-loop-over-all-similar-files
Created: July 2, 2018    Edited:  July 3, 2018
Upload: September 15, 2024    Layout:  post
TOC: false    Navigation:  false    Copy to clipboard:  false


From this Stack Overflow answer: List files that only have number in names:

find . -regex '.*/[0-9]+\.tst'

OR

Using find also has advantages when you want to do something with the files, e.g. using the built-in -exec, -print0 and pipe to xargs -0 or even (using Bash):

while IFS='' read -r -d '' file
do
  # ...
done < <(find . -regex '.*/[0-9]+\.tst' -print0)

Note the other answers here my include files that aren’t numbers if the filename starts with a digit. The answer posted here does not though. For example:

$ ls *.tst
12tst.tst  1.tst  2.tst

$ find . -maxdepth 1 -regex '.*/[0-9]+\.tst'
./1.tst
./2.tst

NOTE: Use -maxdepth 1 argument to only list numbered files in the current directory and not in sub-directories.

⇧ Every time I change networks, DNS cache has the wrong IP. How to fix automatically every time? Ubuntu 18.04 Wifi slow on HP Laptop with Intel Centrino Wireless-N 2230 & Realtek RTL8111/8168/8411 PCI  β‡©