A friendly alternative to find in Linux (fd command)

A friendly alternative to find in Linux (fd command)

The fd command provides a simple and straightforward way to search the Linux file system.

fd is a blazingly fast, Rust-based replacement for the Unix/Linux find command. It does not provide all of the powerful features of find. However, it does provide enough functionality to cover 80% of the situations you are likely to encounter. Features such as well-planned and convenient syntax, colored output, smart casing, regular expressions, and parallel command execution make fd a very capable successor.

Install

Go to the fd GitHub page and see the installation section. It covers how to install programs on macOS, Debian/Ubuntu Red Hat, and Arch Linux. Once installed, you can get a complete overview of all available command line options by running help, fd -h for concise help, or fd --help for more detailed help.

Simple search

fd is designed to help you easily find files and folders in your file system. You can perform the simplest search using fd with a single argument, which is whatever you are searching for. For example, suppose you want to find Markdown documents that contain the word services as part of the file name:

$ fd services
downloads/services.md

If called with only one argument, fd recursively searches the current directory for any files and/or directories that match the given argument. An equivalent search using the built-in find command would be:

$ find . -name 'services'
downloads/services.md

As you can see, fd is much simpler and requires less typing. Doing more with less input is always right in my mind.

Files and folders

You can limit the search to files or directories using the -t parameter followed by the letter that represents what you are searching for. For example, to find all files in the current directory that contain services in their filenames, you could use:

$ fd -tf services
downloads/services.md

And, find all directories in the current directory whose file names contain services:

$ fd -td services
applications/services
library/services

How to list all documents with .md extension in the current folder?

$ fd .md
administration/administration.md
development/elixir/elixir_install.md
readme.md
sidebar.md
linux.md

As you can see from the output, fd can not only find and list files in the current folder, but also find files in subfolders. It's very simple.

You can even search for hidden files using the -H switch:

fd -H sessions .
.bash_sessions

Specify a directory

If you want to search a specific directory, the name of the directory can be passed as the second argument to fd:

$ fd passwd /etc
/etc/default/passwd
/etc/pam.d/passwd
/etc/passwd

In this example, we tell fd that we want to search the etc directory for all instances of the word passwd.

Global Search

What if you know part of the file name, but not the folder? Suppose you downloaded a book on Linux network administration, but you don't know where it is saved. No problem:

fd Administration /
/Users/pmullins/Documents/Books/Linux/Mastering Linux Network Administration.epub

Summarize

fd is an excellent replacement for the find command and I'm sure you'll find it as useful as I do. To know more about the command, just browse the man page.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Get the execution time of a program segment using the gettimeofday function in Linux [Recommended]
  • Detailed explanation of fdisk command usage under Linux
  • Example analysis of the conversion between file descriptor fd and file pointer FILE* in Linux
  • Linux new API signalfd, timerfd, eventfd usage instructions
  • Using Linux's timerfd_create to implement a timer example

<<:  MySQL 8.0.11 installation tutorial with pictures and text

>>:  A brief discussion on the implementation principle of Vue slot

Recommend

How to completely uninstall Docker Toolbox

Docker Toolbox is a solution for installing Docke...

Detailed explanation of Vue custom instructions

Table of contents Vue custom directive Custom dir...

17 404 Pages You'll Want to Experience

How can we say that we should avoid 404? The reas...

Mini Program Development to Implement Unified Management of Access_Token

Table of contents TOKEN Timer Refresher 2. Intern...

CSS World--Code Practice: Image Alt Information Presentation

Using the <img> element with the default sr...

Specific use of GNU Parallel

what is it? GNU Parallel is a shell tool for exec...

How to implement responsive layout with CSS

Implementing responsive layout with CSS Responsiv...

This article will show you the principle of MySQL master-slave synchronization

Table of contents Brief Analysis of MySQL Master-...

Pure CSS to achieve cloudy weather icon effect

Effect The effect is as follows ​ Implementation ...

Introduction to MySQL <> and <=> operators

<> Operator Function: Indicates not equal t...

Example code for implementing anti-shake in Vue

Anti-shake: Prevent repeated clicks from triggeri...