user11518995
user11518995

Reputation:

How to search for files ending/starting/containing a certain letter in terminal?

I have been looking all over the internet to help me with this. I want to list all files that start/end/contain a certain letter but the results I found on the internet do not seem to work for me. I need to use the ls command for this (assignment).

I tried this code from another question:

ls abc*   # list all files starting with abc---
ls *abc*  # list all files containing --abc--
ls *abc   # list all files ending with --abc

but when ever I try any of those it comes back with "ls: cannot access '*abc': No such file or directory"

Upvotes: 4

Views: 12865

Answers (1)

hek2mgl
hek2mgl

Reputation: 158080

Use find for finding files:

find /path/to/folder -maxdepth 1 -type f -name 'abc*' 

This will give you all regular filenames within /path/to/folder which start with abc.

Upvotes: 2

Related Questions