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=

Files

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 filesystems

 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

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 portmnaster to be installed

# portmaster -y --clean-packages