Learn how to Use the ‘fd’ Command in Linux

by | Sep 29, 2023 | Etcetera | 0 comments

The fd command, fast for “uncover list,” is designed to seem and discover files and directories all the way through the filesystem. It’s identified for its simplicity and tempo, making it a favorite among tool administrators and developers alike.

Compared to the usual discover command, fd supplies a further user-friendly syntax and faster search purposes. It’s regularly used for locating specific files, cleaning up directories, or even in automation scripts. Additionally, the fd command will also be paired with other directions like grep for additonal difficult search capacity.

Learn to Arrange the fd Command

fd isn’t normally built-in by the use of default in most Linux distributions, so it is very important arrange it. The arrange process can vary depending on the distribution you’re the usage of. Proper right here’s the way you’ll arrange and uninstall fd on some no longer abnormal distributions:

See also  10 Indicators It’s Time to Pull the Plug on Your Advertising and marketing Marketing campaign

Ubuntu/Debian

To place in fd on Ubuntu or Debian, you’ll use the following command:

sudo apt-get exchange
sudo apt-get arrange fd-find

To uninstall it later, you’ll use:

sudo apt-get remove fd-find

Fedora

On Fedora, you’ll arrange fd with:

sudo dnf arrange fd-find

To uninstall it:

sudo dnf remove fd-find

macOS (the usage of Homebrew)

Whilst you’re on macOS and the usage of Homebrew, you’ll arrange fd with:

brew arrange fd

To uninstall it:

brew uninstall fd

Follow: the package deal deal identify might be fd-find in some package deal deal managers, and also you’ll want to use the command fdfind as an alternative of fd. You’ll alias it to fd by the use of together with alias fd=fdfind on your shell’s configuration report (e.g., .bashrc or .zshrc).

Learn to Use fd

1. Search for Knowledge by the use of Establish

Syntax: fd PATTERN

Explanation: Searches for files and directories with a name matching the given development.

Example: fd 'report.txt'

Output:

/space/individual/bureaucracy/report.txt
/space/individual/archive/report.txt

The command searches for all occurrences of report.txt inside the provide list and its subdirectories, file the whole paths to the files.

2. Search for Knowledge with a Specific Extension

Syntax: fd '.*EXTENSION'

Explanation: Searches for files with a selected extension.

Example: fd '.*.pdf'

Output:

/space/individual/bureaucracy/file1.pdf
/space/individual/bureaucracy/file2.pdf

The command searches for all PDF files inside the provide list and its subdirectories.

3. Search for Knowledge Modified inside the Ultimate N Days

Syntax: fd --changed-within 'Nd'

Explanation: Searches for files and directories replaced all the way through the last N days.

Example: fd --changed-within '7d'

Output:

/space/individual/bureaucracy/week_report.docx
/space/individual/pictures/recent_image.jpg

The command lists all files and directories replaced all the way through the last 7 days.

4. Search for Directories Best possible

Syntax: fd --type d PATTERN

Explanation: Searches for directories with a name matching the given development.

See also  What HubSpot’s Best Appearing Weblog Posts Have in Commonplace & Why Those Components Paintings

Example: fd --type d 'tasks'

Output:

/space/individual/construction/tasks
/space/individual/design/tasks

The command searches for all directories named tasks inside the provide list and its subdirectories.

5. Search for Knowledge Apart from Positive Directories

Syntax: fd --exclude DIR PATTERN

Explanation: Searches for files and directories matching the rage, with the exception of specified directories.

Example: fd --exclude 'archive' 'report.txt'

Output:

/space/individual/bureaucracy/report.txt

The command searches for report.txt then again excludes any results from the “archive” list.

6. Search for Knowledge More than a Specific Measurement

Syntax: fd --size '+SIZE'

Explanation: Searches for files higher than a specified duration.

Example: fd --size '+1M'

Output:

/space/individual/films/large_video.mp4
/space/individual/track/big_album.flac

The command lists all files higher than 1 megabyte inside the provide list and its subdirectories.

7. Search for Knowledge and Execute a Command on Them

Syntax: fd PATTERN -x COMMAND

Explanation: Searches for files matching the rage and executes a specified command on them.

Example: fd '.*.txt' -x cat

Output:

Contents of file1.txt
Contents of file2.txt

The command searches for all text files and then runs the cat command on them, appearing their contents.

8. Search for Knowledge in a Case-Insensitive Method

Syntax: fd --ignore-case PATTERN

Explanation: Searches for files and directories matching the rage, ignoring case.

Example: fd --ignore-case 'readme'

Output:

/space/individual/README
/space/individual/tasks/readme.md

The command searches for all occurrences of readme inside the provide list and its subdirectories, ignoring the case.

9. Search for Knowledge The usage of a Not unusual Expression

Syntax: fd --regex 'REGEX'

Explanation: Searches for files and directories matching a given not unusual expression.

Example: fd --regex '^a.*.txt$'

Output:

/space/individual/bureaucracy/a_file.txt
/space/individual/bureaucracy/another_file.txt

The command searches for all text files inside the provide list and its subdirectories that get began with the letter a.

10. Search for Knowledge with Specific Permissions

Syntax: fd --perm PERMISSIONS

Explanation: Searches for files with specific permissions.

See also  Highest Adobe Choice Apps

Example: fd --perm 755

Output:

/space/individual/scripts/executable_script.sh

The command searches for files with permissions set to 755 (be told, write, and execute for the owner; be told and execute for the group and others).

Further Linux directions:
Checklist Operations rmdir · cd · pwd
Document Operations cat · cp · dd · much less · ls · mkdir · mv · tail · tar · zip
Document Machine Operations chown · mkfs
Networking ping · curl · wget · iptables
Search and Text Processing discover · grep · sed · whatis
Machine Wisdom and Regulate env · historical past · best · who
Particular person and Session Regulate display · su · sudo

The put up Learn how to Use the ‘fd’ Command in Linux gave the impression first on Hongkiat.

WordPress Website Development

Supply: https://www.hongkiat.com/blog/linux-command-fd/

[ continue ]

WordPress Maintenance Plans | WordPress Hosting

read more

0 Comments

Submit a Comment

DON'T LET YOUR WEBSITE GET DESTROYED BY HACKERS!

Get your FREE copy of our Cyber Security for WordPress® whitepaper.

You'll also get exclusive access to discounts that are only found at the bottom of our WP CyberSec whitepaper.

You have Successfully Subscribed!