The fd
command, quick for “discover listing,” is designed to look and find recordsdata and directories throughout the filesystem. It’s recognized for its simplicity and pace, making it a favourite amongst device directors and builders alike.
In comparison to the standard discover
command, fd
provides a extra user-friendly syntax and quicker seek functions. It’s often used for finding explicit recordsdata, cleansing up directories, and even in automation scripts. Moreover, the fd
command can also be paired with different instructions like grep
for extra complicated seek capability.
Learn how to Set up the fd
Command
fd
isn’t generally integrated via default in maximum Linux distributions, so it is important to set up it. The set up procedure can range relying at the distribution you’re the use of. Right here’s how you’ll set up and uninstall fd
on some not unusual distributions:
Ubuntu/Debian
To put in fd
on Ubuntu or Debian, you’ll use the next command:
sudo apt-get replace sudo apt-get set up fd-find
To uninstall it later, you’ll use:
sudo apt-get take away fd-find
Fedora
On Fedora, you’ll set up fd
with:
sudo dnf set up fd-find
To uninstall it:
sudo dnf take away fd-find
macOS (the use of Homebrew)
When you’re on macOS and the use of Homebrew, you’ll set up fd
with:
brew set up fd
To uninstall it:
brew uninstall fd
Observe: the package deal title could be fd-find
in some package deal managers, and you’ll wish to use the command fdfind
as a substitute of fd
. You’ll alias it to fd
via including alias fd=fdfind
in your shell’s configuration document (e.g., .bashrc
or .zshrc
).
Learn how to Use fd
1. Seek for Information via Identify
Syntax: fd PATTERN
Clarification: Searches for recordsdata and directories with a reputation matching the given trend.
Instance: fd 'file.txt'
Output:
/house/person/paperwork/file.txt /house/person/archive/file.txt
The command searches for all occurrences of file.txt
within the present listing and its subdirectories, record the total paths to the recordsdata.
2. Seek for Information with a Particular Extension
Syntax: fd '.*EXTENSION'
Clarification: Searches for recordsdata with a particular extension.
Instance: fd '.*.pdf'
Output:
/house/person/paperwork/file1.pdf /house/person/paperwork/file2.pdf
The command searches for all PDF recordsdata within the present listing and its subdirectories.
3. Seek for Information Changed within the Remaining N Days
Syntax: fd --changed-within 'Nd'
Clarification: Searches for recordsdata and directories changed throughout the closing N days.
Instance: fd --changed-within '7d'
Output:
/house/person/paperwork/week_report.docx /house/person/footage/recent_image.jpg
The command lists all recordsdata and directories changed throughout the closing 7 days.
4. Seek for Directories Best
Syntax: fd --type d PATTERN
Clarification: Searches for directories with a reputation matching the given trend.
Instance: fd --type d 'initiatives'
Output:
/house/person/building/initiatives /house/person/design/initiatives
The command searches for all directories named initiatives
within the present listing and its subdirectories.
5. Seek for Information Aside from Sure Directories
Syntax: fd --exclude DIR PATTERN
Clarification: Searches for recordsdata and directories matching the trend, apart from specified directories.
Instance: fd --exclude 'archive' 'file.txt'
Output:
/house/person/paperwork/file.txt
The command searches for file.txt
however excludes any effects from the “archive” listing.
6. Seek for Information Greater than a Particular Dimension
Syntax: fd --size '+SIZE'
Clarification: Searches for recordsdata better than a specified length.
Instance: fd --size '+1M'
Output:
/house/person/movies/large_video.mp4 /house/person/tune/big_album.flac
The command lists all recordsdata better than 1 megabyte within the present listing and its subdirectories.
7. Seek for Information and Execute a Command on Them
Syntax: fd PATTERN -x COMMAND
Clarification: Searches for recordsdata matching the trend and executes a specified command on them.
Instance: fd '.*.txt' -x cat
Output:
Contents of file1.txt Contents of file2.txt
The command searches for all textual content recordsdata after which runs the cat
command on them, showing their contents.
8. Seek for Information in a Case-Insensitive Approach
Syntax: fd --ignore-case PATTERN
Clarification: Searches for recordsdata and directories matching the trend, ignoring case.
Instance: fd --ignore-case 'readme'
Output:
/house/person/README /house/person/initiatives/readme.md
The command searches for all occurrences of readme
within the present listing and its subdirectories, ignoring the case.
9. Seek for Information The use of a Common Expression
Syntax: fd --regex 'REGEX'
Clarification: Searches for recordsdata and directories matching a given common expression.
Instance: fd --regex '^a.*.txt$'
Output:
/house/person/paperwork/a_file.txt /house/person/paperwork/another_file.txt
The command searches for all textual content recordsdata within the present listing and its subdirectories that get started with the letter a
.
10. Seek for Information with Particular Permissions
Syntax: fd --perm PERMISSIONS
Clarification: Searches for recordsdata with explicit permissions.
Instance: fd --perm 755
Output:
/house/person/scripts/executable_script.sh
The command searches for recordsdata with permissions set to 755
(learn, write, and execute for the landlord; learn and execute for the crowd and others).
Extra Linux instructions:
Listing Operations | rmdir · cd · pwd |
Record Operations | cat · cp · dd · much less · ls · mkdir · mv · tail · tar · zip |
Record Gadget Operations | chown · mkfs |
Networking | ping · curl · wget · iptables |
Seek and Textual content Processing | discover · grep · sed · whatis |
Gadget Knowledge and Control | env · historical past · best · who |
Person and Consultation Control | display · su · sudo |
The publish Learn how to Use the ‘fd’ Command in Linux seemed first on Hongkiat.
WordPress Website Development Source: https://www.hongkiat.com/blog/linux-command-fd/