Skip to content

Instantly share code, notes, and snippets.

@deadbok
Last active November 28, 2016 14:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deadbok/7b2a1805bcd716e806ec0c393802f3c5 to your computer and use it in GitHub Desktop.
Save deadbok/7b2a1805bcd716e806ec0c393802f3c5 to your computer and use it in GitHub Desktop.
Linux command prompt cheat sheet

Linux command prompt cheat sheet

Terminology

Everything enclosed in * characters are placeholders for the arguments that you need in your particular case.

Mount, mount point. etc

To make a drive, actually a partition on a physical drive, available in Linux you mount it somewhere in the file system. Linux has no notion of drive letters.

In Linux everything starts at the root /, and anything is mounted in directories under this root. If we were to mount an NTFS (Windows) partition from the device at /dev/sda1 (the first partition, 1, on the first disk, /dev/sda, in a standard PC) at the mount point /mnt/Windows, all files and directories of that partition would be available by changing to the directory /mnt/Windows/.

Kernel

The actual Linux :-) The kernel is loaded by the boot loader, and is the OS abstraction layer towards the rest of the system. The kernel is modular, and everything from file system drivers to wireless network drivers are managed and loaded by the kernel.

Pipes

A pipe is a channel between two programs, the pipe operator is the character |. In a GUI environment you might save a file in one program, open it in another, do some stuff, save it and open it in a third program. On the command line the pipe makes the saving part unnecessary.

Example:

cat foo.txt | grep bar

Cat shows the content of the file foo.txt and sends the output to grep, which searches for the string bar in the text.

The above example is a common use case for pipes, another is pagination. If then content of foo.txt is longer that one screen, you can pipe the output through a pagination program like less, to stop at every screenful.

cat foo.txt | less

Quick introduction to the directory structure

  • /: The root of the system. Everything the system manages is available as a file or a directory somewhere in here.
  • /bin: Basic system programs like the shell.
  • /boot: Where the kernel and boot loader files live.
  • /dev: Device nodes/files. One of the basic concepts of UNIX is that everything is a file. In here a files representing all devices on the system with a loaded kernel module/driver.
  • /etc/: System configuration files.
  • /home/*: User directories, each named after its user. Stores user files including configuration files, cache, documents and programs. Somewhat similar to the \User\* directories on Windows.
  • /lib/modules/*kernel version*/: Kernel modules ("drivers").
  • /media/: Is often where external media is mounted.
  • /usr/: User programs an utilities, basically everything that is not needed to boot.

Using the command line

These are useful keys when using the command line.

  • Up & down arrow: scroll through previously typed commands.
  • Tab: Will complete the current command, or show a list of possible commands if more than one is available. Typing f*Tab*will show a list of all available commands starting with f . Pressing firef*Tab*will most likely complete to firefox, if available on the system.

Useful Linux commands

In general every command has an argument for showing a help message. There are unfortunately more than one standard, these are the most commonly used variations:

  • --help
  • -h
  • -help
  • -?

Most commands also has a -v switch, verbose mode, which outputs more infos while the command is running.

Interactive commands

Commands with some form of user interface.

  • man *command*: Show the manual page of the command.
    • q gets you out.
    • / lets you search.
    • 'space' advances one page.
  • nano *path to file*: Edit a file.
    • ctrl+x to quit.
    • ctrl+c to show the cursor position.
    • ctrl+k to delete the current line.
    • crtl+w to search for a string.

Non interactive commands

Commands that just do their thing and exits.

  • cat *path to file*: Show the content of the file.
  • cp *source path* *destination path*: Copy a file.* `scp
    • -R: copy subdirectories recursively as well.
  • ls: Show the content of the current directory.
    • If followed by a path ls will show the content of that directory.
  • mv *source path* *destination path*: Move a directory or file.
  • rm *path*: Delete a file.
    • -R: Delete subdirectories recursively as well.
  • ssh *username*@*hostname*: Open an encrypted connection to another machine.
    • If you leave out the username, ssh will login as the user of the local system.
  • scp username*@*hostname*:*source path* *destination path*: Copy a file using an SSH connection from a remote machine.
  • scp *source path* username*@*hostname*:*destination path*: Copy a file using an SSH connection from a remote machine.

Package/Software installation commands on Debian based systems (Ubuntu, mint, etc.)

Every Debian based system uses the apt for managing software. Lately a new tool has been added called apt but the standard command is called apt-get.

  • apt-get install *package name*: Install a new package.
  • apt-get remove *package name*: Remove a package.
  • apt-get purge *package name*: Remove a package and all configuration files of the package.
  • apt search *search pattern*: Search for packages containing search pattern in its name.
  • apt-cache search *search pattern*: Search for packages containing search pattern in its name.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment