Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

linux

shell

ls

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"


1 Answers

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.

like image 150
hek2mgl Avatar answered Sep 17 '25 17:09

hek2mgl