FreeBSD Command Line Tips

This will be just a few useful command line tips or commands that I learn and find useful that I don’t use often enough to remember but when I do need them it’ll be handy to have things in one place. Maybe I’ll actually be able to remember them someday.

Remove location data from EXIF. It’s useful to have the location but sometimes you just don’t want it to show up like on my public website. This requires that the p5-Image-ExifTool-11.70 port be installed

exiftool -gps:all=


Find files by name.. for example this finds .core core dump files in the ~ directory

find ~ -name '*.core'

Find the location of a file my name. This example shows the path to the file named FILENAME

whereis FILENAME

show used and free disk space on all file systems

df -h

Find all files larger than a certain size. This came in handy when my disk was nearly full. This command below searches for files over 100 megabytes in size.

find . -type f -size +100M -exec du -m {} \; | sort -n

Before I discovered that rsync can do local drives or even thought of trying it I’d copy and paste. This makes it so much easier to do and more fail safe to boot.

rsync -vru --delete --ignore-existing --no-owner --no-group --no-perms ~/Music/flac/* /usb

Find duplicate files. The fdupes utility is great for this but it is not included in the FreeBSD base system so first it must be installed

pkg install fdupes

Once it’s installed you can run it. I like to use it with these settings where it’s interactive and only shows one set of dupes at a time. Be careful with it because it will happily delete stuff even if you copied it on purpose. (I didn’t accidentally delete the copies of pictures for my hugo site from the assets directory or anything like that.. )

fdupes -r -d -G 1 -P ~/

Text Files

Find and list occurrences of a string in files. This example searches all files in the content/posts directory for the word FreeBSD

grep -rnw "Freebsd" content/posts/*

Clear a text file. Once in a while I just want to quickly clear at text file and this does the trick. This example clears all text from the /var/log/messages file

cat /dev/null > /var/log/messages

Show the last 10 lines of a file then continue waiting for more text to be appended to the file. Very useful for log files sometimes. This watches the /var/log/messages file

tail -f /var/log/messages

Use Aspell to spellcheck all markdown files in a folder

find content/posts/ -type f -name "*.md" -exec aspell check {} \;

Replace text in multiple files from the command line. This uses find to find the files we want then uses sed to replace the old text with tne new text.

find PATH -name "*.md" | xargs sed -i -r 's/old text/new text/g'

FreeBSD Ports

Delete all ports’ work directories s. It’s a pretty quick way to free up some disk space

rm -rf /usr/ports/*/*/WORK

clean up stale distfiles from the ports to free up space. This requires

portmaster to be installed

portmaster -y --clean-distfiles

Clean up stale ports packages. Again this requires portmaster to be installed

portmaster -y --clean-packages


Show all open ports

sockstat -l

Show all blacklisted IPs by blacklistd and remaining time they’re blocked for.

Show HTTP headers

curl --head

Show all blacklisted ips from blacklistd. Also sort the results by IP address

blacklistctl dump -br | sort -h

Using the ipfw show all blocked IPs.


Find out which package installed another package.

pkg info -r bash

Force reinstall all packages. It can be useful after upgrading between major versions of Freebsd

pkg upgrade -f