List of files of a certain type from a specific directory

How to specify a specific type of files from a specific directory? for example, I want to list all * .csv files from the directory / home / ABC / files /, and now I'm in / home.

+4
source share
3 answers

TMTOWTDI .

(cd /home/ABC/files/; ls *.csv) ls /home/ABC/files/*.csv | sed 's:.*/::' ls /home/ABC/files/*.csv | xargs -n1 basename ls /home/ABC/files/*.csv | rev | cut -d/ -f1 | rev for i in /home/ABC/files/*.csv; do echo "${i##*/}"; done 
+7
source
 ls ABC/files/*.csv ls /home/ABC/files/*.csv echo ABC/files/*.csv echo /home/ABC/files/*.csv 

using for loop

 for file in ABC/files/*.csv do # further processing done 

and, of course, always a useful find. (GNU)

 find ABC/file -type f -iname "*.csv" -printf "%f\n" 
+4
source
 ls ABC/files/*.csv ls /home/ABC/files/*.csv 
+3
source

Source: https://habr.com/ru/post/1336269/


All Articles