Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List files of particular type from a specific directory

Tags:

file

unix

How to list particular type of files from a specific directory? e.g. I want to list all *.csv files from /home/ABC/files/ directory and I am in /home directory right now.

like image 477
yogsma Avatar asked Jan 20 '11 06:01

yogsma


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
like image 79
ephemient Avatar answered Sep 22 '22 12:09

ephemient


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, the ever useful find.(GNU)

find ABC/file -type f -iname "*.csv" -printf "%f\n"
like image 34
ghostdog74 Avatar answered Sep 20 '22 12:09

ghostdog74


ls ABC/files/*.csv
ls /home/ABC/files/*.csv
like image 21
Ignacio Vazquez-Abrams Avatar answered Sep 19 '22 12:09

Ignacio Vazquez-Abrams