Skip to content

Instantly share code, notes, and snippets.

@akliuxingyuan
Last active June 13, 2021 12:07
Show Gist options
  • Save akliuxingyuan/174c537e0ceec1f89e8954737c34d413 to your computer and use it in GitHub Desktop.
Save akliuxingyuan/174c537e0ceec1f89e8954737c34d413 to your computer and use it in GitHub Desktop.

fd example

--type

fd sh --type f
fd sh --type f --type l

Filter search by type:

f, file

regular files

d, directory

directories

l, symlink

symbolic links

x, executable

executable (files)

e, empty

empty files or directories

s, socket

sockets

p, pipe

named pipes (FIFOs)

This option can be used repeatedly to allow for multiple file types.

-H (--hidden) & -i (--ignore-case)

fd -Hi '.*\.ttf' '/usr/share/fonts'

-H : Search hidden files and directories

-i : Case-insensitive search

-e (--extension)

fd -e conf --base-directory /etc

-E (--exclude)

fd -Hie conf -E BackUP -E .config

-S (--size)

fd -S=+1Gi # search file which size bigger than or equal 1GiB
fd -S=-10Mi # search file which size smaller than or equal 10MiB
fd -S=1B # search file which size exactly 1Byte

'b' bytes

'k' kilobytes (base ten, 10^3 = 1000 bytes)

'm' megabytes

'g' gigabytes

't' terabytes

'ki' kibibytes (base two, 2^10 = 1024 bytes)

'mi' mebibytes

'gi' gibibytes

'ti' tebibytes

-x (--exec) & -X (--exec-batch)

fd -Hi '.*\.ttf$' '/usr/share/fonts' -X sh -c '
for file in "$@"
do
	ln -sf "$file" "${file##*/}"
done' sh {}
# sh {} is better than just {}
fd -Hi '.*\.ttf$' '/usr/share/fonts' -x ln -sf {} {/}
fd -Hi '.*\.ttf$' '/usr/local/share/fonts' -X sh -c '
for file do
    echo ln -sf "$file" "${file##*/}"
done
' sh {}

Analytics

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment