brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: find -type d,l matches several file types in one test

Find
~/tips/tip-find-type-comma-list

find /srv -maxdepth 1 -type d,l

Lists folders and symlinks together without writing two type tests joined with -o.

Listing folders and the links next to them is common when looking around a server. With older finds, you’d write two type tests joined with -o, plus parentheses. GNU find takes a list.

find /srv -maxdepth 1 -type d,l

The letters are separated by commas, without spaces. d is a folder, l a symbolic link, f a regular file, and there are p for named pipes, s for sockets and b and c for device files. The result lists every folder and symlink at the top level, and no regular files.

It also helps when cleaning up: find . -type f,l -name '*.tmp' catches temporary files and stray links to them in one go.

Two things to know. A list matches if any type matches, so it’s an “or”, never an “and”. And -xtype takes the same list form, checking what a link points to instead of the link itself.

This is a GNU findutils feature. BusyBox find in an Alpine container refused it with an “invalid argument” error, and the find on macOS doesn’t take it either. In scripts that need to run everywhere, I’d stay with the long form: \( -type d -o -type l \).

Further reading: find(1) manual page, GNU findutils manual

More Find tips find / -maxdepth 1 -fstype proc find /backup -name '*.gz' ! -exec gzip -t {} \; -print 2>/dev/null find /srv/downloads -type f -size +100M -size -1G -exec ls -lh {} + find /srv/data -depth -print find /srv -xdev -samefile /srv/downloads/movie.mkv All Find tips (46) All topics

Link