Recursively find files with a specific extension
My preference:
find . -name '*.jpg' -o -name '*.png' -print | grep Robert
Recursively Find Files With Particular File Extension and Content
What do you mean by keyword? Is that a word, present inside the file? Or is it a part of the filename?
In case it's the part of the filename, you can use file:
in the Windows search, like in following example:
file:*keyword*.py
This will show you all files, called *keyword*.py
. After you've done that, you might change your Windows explorer's view, clicking on the "View" tab and choose "Details", this will also show you the directory where those files are located.
How can I recursively find all files in current and subfolders based on wildcard matching?
Use find
:
find . -name "foo*"
find
needs a starting point, so the .
(dot) points to the current directory.
recursive search of file with specific extension
You want the sum after filtering all the files:
def fileCount(path, extension):
count = 0
for root, dirs, files in os.walk(path):
count += sum(f.endswith(extension) for f in files)
return count
files
returns a list of files so sum(f.endswith(extension) for f in files)
will give you the count of all the files ending with the given extension.
Or just return the sum of all:
def fileCount(path, extension):
return sum(f.endswith(extension) for root, dirs, files in os.walk(path) for f in files)
How can I grep recursively, but only in files with certain extensions?
Just use the --include
parameter, like this:
grep -inr --include \*.h --include \*.cpp CP_Image ~/path[12345] | mailx -s GREP email@domain.example
That should do what you want.
To take the explanation from HoldOffHunger's answer below:
grep
: command-r
: recursively-i
: ignore-case-n
: each output line is preceded by its relative line number in the file--include \*.cpp
: all *.cpp: C++ files (escape with \ just in case you have a directory with asterisks in the filenames)./
: Start at current directory.
How to retrieve recursively any files with a specific extensions in PowerShell?
If sorting by Length is not a necessity, you can use the -Name
parameter to have Get-ChildItem
return just the name, then use [System.IO.Path]::GetFileNameWithoutExtension()
to remove the path and extension:
Get-ChildItem -Path .\ -Filter *.js -Recurse -File -Name| ForEach-Object {
[System.IO.Path]::GetFileNameWithoutExtension($_)
}
If sorting by length is desired, drop the -Name
parameter and output the BaseName
property of each FileInfo
object. You can pipe the output (in both examples) to clip
, to copy it into the clipboard:
Get-ChildItem -Path .\ -Filter *.js -Recurse -File| Sort-Object Length -Descending | ForEach-Object {
$_.BaseName
} | clip
If you want the full path, but without the extension, substitute $_.BaseName
with:
$_.FullName.Remove($_.FullName.Length - $_.Extension.Length)
Related Topics
Argument List Too Long Error For Rm, Cp, Mv Commands
How to Fix 'Sudo: No Tty Present and No Askpass Program Specified' Error
How to Measure the Actual Memory Usage of an Application or Process
Iterate Over a List of Files With Spaces
Defining a Variable With or Without Export
How to Symlink a File in Linux
Use Expect in a Bash Script to Provide a Password to an Ssh Command
How Do the Likely/Unlikely Macros in the Linux Kernel Work and What Is Their Benefit
How to Set the Environmental Variable Ld_Library_Path in Linux
How to 'Grep' a Continuous Stream
Redirect All Output to File in Bash
How to Kill a Process by Name Instead of Pid, on Linux
How to Set the Gopath Environment Variable on Ubuntu? What File Must I Edit
[ :Unexpected Operator in Shell Programming
Edit Shell Script While It's Running
What Is the Maximum Size of a Linux Environment Variable Value