Skip to content

Basic UNIX and bash commands

Jennings Zhang edited this page Mar 22, 2018 · 15 revisions

CAPITAL LETTERS describe a required argument.

[square brackets] indicate optional parameters, flags, or options.

The basic command syntax looks like this:

command --option PARAMETER

GNU coreutils and shell commands

  • echo [string] outputs the string.
  • ls [-alh] [dir] displays the contents of the directory DIR.
    • ls -a lists all files, including . and .., as well as hidden files (which filenames begin with .).
    • ls -l lists files with metadata, such as permissions, owner, size, and date.
      • ls -lh reports the information in "human readable" format.
  • cd DIR changes the current working directory to DIR.
  • mkdir DIR creates a new directory.
  • rmdir DIR deletes an empty directory.
  • rm FILE deletes a file. (accepts multiple arguments)
  • touch FILE creates a blank file called FILE.
  • cat concatenates the input stream and prints to the output stream.
    • cat FILE prints the content of FILE
    • cat > FILE will write the standard input stream out to FILE. End this command by pressing CTRL-D.
  • man COMMAND shows the manual page for COMMAND.
  • whatis COMMAND shows a brief, one-line description of COMMAND.
  • sudo COMMAND runs COMMAND with superuser (root) privileges.
  • grep REGEX [file] filters the input stream or file based on a regular expression.
    • fgrep or grep -F forces literal evaluation of string.
    • I strongly recommend you add alias grep='grep --color' to your ~/.bashrc file.

System administration

  • nano [file] opens an easy-to-use text-based text editor.
  • vim [file] opens an advanced text-based text editor.
  • ln -s TARGET LINKNAME creates a symbolic link.
  • sudo -s enters $SHELL as the root user.
  • sudoedit FILE edits a file as the root user. ($SUDO_EDITOR must be set, recommend rvim)
  • dmesg [-H] print the kernel ring buffer (debug messages produced by the kernel)
  • journalctl -b [-r] shows systemd log entries from the current boot.
You can’t perform that action at this time.