Which command is used to list all the files and directories start with any character between letter A to letter D?

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.

remjg

3,3733 gold badges17 silver badges21 bronze badges

asked Dec 5, 2012 at 6:00

To complete existing answers:

ls

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.


tree

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.

answered Dec 5, 2012 at 7:42

TakkatTakkat

138k51 gold badges304 silver badges418 bronze badges

6

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

-iname -regex

option with find command to search filename using a pattern

answered Dec 5, 2012 at 6:48

devav2devav2

34.6k16 gold badges78 silver badges82 bronze badges

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.)

answered Dec 5, 2012 at 6:58

YamahoYamaho

4,1732 gold badges15 silver badges17 bronze badges

1

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).

Which command is used to list all the files and directories start with any character between letter A to letter D?

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

Which command is used to list all the files and directories start with any character between letter A to letter D?

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

Which command is used to list all the files and directories start with any character between letter A to letter D?

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

answered Dec 5, 2012 at 15:06

remjgremjg

3,3733 gold badges17 silver badges21 bronze badges

1

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"

answered Jul 11, 2017 at 4:20

1

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

answered Mar 30, 2015 at 11:32

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 /mnt/clone/home/rick/.cache/mozilla/firefox/9fu0cuql.default/cache2/entries/ABC6AD2FEC16465049B48D39FD2FE538258F2A34 /mnt/clone/home/rick/.cache/mozilla/firefox/9fu0cuql.default/cache2/entries/ABCBFDA54262F47253F95ED6ED4131A465EE0E39 /mnt/clone/usr/src/linux-headers-5.0.1-050001/tools/lib/lockdep/tests/ABCABC.sh /mnt/clone/usr/src/linux-headers-5.0.1-050001/tools/lib/lockdep/tests/ABCDBCDA.sh /mnt/clone/usr/src/linux-headers-5.0.1-050001/tools/lib/lockdep/tests/ABCDBDDA.sh /mnt/old/home/rick/.cache/mozilla/firefox/3vkvi6ov.default/cache2/entries/ABC0C99FCEABAD0C6AA2078CD025A1CDE48D7BA1 /usr/src/linux-headers-5.0.1-050001/tools/lib/lockdep/tests/ABCABC.sh /usr/src/linux-headers-5.0.1-050001/tools/lib/lockdep/tests/ABCDBCDA.sh /usr/src/linux-headers-5.0.1-050001/tools/lib/lockdep/tests/ABCDBDDA.sh

Notes:

  • 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.

answered Aug 2, 2019 at 11:02

Which command is used to list all the files and directories start with any character between letter A to letter D?

WinEunuuchs2UnixWinEunuuchs2Unix

95.1k32 gold badges215 silver badges387 bronze badges

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

Which command is used to list all the files and directories start with any character between letter A to letter D?

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

CTRL+R

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

fzf

Then start your file name

ABC

Also, you can write inside vim

:CommandT

Really helpful especially in large folders.

answered Jan 29, 2018 at 23:18

Which command is used to list all the files and directories start with any character between letter A to letter D?

HMagdyHMagdy

1,3312 gold badges8 silver badges8 bronze badges

I use

ls | grep abc

or

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.

answered Jun 17, 2015 at 22:37

Which command is used to list all the files and directories start with any character between letter A to letter D?

Mariano CaliMariano Cali

691 gold badge1 silver badge7 bronze badges

Python:

$ 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:

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

answered Jul 13, 2017 at 3:36

Which command is used to list all the files and directories start with any character between letter A to letter D?

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*

Returns:

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

If you need line breaks after each instance:

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

Returns:

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

"/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*

Returns

ABC ABC123

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

answered Jul 13, 2017 at 7:07

Which command is used to list all the files and directories start with any character between letter A to letter D?

1

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" ./etc ./usr/lib/firefox/bundled/etc ./usr/lib/unix-yarn/etc ./usr/lib/unix/etc ./usr/lib/festival/etc ./usr/bin/lib/vmware-tools/lib64/libconf/etc ./usr/bin/lib/vmware-tools/lib32/libconf/etc ./usr/etc ./usr/share/doc/oddjob-0.30/sample/etc ./usr/share/festival/lib/etc ./usr/local/etc ./usr/java/jdk1.7.0_25/lib/visualvm/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,

etc

What command is used to list files and directories of directories?

Use the ls command to display the contents of a directory. The ls command writes to standard output the contents of each specified Directory or the name of each specified File, along with any other information you ask for with the flags.

What is the command to list all files in a directory?

You can use the DIR command by itself (just type “dir” at the Command Prompt) to list the files and folders in the current directory.

What command do you need to type to list all the files and folders in the directory proc with the letter S in their name?

The ls command lists files and directories within the file system, and shows detailed information about them.

Which command is use to show a list of all files where name starts with either a B or C in the current directory?

dir read *. * lists all files in the current directory that begin with read with any extension.