pogba123 pogba123 - 17 days ago 8
Bash Question

How do i get a list of all the files from a certain directory whos name contains a letters that i supply?

I want to create a command that will give me a list of files from a certain directory based on the pattern of letters i give it. Below is the code that i have at the moment but it for it to work i have to enter the correct filename. And for the output it shows me the full path to the file. Below $1 is the argument (pattern to search for).

find /path/to/directory -name $1 -type f

How would i do it so that all files matching the pattern are displayed and only the file name is displayed (rather than the path to the file).

Answer

You can perhaps add the following besides the doublequotes around $1. Something like this in your script

find . -name "$1" -type f -exec basename {} \;
Comments