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
Files
Find files by name.. for example this finds .core core dump files in the ~ directory
Find the location of a file my name. This example shows the path to the file named FILENAME
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.
|
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.
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
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.. )
File System
show used and free disk space on all file systems
Show all partitions and filesytem types on them.
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
Find files that do not contain a string and then open them all in an editor. In my case I’m using kate.
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
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
Use Aspell to spellcheck all markdown files in a folder
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.
|
FreeBSD Ports
Delete all ports’ work directories s. It’s a pretty quick way to free up some disk space
clean up stale distfiles from the ports to free up space. This requires
portmaster to be installed
Clean up stale ports packages. Again this requires portmaster to be installed
Now that portsnap is depreciated to update the ports tree you can use if you don’t need or ohave git installed.
Network
Show all open ports
Show all blacklisted IPs by blacklistd and remaining time they’re blocked for.
Show HTTP headers
Show all blacklisted ips from blacklistd. Also sort the results by IP address
|
Using the ipfw show all blocked IPs.
Show all of ipfw’s rules
ipfw list
I use pf firewall along with blacklistd and this is how to show allthe blocked IP addresses
pfctl -a 'blacklistd/22' -t port22 -T show
Packages
Find out which package installed another package.
Force reinstall all packages. It can be useful after upgrading between major versions of Freebsd
clean up stale packages from the cache
FreeBSD system
See what the currently installed version of FreeBSD is
Here’s how update the FreeBSD kernel and base version
Here’s how to upgrade between major versions of the kernal and base system
reboot system now
reboot
shutdown system
shutdown -p