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. Show
remjg 3,3733 gold badges17 silver badges21 bronze badges asked Dec 5, 2012 at 6:00
To complete existing answers: lsThe 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 --abcNote that the file extension is relevant for the search results too. treeIn 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 -regexoption 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:
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). Then, just type the regular expression ABC* and validate. Every file whose name matches your pattern will be automatically selected. 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 PATTERNHere you can give any regular expression in the PATTERN. For example, to find files with "ab" anywhere within its name, type 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 ABCanswered 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.shNotes:
answered Aug 2, 2019 at 11:02
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:
As you can see I always search in command history by opening a new terminal and hit: CTRL+RIn addition to searching in all folders recursively by writing in any terminal tab: fzfThen start your file name ABCAlso, you can write inside vim :CommandTReally helpful especially in large folders. answered Jan 29, 2018 at 23:18
HMagdyHMagdy 1,3312 gold badges8 silver badges8 bronze badges I use ls | grep abcor ls -la | grep abcIt 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
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
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/ABC123If 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 ABC123Assuming you run the command within the directory in which the files exist. answered Jul 13, 2017 at 7:07
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/etcAnother Example, Also we can write: ls | grep "etc"we get, etcWhat 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.
|