Linux Quick Reference

The topic of Linux is very large and can be very advanced. This page is designed to be an overview of some simple system commands in order to navigate the file system and perform basic tasks.

Note

Anytime a line is indented and starts with a $, this is a command to be typed at your command prompt of choice (cmd, powershell, bash, zsh, etc)

Dissecting A Linux Command

To input a command in the Linux Command Line Interface, the following pattern is used

$ command [option(s)] [argument(s)]

The command is actually a program that the Linux system is going to run with the given arguments and options. The arguments are the required input of the command. For example, the cp command copies a file and pastes it to a desired location

$ cp file.txt file2.txt

In this example, file.txt and file2.txt are the arguments which specify the file to copy (file.txt) and the file name to use when it is pasted (file2.txt).

Command options are prefaced with either a single dash (-) as a short form, or a double dash (–) in the long form.

$ man -h
$ man --help

These two optional arguments are the same, but use different forms.

Tab Completion

One of the most useful features of the Linux command line is Tab Completion. By simply pressing tab, Linux will attempt to auto-complete the command, or display a list of available commands or files. This dramatically speeds up any command line work, and helps prevents typos.

Gathering Information

The man command will bring up the manual page for a command that will give useful information, such as examples and optional arguments that can be included

$ man [command]
$ man ls

Note

To exit the manual pages of a command, press q

Viewing the current files and directories in the current directory

$ ls
$ ls -la

Display the current directory

$ pwd

File Commands

Changing directories

$ cd [directory]

Changing directories to the parent directory

$ cd ..

Changing to your home directory

$ cd
$ cd ~

Creating a new directory

$ mkdir [directory name]

Creating a new file

$ touch [file name with extension]

Copying a file

$ cp [file to copy] [destination and name of copied file]

Copying a directory

$ cp -r [directory to copy] [destination and name of copied directory]

Renaming or moving a file

$ mv [file] [destination and/or name of moved file]

Deleting a file

$ rm [file]

Deleting a directory

$ rm -r [directory]

Output the contents of a file

$ cat [file]

Redirecting output to a file

$ [command] > [file]

Append the output to an existing file

$ [command] >> [file]

Note

Ctrl+c will kill a running command