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

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.


Find out which package installed another package . #pkg info -r bash