Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
fd An Alternative to the Linux find Command
The fd command is a popular alternative to the find command in Linux. It is a faster and more user-friendly version of find, written in Rust for performance. Key features of fd include the ability to search using regular expressions, a more natural syntax for specifying search parameters, and the ability to search using specific file extensions or names.
Installation
The fd command can be installed on Linux and macOS using the package manager of your distribution.
On Debian based distributions
sudo apt-get install fd-find
On Fedora and CentOS
sudo yum install fd-find
On Arch Linux and Manjaro
sudo pacman -S fd
On macOS
brew install fd
Alternatively, you can install fd from source using Cargo
cargo install fd-find
Basic Usage
The basic usage of fd is simpler than the traditional find command. Here are common examples
Finding all files in the current directory
fd
Finding all files with a specific name
fd testfile
Finding all files with a specific extension
fd -e txt
Finding all files that contain a specific string in the name
fd "test file"
Finding all directories
fd -t d
Finding all symbolic links
fd -t l
Advanced Search Criteria
The fd command allows you to specify various search criteria to narrow down your search results
Searching by File Size
Finding files larger than a certain size
fd -S +10M
Finding files smaller than a certain size
fd -S -1K
Using Regular Expressions
Searching using regular expressions
fd '^[a-z].*\.txt$'
This finds all text files that start with a lowercase letter.
Searching in Specific Paths
Searching in a specific directory
fd testfile /path/to/directory
Directory Traversal Control
The fd command allows you to control the depth of directory traversal when searching for files. By default, fd searches recursively through all subdirectories.
Limiting search depth
fd -d 2 -t f
This searches only in the current directory and immediate subdirectories.
Setting minimum depth
fd --min-depth 2 -t f
This searches only in directories that are two levels deep or more.
Combining depth limits
fd --max-depth 3 --min-depth 1 -t f
Symbolic Links and Hidden Files
By default, fd does not follow symbolic links. To follow symbolic links
fd -L -t f
To include hidden files and directories
fd --hidden -t f
To search in ignored directories (like .git or node_modules)
fd --no-ignore -t f
Execute Commands on Results
The fd command allows you to execute commands on search results using the -x or --exec option
Display contents of matching files
fd -e txt -x cat {}
Move matching files to a destination
fd -e log -x mv {} /path/to/backup/
The {} placeholder represents each found file.
Performance Comparison
| Feature | find | fd |
|---|---|---|
| Performance | Standard | Faster (Rust-based) |
| Syntax | Complex | Intuitive |
| Regex Support | Limited | Native |
| Colored Output | No | Yes |
| Git-aware | No | Yes (ignores .gitignore) |
Conclusion
The fd command is a powerful and modern alternative to the traditional find command, offering faster performance and more intuitive syntax. Its regex support, colored output, and Git integration make it an excellent choice for developers and system administrators who frequently search for files in complex directory structures.
