简体   繁体   中英

linux ls command to list file with certain characters in filename

I have files with name 145345000_abcd_20211201 100045430_abcd_20211130 143240000_abcd_20211129

in this ( abcd ) remains constant rest of the numbers in beginning and timestamp at the end changes every day. i want to list all such files in a txt file I am doing the following ls ${mypath}/ > ${mypath}/my_list.txt

this will list all files and folder in mypath where I want only file with ( abcd ) in file name please guide. i Have tried many combinations already

Use grep to filter the files with abcd like this:

ls ${mypath}/ | grep abcd > ${mypath}/my_list.txt

Alternatively, you can use ls only like this:

ls -1 ${mypath}/*abcd* > ${mypath}/my_list.txt

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