File:  [NetBSD Developer Wiki] / wikisrc / tutorials / netbsd_command-line_cheat-sheet.mdwn
Revision 1.5: download - view: text, annotated - select for diffs
Fri Apr 5 00:18:03 2019 UTC (15 months ago) by sevan
Branches: MAIN
CVS tags: HEAD
Again

    1: **Contents**
    2: 
    3: [[!toc levels=2]]
    4: 
    5: #  Startup & Shutdown 
    6: 
    7:   * Shutdown the machine immediately and reboot 
    8:     
    9:     shutdown -r now
   10: 
   11:   * Shutdown the machine and immediately power off (for ATX hardware, you will need to install and enable the [apm(8)](http://netbsd.gw.com/cgi-bin/man-cgi?apm+8+NetBSD-current) support in kernel: see [[How to poweroff at shutdown]] for details) 
   12: 
   13:     shutdown -p now
   14: 
   15:   * Shutdown the machine and halt afterwards (but keep the power on) 
   16: 
   17:     shutdown -h now
   18: 
   19: #  File & Directory Operations 
   20: 
   21:   * Find out what directory you are in 
   22:     
   23:     pwd
   24: 
   25:   * List contents of current working directory 
   26:     
   27:     ls
   28: 
   29:   * Copy a file to a new file with a different name 
   30:     
   31:     cp foobar.txt barfoo.txt
   32: 
   33:   * Remove a file (delete it) 
   34:     
   35:     rm foobar.txt
   36: 
   37:   * Remove an ""empty"" directory. 
   38:     
   39:     rmdir mydir
   40: 
   41:   * 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. 
   42:     
   43:     rm -rf mydir
   44: 
   45: #  Using Archives 
   46: 
   47:   * Create a ""tar"" archive with the contents of a directory displaying each file and directory as tar runs verbosely. 
   48:     
   49:     tar cvf my_archive.tar some_directory
   50: 
   51: The same using pax: 
   52:     
   53:     pax -w -v -f my_archive.tar some_directory
   54: 
   55:   * Extract a ""tar"" archive to the current directory displaying each file and directory as tar runs verbosely. 
   56:     
   57:     tar xvf my_archive.tar
   58: 
   59: The same using pax: 
   60:     
   61:     pax -r -v -f my_archive.tar
   62: 
   63:   * Compress a file with gzip using maximum (slowest) compression 
   64:     
   65:     gzip -9 foobar.txt
   66: 
   67:   * 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. 
   68:     
   69:     bzip2 -9 foobar.txt
   70: 
   71: #  User Operations 
   72: 
   73:   * Add a new user and create their home directory 
   74:     
   75:     useradd -m jsmith
   76: 
   77:   * Change a user's default shell 
   78:     
   79:     chsh -s /path/newshell jsmith
   80: 
   81: or 
   82: 
   83:     chpass -s /bin/ksh jsmith
   84:     
   85: 
   86: #  Package Operations (pkgsrc) 
   87: 
   88:   * Add a binary package 
   89:     
   90:     pkg_add my_binary_package.tgz
   91: 
   92:   * List all (installed) packages 
   93:     
   94:     pkg_info
   95: 
   96:   * List all files that are part of a directory 
   97:     
   98:     pkg_info -L the_package_name
   99: 
  100:   * Delete a package 
  101:     
  102:     pkg_delete the_package_name
  103: 
  104:   * Create a binary package file from an already installed package (this requires the **pkg_tarup** tool from pkgsrc which lives under the **pkgtools** subdirectory.) 
  105:     
  106:     pkg_tarup the_package_name
  107: 
  108: #  Advanced Command Line Recipes 
  109: 
  110:   * Create a binary package for every single installed package on the system and place them all in the current directory. 
  111:     
  112:     
  113:     for pkg in `pkg_info -e "*" | sort`; do echo "Packaging $pkg"; pkg_tarup -d . $pkg 1>/dev/null; done
  114:     
  115: 

CVSweb for NetBSD wikisrc <wikimaster@NetBSD.org> software: FreeBSD-CVSweb