Need to find files quickly using a search pattern? The *
(asterisk/star) is your wildcard hero! It's used in command lines, programming, and even GUI file managers to match any sequence of characters.
π§ 1. Command Line (Shell / CMD)
The *
wildcard helps list or find files easily.
π§ Unix/Linux/macOS
bash
ls * # lists all files and folders
ls *.txt # lists all files ending in .txt
ls data* # matches files like data.csv, data1.txt, data_report.pdf
πͺ Windows Command Prompt
cmd
dir * # lists all files and folders
dir *.jpg # lists all .jpg files
dir file*.* # matches file.txt, file123.csv, file_report.docx
π 2. In Programming (e.g., Python with glob
)
Use glob
for file pattern matching in scripts.
python
import glob
# Get all .txt files in current directory
for file in glob.glob("*.txt"):
print(file)
Or recursively:
python
import glob
# Get all .java files in subdirectories too
for file in glob.glob("**/*.java", recursive=True):
print(file)
π» 3. Java File Search Using *
Java doesn't directly support glob with *
via File
, but you can use java.nio.file
:
java
import java.io.IOException;
import java.nio.file.*;
import java.util.stream.Stream;
public class FileSearchExample {
public static void main(String[] args) throws IOException {
Path dir = Paths.get(".");
try (Stream<Path> stream = Files.newDirectoryStream(dir, "*.txt").stream()) {
stream.forEach(System.out::println);
}
}
}
Or use Files.walk
+ endsWith
:
java
Files.walk(Paths.get("."))
.filter(path -> path.toString().endsWith(".txt"))
.forEach(System.out::println);
ποΈ 4. File Managers
Many GUI file explorers (Windows, macOS Finder, Linux file managers) support *
:
*.pdf
β finds all PDFsreport*
β finds report1.docx, report_final.pdf*log*
β matches any file with "log" in its name
β
Summary
ContextExampleDescriptionShell/CMDls *.txt
All .txt
filesPython (glob
)glob("*.csv")
Matches all .csv
filesJavanewDirectoryStream("*.log")
Files ending in .log
GUI File Manager*data*
All files with "data" in name
The *
wildcard means βmatch anythingββso itβs your go-to for flexible file filtering.