简体   繁体   中英

Linux: 'ls' all jpg files recursively in csv

I'm trying to find a way to list all jpg images in all subdirectories and in csv format without the dir name present.

ls -R -1 -m . | grep '.jpg'

The ls command does output to csv fine, but the grep command breaks the csv format making each file appear on a new line instead of comma seperated.

I know I can use 'find' to list images but it seems to output the files in a different order than 'ls' and I don't see a output to csv parameter for 'find'

I need the images in each subdirectory on 1 comma seperated line.

I believe this does what you want. Each outputted line is a list of jpgs in a single directory separated by commas.

ls -d */ | xargs -i{} sh -c 'cd {};ls -m *jpg'

If you wanted to know which line was which directory you could run it in 2 steps like this

ls -d */ > dirs.txt 
cat dirs.txt | xargs -i{} sh -c 'cd {};ls -m *txt'

and then the first line in dirs.txt would correspond to each line of output.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM