List of FreeBSD Commands by Category
That quick reference guide for whenever you need to remember something.
Hail, guys! Below is a FreeBSD Cheat Sheet separated by category.
Assembly Commands
- Mount MS-DOS file system (USB stick, external FAT32 drive)
sudo mount_msdosfs [-o large] /dev/ad0s1 /mnt
- Mount ISO 9660 using memory disk
sudo mount -t cd9660 /dev/`mdconfig -f <image.iso>` /mnt
- Mount Linux procfs
sudo mkdir -p /proc
sudo mount -t procfs proc /proc
- Mount Linux linprocfs
sudo mkdir -p /compat/linux/proc
sudo mount -t linprocfs linproc /compat/linux/proc
- Mount fs file descriptor
sudo mount -t fdescfs fdesc /dev/fd
update commands
- Run FreeBSD binary update
sudo freebsd-update fetch
sudo freebsd-update upgrade -r <release>
sudo freebsd-update install
pkg
commands
- Install a packages
sudo pkg install [package]
- Remove a package
sudo pkg delete [package]
- Update package databases from repository
sudo pkg update
sudo pkg [-d] update
- Remove unused dependencies
sudo pkg autoremove
- Update packages to a new version
sudo pkg upgrade [-f]
- Update vuln.xml database
sudo pkg audit -F
- Is
pkg
installed?
pkg info|grep <pkg>
- View package information
pkg info <pkg>
pkg show <pkg>
- Lock package for current version and display locked packages
pkg lock <pkg>
pkg lock -l
- Clear local cache
sudo pkg clean -y
- View packet statistics
pkg stats
- Find the file installation package:
pkg which /usr/local/bin/vim
- Find the file if the package is not installed:
sudo pkg install pkg-provides
sudo pkg provides -uf
pkg provides /path/to/file
Network Commands
- TCP sockets open (
LISTEN
,ESTABLISHED
,CLOSE_WAIT
)
sudo netstat -p tcp -an
sudo socksstat -P tcp -a
- Consult the tcp dtrace script at:
/usr/share/dtrace
cd /usr/share/dtrace
sudo tcpconn
sudo tcpdebug
sudo tcpstate
sudo tcptrack
Commands from kernel modules
- Lists loaded kernel modules
sudo kldstat [-v]
- Kernel load module (HW thermal sensors)
sudo kldload <module>
sudo kldload coretemp
- Generate hints for the boot loader
sudo kldxref [v] /boot/kernel /boot/modules
sudo kldxref -R /boot
- Dump(Dump) the running kernel configuration
sysctl -n kern.conftxt
config -x /boot/kernel/kernel
Commands for ports
- Update and extract snapshots
sudo mkdir -p /usr/ports
sudo portsnap fetch extract
- Search for a
ports
in the tree
cd /usr/ports/*/*/<portname>
make -C /usr/ports search name=<portname>
make -C /usr/ports search name=<portname> display=name,path
sudo pkg install psearch
psearch <portname>
- Display
ports
variables
make -C /usr/ports/editor/vim -V MAINTAINER -V PORTVERSION
make -C /usr/ports/editor/vim -V WRKSRC -V WRKDIR
- Search distfile(s)
cd /usr/ports/editor/vim && make fetch extract
cd work
- Regenerate the information hash of the distfile(s)
make -C /usr/ports/editor/vim makesum
- Change KNOB/Options configuration
make -C /usr/ports/editor/vim showconfig
make -C /usr/ports/editor/vim config
make -C /usr/ports/editor/vim rmconfig
make check-license check-categories check-deprecated check-vulnerable security-check check-sanity check-plist check-orphans check-config
- List Makefile destinations from
ports
grep -E '^[^${\.#]+:$' /usr/ports/Mk/bsd.port.mk |cut -d ':' -f1 | sort -u
make -C /usr/ports -V .ALLTARGETS
- List dependencies to rebuild
make all-depends-list
make build-depends-list
make run-depends-list
- Rebuild
ports
without building their dependencies
make missing-packages # list missing packages
make install-missing-packages
make install clean
Commands for src
- Extract
/usr/src
Makefile targets with descriptions (lists all available targets)
grep '^# [a-z].*- [A-Z].*' /usr/src/Makefile | sed 's,^# ,,' | luck
make -C /usr/src -V .ALLTARGETS
- Enter the userland binary utility source code folder (e.g. ls)
cd `where -sq ls`
poudriere
commands
- Create a
jail
sudo poudriere jail -c -j <jail> -v 12.2-RELEASE -a <arch> -M ftp -p <ptree>
sudo poudriere jail -c -j 12amd64 -v 12.2-RELEASE -a amd64 -M ftp -p portsdir
- Delete a
jail
sudo poudriere jail -d -j <jail> -C all
sudo poudriere jail -d -j 12amd64 -C all
- List
jail
(s)
sudo poudriere jail -l
sudo poudriere jail -l [-n] [-q]
- Upgrade jail
sudo poudriere jail -u -j <jail>
sudo poudriere jail -u -j <jail> -t 12.1
- Create
ports
sudo poudriere ports -c -m null -M ${PWD}/svn/ports -p portsdir -v
sudo poudriere ports -l
- Tree list of
ports
sudo poudriere ports -l
sudo poudriere ports -l [-n] [-q]
- Build a test
ports
sudo poudriere testport -o <origin>/<port> -p portsdir -n # dry run
sudo poudriere testport -o editor/vim -p portsdir -v # verbose
Development commands
- Get
sources
git clone --depth 1 https://github.com/freebsd/freebsd.git /usr/src
git clone --depth 1 https://git.freebsd.org/src.git /usr/src
For a specific branch
, eg. Version 12.x:
git checkout -b releng-12.2 freebsd/releng/12.2
git switch -c releng-12.2 freebsd/releng/12.2
- Download
ports
git clone --depth 1 https://github.com/freebsd/freebsd-ports.git /usr/ports
git clone --depth 1 https://git.freebsd.org/ports.git /usr/ports
Commands for Wireless (Wireless networks)
- Restart the wifi network
sudo service wpa_supplicant restart wlan0
- List Wireless devices
sysctl net.wlan.devices
- List wireless SSID hotspot (with wlan0 device)
sudo ifconfig [-v] wlan0 list scan
- Debug the wireless network “stack”
sudo sysctl debug.iwi=1
sudo sysctl hw.wi.debug=1
sudo sysctl net.wlan.debug=1
Build commands
- Build the “world” and the kernel
cd /usr/src
sudo nice -n -20 make -j`sysctl -n hw.ncpu` -DNO_CLEAN -DKERNFAST buildworld buildkernel | tee -a build.log
- Install Kernel (debug)
cd /usr/src
sudo make installworld installkernel
sudo make installkernel.debug
- Update
/etc
settings
sudo etcupdate
sudo mergemaster -ui
hardware commands
- PCI devices
sudo pciconf -vl
sudo pkg install pciutils
sudo lspci [-v]
- USB devices
sudo usbconfig list
sudo usbconfig dump_all_desc
sudo pkg install usbutils
sudo lsusb [-v]
- CPU info
sudo dmesg
sudo dmesg | sed -n '/^CPU:/,/^real/p'
sudo sysctl hw.model hw.ncpu
sudo sysctl kern.smp.cpus
memory commands
- virtual memory
vmstat -c 1
sysctl hw.realmem hw.physmem
top -bt 0
- Process memory mappings
procstat vm <pid>
cat /proc/<pid>/map
cat /compat/linux/proc/<pid>/maps
sound commands
- sound devices
sudo cat /dev/sndstat
sudo sysctl dev.pcm
- disable beep
sudo sysctl hw.syscons.bell=0
sudo sysctl kern.vt.enable_bell=0
- Volume via mixer
mixer vol 100
Input and Output Commands (I/O, I/O)
- Input and Output statistics for device read/write
iostat [-x]
iostat -x -w 1 # watch mode
Commands to/from ZFS
- Import ZFS Pools
zpool import -R /mnt zroot
zpool import -R /mnt -e readonly=on zroot # readonly
- List and mount ZFS datasets
zfs list
mount -t vfs zroot/usr/home /tmp/home
Comments