I need to search for files starting with some particular name. There can be multiple files starting with a particular pattern and I want to list all such files present in the directory.

12 Answers 12


To complete existing answers:


The default directory list utility ls can be used in combination with the shell's wildcards . To search for all files with pattern abc:

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

Note that the file extension is relevant for the search results too.


In case we need to list files in a directory tree we can also issue tree to search for a given pattern like:

tree -P 'abc*'  # list directory tree of file starting with abc---
tree -l 'def*'  # exclude files starting with def---

In this case, tree itself supports wildcards.

  • 2
    Why when I do ls -l B* does it show the contents of all directories starting with B instead of just the names of the matching directories?
    – ErikE
    Commented Jan 24, 2018 at 23:24
  • 1
    @ErikE Because when you ask ls to list a directory, it opens it, it's the same as doing ls -l BirthdayPhotos. You can suppress that behavior with ls -d B*. Commented Apr 17, 2018 at 17:23
  • @AzorAhai But why does it treat B* as a directory specification?
    – ErikE
    Commented Apr 17, 2018 at 17:24
  • @ErikE Because using the file glob B* expands to match all directories that start with B so you're really passing ls a list of directories, so it opens them all for you. Commented Apr 17, 2018 at 17:26
  • 3
    Does not answer the question. ls -d ABC* was what the author was asking about. Also comments in the code snippet are wrong, ls abc* lists content of directories starting with abc.
    – greatvovan
    Commented Apr 11, 2019 at 18:38

You can use find command to search files with pattern

find . -type f -name "abc*" 

The above command will search the file that starts with abc under the current working directory.

-name 'abc' will list the files that are exact match. Eg: abc

You can also use


option with find command to search filename using a pattern


There are many ways to do it, depending on exactly what you want to do with them. Generally, if you want to just list them, you can do it in a terminal using:

find | grep '^\./ABC'

... and replacing ABC with your text.

To understand the command, let's break it down a bit:

  • find lists all files under the current directory and its sub-directories; using it alone will just list everything there. Note that find outputs each file or directory starting with ./, indicating that their path is relative to the current directory. Being aware of this is important because it means we will search for results starting with ./ABC and not just ABC.

  • The pipe character | redirects the output of one command to another, in this case the output of find is redirected to grep. This is called piping.

  • grep takes the output and filters it using the given pattern, ^\./ABC.

    • Notice that the pattern is quoted with single quotes ' ' to prevent the shell from interpreting the special characters inside it.
  • Now the pattern itself is written in a particular syntax called regular expression, or regex for short. Regex is an extremely powerful searching tool if you master it, and there are sites such as this which teach you about it in more depth, but note that grep is not a full-fledged regex engine and you can't do everything with it.

  • For our purpose:

    • ^ in regex matches the beginning of the string; this prevents it from matching the pattern if it doesn't occur in the beginning of the file name.

    • . in regex has a special meaning too: it means "match any single character here". In case you want to use it as a literal dot, you'll have to "escape" it using a backslash \ before it. (Yeah, matching any character would be harmless in our case, but I did it for completeness' sake.)

  • 3
    Why would you find | grep when find has its own perfectly good pattern-matching capabilities?
    – Darael
    Commented Jul 11, 2017 at 11:26

You can search for a particular pattern using the Nautilus file manager and regular expressions.

To do so, click on Select Items Matching in the Gear menu like below (you can also press Ctrl+s).

enter image description here

Then, just type the regular expression ABC* and validate.

enter image description here

Every file whose name matches your pattern will be automatically selected.

enter image description here

I'm using Nautilus 3.6.* from GNOME3 PPA on Ubuntu 12.10 (Quantal).

  • this is a powerful answer. Still valid today 2021 Commented Feb 11, 2021 at 8:44

The easiest solution to me

ls | grep PATTERN

Here you can give any regular expression in the PATTERN.

For example, to find files with "ab" anywhere within its name, type

ls | grep ".*ab.*"

To find the files starting with "ab", type

ls | grep "^ab"
  • it takes forever for me and i am trying to get video file names with for example (1990) find . -maxdepth 1 | grep -R "\(\d\d\d\d\)" Commented Feb 11, 2021 at 8:43

If you don't know the directory the ABC* files are located in, and you have millions of files, the locate command is the fastest method.

$ locate /ABC


  • The above command takes 1 second to run on 1 million files.
  • In comparison the find command starting at / root directory will a very long time and generate many permission errors.
  • If files were created today you must run sudo updatedb first.

you can use GREP, I think this is the most simple solution, probably also add some other grep parameters to make the match more accurate

tree | grep ABC

Command-t in one of my favorite vim plugins, it's ruby based plugin above integration with FZF.

By using Comamnd-T and FZF you can do the search with an extremely fast "fuzzy" mechanism for:

  • Opening files and buffers
  • Jumping to tags and help
  • Running commands, or previous searches and commands
  • with a minimal number of keystrokes.

As you can see

enter image description here

I always search in command history by opening a new terminal and hit:


In addition to searching in all folders recursively by writing in any terminal tab:


Then start your file name


Also, you can write inside vim


Really helpful especially in large folders.


I use

ls | grep abc


ls -la | grep abc

It show all files with abc, not just starting with abc. But, It's a really easy way for me for to do this.



$ python -c 'import sys,os;found=[os.path.join(r,i) for r,s,f in os.walk(".") for i in f if i.startswith("ABC")];map(lambda x: sys.stdout.write(x+"\n") ,found)'


$ perl -le 'use File::Find;find(sub{ -f && $_ =~/^ABC/ && print $File::Find::name  },".")' 
printf "%s" /path/to/files/ABC*

This is glob pattern matching which is anchored at both ends. This will match all occurrences of files starting with "ABC" such as "ABC", "ABC.txt", "ABC123", but not "xABC". From the command line using 'ls' in place of 'printf' here is a safe alternative however, depending on who's opinion you agree with, 'ls' is not safe for use in a script. In that case using 'printf' with glob pattern matching is considered safe. If you going to use this in a script the output of 'printf' will not contain a new line character until the end of the output stream as such:

printf "%s" /path/to/files/ABC*  


/path/to/files/ABC /path/to/files/ABC123

If you need line breaks after each instance:

printf "%s\n" /path/to/files/ABC*




"/path/to/files/" remains in the output if you entered it that way when you ran the 'printf' command. Without it just the file name appears:

printf "%s" ABC* 



Assuming you run the command within the directory in which the files exist.

  • The echo /path/to/files/ABC* | tr " " "\n" isn't a good idea. Consider if there's a file /path/to/files/ABC EFG , there is a space in the filename. Your tr will break the filename into two separate lines, which is not good. Even worse if there's multiple spaces in filename. I'd recommend you use printf "%s\n" ABC* instead, which should help with spaces in the filenames, but still is problematic with other special characters like \n Commented Jul 13, 2017 at 7:14

Assume that I am at the root directory and I want the list of the etc directory only: we write,

find -type d -name "etc"

result we get,

[root@unix /]# find -type d -name "etc"

./home/user1/Desktop/VMware Tools/vmware-tools-distrib/lib/lib64/libconf/etc
./home/user1/Desktop/VMware Tools/vmware-tools-distrib/lib/lib32/libconf/etc
./home/user1/Desktop/VMware Tools/vmware-tools-distrib/etc
./home/user1/Desktop/VMware Tools/vmware-tools-distrib/caf/etc

Another Example,

Also we can write:

ls | grep "etc"

we get,


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .