Linux commands

From Tux
Jump to: navigation, search

This page details some common and useful Linux commands

A full cheatsheet can be found at https://tux.cs.unlv.edu/refs/linux_commands.html

Miscellany

  • exit - end the terminal session
  • clear - clear the terminal screen
  • history - view your command history

Command information

  • man command - read the manual page for command

Paths

In every file system files are organized into various folders or directories. A path describes the location of a file or directory and can be relative or absolute. For instance, suppose a file system has the following folders:

  • /
  • /dirA
  • /dirB
  • /dirB/files

If we wish to examine a file listing of /dirB/files and our current directory is /dirB then we can issue the command ls files (relative path) or /dirB/files (absolute path)

Additionally, there are special symbols with respect to paths that can be used:

  • . - current directory
  • .. - parent directory (one level up)
  • ~ - home directory

Navigation

  • pwd - print the current directory you are in
  • ls - list files in the current directory
  • ls -l - list files with complete details in the current directory
  • ls -a - list all files in the current directory (including hidden files starting with .)
  • ls directory - list files in directory
  • cd directory - make directory the current directory
  • cd .. - make the parent directory the current directory
  • cd - make your home directory the current directory
  • mkdir directory - create a subdirectory
  • rmdir directory - remove a directory (only if empty)
  • rm filename - remove a file
  • rm -rf directory - delete a directory and all contents within
  • rm * - remove all files in the current directory
  • mv file1 file2 - move and/or rename file1 to file2
  • cp file1 file2 - copy file1 to file2
    • Both cp and mv will overwrite the destination file if it already exists