Find the name which has specific extension in linux using grep Find the name which has specific extension in linux using grep shell shell

Find the name which has specific extension in linux using grep


You can try the following one:

grep -o '[^?"]*\.css'

-o makes grep output only the matching parts. The pattern just searches for a string of non-question-marks and non-double-quotes that ends in ".css".


With this command you can extract all css files present in your provided sample text/code,

grep -o \/[\-a-zA-Z.0-9]*\.css? sample.txt |tr -d '/?'

Here is the explanations of above command,

grep -o \/[\-a-zA-Z.0-9]*\.css? sample.txt

grep command you will extracting string between / and .css?

tr -d '/?'

tr command here will omits unwanted characters from output such as / and ? .

Here is the output from my console,

enter image description here