Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shell command to find files in a directory pattern

With a shell command i need to list all files on my server in the following directory pattern:

/home/*/public_html/images/*.php

Theres a few an its taking a long time to do this manually. I really have no idea when it comes to these commands.

like image 532
Grant Unwin Avatar asked Jan 02 '11 23:01

Grant Unwin


People also ask

What command is used to search files for a pattern?

The grep command can search for a string in groups of files. When it finds a pattern that matches in more than one file, it prints the name of the file, followed by a colon, then the line matching the pattern.

How do I search for a file in shell?

The first option is the “-name” option to search for a file with its name in double inverted commas. You can utilize this option alongside the path to some directory to search for a file. If you don't want to utilize the path, leave it with “.” as we did below.

How do I list files in a directory in Bash?

To see a list of all subdirectories and files within your current working directory, use the command ls .

How do I find a pattern in a file in Linux?

If you want to search for a pattern in files, use grep (1). find (1) is usually used to find files with a given pattern in filename. But find will search the directory hierarchy whereas grep is just looking in the single directory.

How to search for files in a directory using find command?

The path... attribute defines the starting directory or directories where find will search the files. The expression attribute is made up of options, search patterns, and actions separated by operators. To search for files in a directory, the user invoking the find command needs to have read permissions on that directory.

How do I search for a pattern in a group of files?

Using find command to search a pattern in group of files Hi find ../ -name "*.csh" grep ABC {} ; -print If you want to search for a pattern in files, use grep(1). But find will search the directory hierarchy whereas grep is just looking in the single directory. find .

Does the find command filter the directories traversed to reach the file?

This does not filter on the directories traversed to reach the file. If the files are in subdirectories of the parent directory (e.g. ../a_foo/wibble.csv ), you don't need find: the find command is only useful to search directory trees recursively. You can use echo or ls:


1 Answers

find /path/to/directory/.  -path "*/match/this/path/*" -type f -name "*.php"
like image 66
karthik m Avatar answered Sep 21 '22 15:09

karthik m