- 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
Find out what directory you are in
List contents of current working directory
Copy a file to a new file with a different name
cp foobar.txt barfoo.txt
Remove a file (delete it)
Remove an ""empty"" directory.
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
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
Add a new user and create their home directory
Change a user's default shell
-s /path/newshell jsmith
<span class="createlink"><a href="/cgi-bin/ikiwiki?page=basics%2Fchpass&do=create&from=tutorials%2Fnetbsd_command-line_cheat-sheet" rel="nofollow">?</a>chpass</span> -s /bin/ksh jsmith
Add a binary package
List all (installed) packages
List all files that are part of a directory
pkg_info -L the_package_name
Delete a package
Create a binary package file from an already installed package (this requires the pkg_tarup tool from pkgsrc which lives under the pkgtools subdirectory.)
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