# Linux Guide/Using the shell
## Introduction

The command line interface (CLI or terminal) may seem intimidating at first, but it's important to remember that the command line is really, truly your friend. An army of tools are at your disposal that can take what would be a tedious and lengthy job (like removing the last four characters from every line of a lengthy file) and turn it into a two minute job.
For every Linux distribution the command line prompt will look a little different. For example, on one system you might see your username, the '@' symbol, the machine name, your current directory and the prompt.
This is a very common prompt. You may also see your username, a space, the fully qualified domain name of the computer, the full path to your present working directory followed by the prompt. In the example above 'user' is the username and 'linux' is the name of the host(computer) you are logged on.
The prompt varies from system to system based on a number of things. For example, it may be the default configuration set by the creators of your particular Linux distribution. It could also have been configured by the person who administers the computer. Maybe you, yourself, configured how you wanted your prompt to look.
The way you configure the look of your command prompt depends on what shell you use and the shell is the piece that most people commonly refer to as "the command line" when, in reality, it is simply a piece of software that provides an interface to the services of a kernel. The distinction between a 'shell' and the 'command line' is simply that a shell refers to a specific piece of software (e.g BASH, Tch, ksh, etc) that provides a command line interface. Most modern Linux systems use BASH (Bourne Again SHell) as the default shell.

### A Little History

The commands used at the command line may seem a little cryptic due to their tendency to be very short. This is because the roots of the Linux command line are from systems where a single letter entry could take a significant amount of time to travel from a terminal, to a central server and back to the terminal where it was printed onto a roll of paper. In those old systems, the shorter the input was, the better as it meant less time waiting to issue your command and receive output. The best thing you can do to remember what commands stand for is to find out what word the command is an abbreviation for. This can go a long way to remembering the command later.

## Some Useful Terminal Commands
#### Summary of Common Commands

* ls - This command lists the contents of your present working directory.
* pwd - Shows you what your present working directory is.
* cd - Lets you change directories.
* rm - Removes one or more files.
* rmdir - Remove an empty directory.
* mkdir - Make a directory.
* ps - Provides a list of currently running processes.
* cp - Copy a file.
* mv - Move a file (this is also used to rename a file, "moving" it from one file name to another.)
* grep - The global regular expression print program lets you search through a file or output of another program.
* find - Find a file on the filesystem
* man - Displays the manual for most commands (including 'man').

##### TIP

    For help about a command, try man <command> which will bring up the manual for it. Note that some commands are built into your shell and do not have a man page, use your interpreter internal command (should be help <command>).

#### Using Common Commands
##### Using ls

You may notice from the example, default output of 'ls' that the files are not in strict alphabetical order. This is because the output is sorted on the numeric ASCII value of each letter. Because upper case letters have a lower ASCII value than lowercase letters, the returned result will always be files starting with upper case letters first. For example, if we add the file AZTRIP to the directory we will get 'AZTRIP' as the file listed first followed by 'Afilez' because the ASCII value of 'Z' is numerically lower than the ASCII value of 'f'.
If the ASCII values of letters has you confused, the important thing to remember here is that uppercase letters trump lowercase letters and will appear first in listings. The result is that files are first sorted by case and sorted alphabetically second.
The default output of ls isn't as useful as it could be. For example, given the output in the example, we don't know what are files and what are directories. We can likely guess that "Afilez", "aFilea" and "vacation pictures" are all directories as they don't have an extension after the file name. To confirm this, we can pass the 'l' parameter to 'ls' to get "long listing format" output.
The first character in the output above indicates the file type; where a dash indicates a file and the letter 'd' indicates a directory. From this output we see that the only directory is "vacation pictures"

###### NOTE

    Most systems have an alias on the ls command to include the '--color' flag so that the command highlights different file types with different colors. Directories are commonly shown in blue. If the output of your 'ls' command is always the same color, try "ls --color".

###### TIP

    Another common parameter (also known as an "argument") to the ls command is 'a' which shows all files including any hidden files and folders that start with a period. Arguments may also be combined together in a single block of letters. For example, "ls -l -a" can also be expressed as "ls -la".

##### Using cd

The cd command lets you navigate from directory to directory on your system. The first thing you may need to know when using the cd command is that, unlike windows, Linux does not use the concept of drive letters. Instead, everything is somewhere within the root directory, '/', including other disk drives.
There's a couple ways to use cd to navigate to the directory you want. These are known as "full path" and "relative path".
Full path always begins with the root directory '/'. For example, if we're in our home directory '/home/user' and we want to navigate to the 'vacation pictures' directory, we would issue the following command.
You may note that our prompt changed a little to indicate the directory we're currently in. This will be the case on most systems, but as previously discussed, this depends on how your shell is configured. You may also note the backslash between "vacation" and " pictures". This backslash is known as the "escape character" and tells the cd command that the space is part of the directory name. If we omitted the backslash, the cd command would error and tell us that it could not find the directory "vacation". If you don't like typing backslash or have a directory name with many spaces in it, you can use quotation marks around the path.
Relative path can start a number of ways, but always describes how to get to a specific directory from the directory you're currently in. To do this, we need to know how to move to directories that immediately surround the directory. These directories are parent directories and sub-directories
A sub-directory is any directory that is contained within the directory we're currently. Given the output below of "ls -l", we see that chicago, florida and "new york" are all sub-directories to the "vacation pictures" directory.
A parent directory is the directory that contains the folder that we are in. This makes the "vacation pictures" folder the parent of the "chicago", "florida" and "new york" directories.
To cd to a sub-directory, you can start the path name with "./" which indicates the directory we're already in, or you can immediately start with the name of the sub-directory. For example, both of the following commands will change you to the "florida" directory.
To cd to a parent directory, you always specify "../". The following command will return us to the "vacation pictures" directory.
If we are already in the "chicago" directory and want to cd to "new york", we must first tell the system we want to go up one level to the parent directory and then to the "new york" directory. We can do this by saying "cd ../" and then "cd new\ york" or we can do it as one step using the command below.

###### NOTE

    Notice how we used quotation marks around the path to cd to the "new york" directory. We could have, instead used the backslash before the space and omitted the quotes to get the same result.
Similar to "./" and "../", there's also "~/" which indicates the home directory of the user we're logged in as. If we wanted to cd to the "vacation pictures" folder while in the "/usr/lib" directory, we could do this with any of the following commands.

###### TIP

    Using the cd command without specifying a directory will return you to your home directory.

### File manipulation

Copy directory options:
Copy img to floppy:
Copy source to make img:
DELETING
PERMISSIONS
Usage format:
In addition, three extra permission may be assigned:
VI / VIM
VI/M uses 2 modes in which to process text. To process the various commands available use the "<esc>" key. To insert text simply type "i" to return to text insert mode.
For Starters/Basics------------------------
Sort all
Replace text
See Line Numbers
Write lines to new file
Change working file from current to file abc [be sure to save first]
Read abc file into working file after cursor
Execute command from prompt
Enable syntax option for programming source text highlighting

### Printing

Work from Bash Prompt:
See also: CUPS

## Disk System
### Disk space usage: du -h <dir>

    lists an estimate of total space usage for each subdirectory found in <dir> and the estimated grand total disk space used

### File System (mounted) Disks space usage: df

    lists all mounted disks and blocks total, used, free, and logical disk name

### df .

    lists only current working mounted disk, displaying total, used, free in blocks.

### df -h

    lists all mounted disks total, used, free, and logical disk name in human terms (KB,MB,GB,TB).

### df -kh

    lists all mounted disks total, used, free and logical disk name in human terms (KB, MB, GB, TB) and space used in % (percentages)[-k] option.

### List partitions: fdisk -l <disk>

    list all partitions on a hard drive e.g. fdisk -l /dev/hda