Contents
Startup & Shutdown
Shutdown the machine immediately and reboot
shutdown -r now
Shutdown the machine and immediately power off (for ATX hardware, you will need to install and enable the apm(8) support in kernel: see ?How to poweroff at shutdown for details)
shutdown -p now
Shutdown the machine and halt afterwards (but keep the power on)
shutdown -h now
File & Directory Operations
Find out what directory you are in
pwd
List contents of current working directory
ls
Copy a file to a new file with a different name
cp foobar.txt barfoo.txt
Remove a file (delete it)
rm foobar.txt
Remove an ""empty"" directory.
rmdir mydir
Recursively remove a directory (be careful with this, if you mess up, you can easily wipe out your whole system). This will remove the directory and all the files and subdirectories it contains, provided you have permissions.
rm -rf mydir
Using Archives
Create a ""tar"" archive with the contents of a directory displaying each file and directory as tar runs verbosely.
tar cvf my_archive.tar some_directory
The same using pax:
pax -w -v -f my_archive.tar some_directory
Extract a ""tar"" archive to the current directory displaying each file and directory as tar runs verbosely.
tar xvf my_archive.tar
The same using pax:
pax -r -v -f my_archive.tar
Compress a file with gzip using maximum (slowest) compression
gzip -9 foobar.txt
Compress a file with bzip2 using maximum (slowest) compression. Bzip generally compresses files better at the cost of greater time during the compression phase. The archives it creates generally de-compress at the same speed as gzip.
bzip2 -9 foobar.txt
User Operations
Add a new user and create their home directory
useradd -m jsmith
Change a user's default shell
chsh -s /path/newshell jsmith
or
chpass -s /bin/ksh jsmith
Package Operations (pkgsrc)
Add a binary package
pkg_add my_binary_package.tgz
List all (installed) packages
pkg_info
List all files that are part of a directory
pkg_info -L the_package_name
Delete a package
pkg_delete the_package_name
Create a binary package file from an already installed package (this requires the pkg_tarup tool from pkgsrc which lives under the pkgtools subdirectory.)
pkg_tarup the_package_name
Advanced Command Line Recipes
Create a binary package for every single installed package on the system and place them all in the current directory.
for pkg in
pkg_info -e "*" | sort
; do echo "Packaging $pkg"; pkg_tarup -d . $pkg 1>/dev/null; done