Project

General

Profile

Intro to Linux

User documentation
09/13/2017

  • Last Updated: 06/26/2019

The Linux Terminal

The Linux terminal (bash by default) is a command line-based tool used to control a Linux system. This is the most basic way of interacting with a Linux system. The terminal is command-based. Different commands perform different functions in the terminal. For instance, ls lists all the items in a directory, while cd changes the current working directory.

In this lesson, we are going to go through basic Linux commands and give you an overview of how to use the terminal.

Movement commands

To list all the files in a directory, use the "ls" command. For example in your home directory:

example@example-laptop:~$ ls
Desktop  Documents  Photos  Videos

To change directories, use "cd" which stands for change directories. ".." refers to the above directory, while "." refers to the working directory.

example@example-laptop:~$ ls
Desktop  Documents  Photos  Videos
example@example-laptop:~$ cd Documents/
example@example-laptop:~/Documents$ ls
Example.txt
example@example-laptop:~/Documents$ pwd
/home/example/Documents

Now, let's learn how to copy, move, and delete files.

example@example-laptop:~/Documents$ cp Example.txt Example2.txt
example@example-laptop:~/Documents$ ls
Example2.txt  Example.txt
example@example-laptop:~/Documents$ mv Example.txt NewName.txt
example@example-laptop:~/Documents$ ls
NewName.txt   Example2.txt
example@example-laptop:~/Documents$ rm NewName.txt 
example@example-laptop:~/Documents$ ls
Example2.txt

Here, we used the cp command to copy a file and the mv command to move the file to a new location. In this case, we just moved it to a new filename. This is also how you rename files in Linux. Then, we used rm (remove) to delete the file.

Here's another example of what we can do with these movement commands combined with mkdir and pwd.

example@example-laptop:~$ cd Documents/
example@example-laptop:~/Documents$ ls
Example2.txt
example@example-laptop:~/Documents$ mkdir ExDir
example@example-laptop:~/Documents$ cd ExDir/
example@example-laptop:~/Documents/ExDir$ pwd
/home/example/Documents/ExDir

In this example, the only new tools we used were mkdir to make a new directory and pwd to check the path of our working directory.

The Linux File System

The beginning of every Linux file system is the root, or "/". Everything else comes after that. There are some important subdirectories of /:
/bin: the directory for basic binary programs like ls and cp
/boot: the location of the files that tell the computer how to boot up
/dev: the location of all the devices connected (USB, HDD, etc) including some fake ones like random and zero
/etc: the directory for configuration files
/home: the directory containing the users' home directories
/lib: library files
/proc: the directory for files describing all the running processes
/root: the home directory for root
/sbin: the binaries only accessible by root
/usr: the directory for files you need to be accessible by other users
/var: "variable" files such as system logs, keyboard recordings, etc.

You can cd to / and ls to see all these directories plus more.

Searching for files

There are a few commands in Linux that can be used to find files, whether it be searching by filename or by file contents.

For example, if we want to find the Example2.txt file and we knew it was in a subdirectory of where we were, we could use find.

example@example-laptop:~$ find . -name Example2.txt
./Documents/Example2.txt

If we knew a pattern was in Example2, we could use grep to search for that.

example@example-laptop:~$ grep -ir example .
./Documents/Example2.txt:This is an example document

In this case, we had to use the recursive grep (-r) because the file we wanted was in a subdirectory of our current folder. "example" was the text to search for, and the working directory (.) was the directory to search in.

Displaying Files

The most basic tool for displaying a file in pure text for is "cat". cat (short for catenate) catenates all the files that match a given pattern and outputs the result.

example@example-laptop:~/Documents$ ls
Example1.txt  Example2.txt
example@example-laptop:~/Documents$ cat *
this is from the example1 file

this is from the example 2 document
example@example-laptop:~/Documents$ 

Another tool is less. Instead of catenating, less displays each file individually. You can press "n" to cycle through the files. You can scroll up and down through the files with the arrow keys. When done, press q to quit. You can use / to search downwards and ? to search from the bottom up.

File Permissions

In Linux, there are the types of permissions--read, write, execute--for 3 different sets of people--owner, group, and anybody. We can view these permissions using ls:

example@example-laptop:~/Documents$ ls -alh
total 16K
drwxrwxr-x 2 example example 4.0K Jun 19 16:24 .
drwxr-xr-x 6 example example 4.0K Jun 19 16:13 ..
-rw-rw-r-- 1 example example   33 Jun 19 16:09 Example1.txt
-rw-rw-r-- 1 example example   36 Jun 19 16:09 Example2.txt
-rw-rw-r-- 1 example example    0 Jun 19 16:24 script.py

Here there are 3 files all with the same permissions. You can see these permissions by looking at the string of characters on the left. The first character denotes whether or not the file is of a special type. In this case, ".." and "." are because they refer to directories. The next 3 sets of 3 characters show the permissions for the owner, group, and anybody, respectively. Right now, the owner can read and write, anybody in the group can read and write, and anybody can read the files. This is fine for the documents, but you need to be able to execute a script. To make the script executable, we use chmod:

example@example-laptop:~/Documents$ chmod +x script.py 
example@example-laptop:~/Documents$ ls -alh
total 16K
drwxrwxr-x 2 example example 4.0K Jun 19 16:24 .
drwxr-xr-x 6 example example 4.0K Jun 19 16:13 ..
-rw-rw-r-- 1 example example   33 Jun 19 16:09 Example1.txt
-rw-rw-r-- 1 example example   36 Jun 19 16:09 Example2.txt
-rwxrwxr-x 1 example example    0 Jun 19 16:24 script.py

Now, script.py can be executed by anybody. You can also use modifiers to make it so only certain people can execute:

example@example-laptop:~/Documents$ ls -alh
total 16K
drwxrwxr-x 2 example example 4.0K Jun 19 16:24 .
drwxr-xr-x 6 example example 4.0K Jun 19 16:13 ..
-rw-rw-r-- 1 example example   33 Jun 19 16:09 Example1.txt
-rw-rw-r-- 1 example example   36 Jun 19 16:09 Example2.txt
-rw-rw-r-- 1 example example    0 Jun 19 16:24 script.py
example@example-laptop:~/Documents$ chmod g+x script.py 
example@example-laptop:~/Documents$ ls -alh
total 16K
drwxrwxr-x 2 example example 4.0K Jun 19 16:24 .
drwxr-xr-x 6 example example 4.0K Jun 19 16:13 ..
-rw-rw-r-- 1 example example   33 Jun 19 16:09 Example1.txt
-rw-rw-r-- 1 example example   36 Jun 19 16:09 Example2.txt
-rw-rwxr-- 1 example example    0 Jun 19 16:24 script.py

Now, only people in the group can execute the file. In this case, the group is just example, but it could be something like the editors at a blog.

You can also chmod faster if you use a set of numbers designated to different permissions. These numbers can be found here: http://forums.34sp.com/setupimages/chmod4.jpg Example:

example@example-laptop:~/Documents$ chmod 755 script.py 
example@example-laptop:~/Documents$ ls -alh
total 16K
drwxrwxr-x 2 example example 4.0K Jun 19 16:24 .
drwxr-xr-x 6 example example 4.0K Jun 19 16:13 ..
-rw-rw-r-- 1 example example   33 Jun 19 16:09 Example1.txt
-rw-rw-r-- 1 example example   36 Jun 19 16:09 Example2.txt
-rwxr-xr-x 1 example example    0 Jun 19 16:24 script.py

You can also use chown and chgrp to change owner and group for a file. These require root privileges. To get those, use sudo or su to root.

root@example-laptop:/home/example/Documents# ls -alh
total 16K
drwxrwxr-x 2 example example 4.0K Jun 19 16:24 .
drwxr-xr-x 6 example example 4.0K Jun 19 16:13 ..
-rw-rw-r-- 1 example example   33 Jun 19 16:09 Example1.txt
-rw-rw-r-- 1 example example   36 Jun 19 16:09 Example2.txt
-rwxrwxrwx 1 example example    0 Jun 19 16:24 script.py
root@example-laptop:/home/example/Documents# chown root script.py 
root@example-laptop:/home/example/Documents# chgrp root script.py 
root@example-laptop:/home/example/Documents# ls -alh
total 16K
drwxrwxr-x 2 example example 4.0K Jun 19 16:24 .
drwxr-xr-x 6 example example 4.0K Jun 19 16:13 ..
-rw-rw-r-- 1 example example   33 Jun 19 16:09 Example1.txt
-rw-rw-r-- 1 example example   36 Jun 19 16:09 Example2.txt
-rwxrwxrwx 1 root    root       0 Jun 19 16:24 script.py

Proper permissions help with security significantly as they allow you to precisely define who can do what.

Shutting down a linux server

Similar to shutting down a windows machine, you need to properly shutdown the machine rather then suddenly take power from it. that way all the services and processes are properly closed. Either these two commands are ways to shutdown the linux machine

example@example-laptop:/sbin/halt -p
example@example-laptop:shutdown -h 0

Processes

In Linux, (almost) everything is a file or a process. You can use "ps" to return a list of running processes. The two main ways to view processes are the "ps -e" (standard Linux syntax) and the "ps ax" (standard BSD syntax) commands. Check the man page for ps for more information.

To kill a process, you can use the "kill" command followed by the process ID (PID) of the process you wan to kill. For example, if I wanted to kill firefox, I could do this:

example@example-laptop:~$ ps ax | grep firefox
23079 ?        Sl     0:05 /usr/lib/firefox/firefox
23204 pts/4    S+     0:00 grep --color=auto firefox
example@example-laptop:~$ kill 23079

Alternatively, I could use the "killall" command which blindly kills all processes that match a certain pattern.

example@example-laptop:~$ killall firefox

Piping

Very simply, piping takes the output of one command and pipes into the input for another command. For example, if I wanted to search of all instances of where I used vim, I could do this:

example@example-laptop:~$ history | grep vim
    3  vim .bashrc 
    5  vim .bashrc 
   41  vim Documents/Example2.txt 
   46  vim Example1.txt
   48  vim Example2.txt 
   49  vim Example1.txt
   95  history | grep vim

Here, instead of a filename, grep takes STDIN as its input. You can also use > to send output to a filename.

example@example-laptop:~$ history | grep vim > vimresults.txt
example@example-laptop:~$ cat vimresults.txt 
    3  vim .bashrc 
    5  vim .bashrc 
   41  vim Documents/Example2.txt 
   46  vim Example1.txt
   48  vim Example2.txt 
   49  vim Example1.txt
   95  history | grep vim
   96  history | grep vim > vimresults.txt

$PATH

In bash, the $PATH variable is a list of all directories to look in when issuing commands. Let's use the ls command as an example:

example@example-laptop:~/Documents$ ls
Example2.txt  ExDir
example@example-laptop:~/Documents$ /bin/ls
Example2.txt  ExDir

The ls command is actually located in /bin, but we can use it without the /bin prefix regardless of our directory. This is because we have added /bin to our path. Since /bin is in our path, bash knows to look there when we issue a command. Let's see what makes up $PATH:

example@example-laptop:~$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

All of these directories will be searched when we issue a bash command. To find out where a command (that is in our path) lies, we can use the which command:

example@example-laptop:~$ which ls
/bin/ls

SSH

SSH (Secure Shell) is a protocol that allows a user to remotely access a server via a command line terminal. Most systems require a username and password to be entered. These systems (normally Linux based) are accessed through the terminal through the "ssh" command as such:

example@example-host:~$ ssh -p 1337 root@216.58.217.78
The authenticity of host '[261.58.217.78]:1337 ([261.58.217.78]:1337)' can't be established.
ECDSA key fingerprint is cd:e1:3e:41:8b:cc:a1:61:20:bb:7c:e5:b4:c0:f2:ac.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[261.58.217.78]:1337' (ECDSA) to the list of known hosts.
root@261.58.217.78's password: 

After the "ssh" command, there is a "-p". This states that you are attempting to connect to a server through a ip address and port number. If no port number is given (only an IP address), the server attempts to connect to port 22. Invalid input will return such:

example@example-laptop:~$ ssh -p 9.9.9.9
Bad port '9.9.9.9'

There is a "1337" which states the attempted port to connect to. "root" is the user we are connecting as. If no user is given, the user will be the same as the one currently on your host machine. The "@216.58.217.78" is the ip address that is being attempted to connect to.

If an invalid port or ip is entered:

example@example-laptop:/home/rwintern$ ssh -p 9 9.9.9.9

Nothing will happen. You can always cancel the command by pressing "Ctrl + C".

Absolute and Relative Paths

Definite Paths

Definite paths give the location of a file. They begin with a "/" and end with the name of the file. You navigate through each directory looking for a file and end up with a list like such:

/home/Documents/text.txt

This is an example of an definite path. You can also use the "readlink" command with the file to get its location:

example@example-laptop:/home/Documents$ readlink -f text.txt
/home/Documents/text.txt

Relative Paths

Relative Paths define where an object is starting from where you are. For example, if I am inside a directory named "Documents" with a subdirectory named "test" with a file inside it named "object.txt", its relative path would be "/test/object.txt". This is NOT the same as its absolute directory, which would include any larger folders that "Documents" is inside of.

For example, if you are inside Documents:
Absolute Path: /home/Documents/test/object.txt
Relative Path: /test/object.txt

Man

The "Man" command is used to help learn about other commands. It acts similar to an API by giving information about a specific key word. For instance, we can see what "ls" does with the command:

example@example-laptop$ man ls

This code will open a description of the function in Less. For example, ls returns:

LS(1)                            User Commands                           LS(1)

NAME
       ls - list directory contents

SYNOPSIS
       ls [OPTION]... [FILE]...

DESCRIPTION
       List  information  about  the FILEs (the current directory by default).
       Sort entries alphabetically if none of -cftuvSUX nor --sort  is  speci?
       fied.

       Mandatory  arguments  to  long  options are mandatory for short options
       too.

       -a, --all
              do not ignore entries starting with .

This is just part of the doccumentation. You can exit Less by pressing "q".

Sudo and Su

Sudo

The Sudo command in Linux performs an action as a superuser. It can be added before any commands simply by putting the word "sudo" in front of it. Sudo users are required to enter their own personal password before continuing to execute the following function, no matter the current user. Some commands require sudo, such as apt install.

example@example-laptop:~$ apt install vim
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
example@example-laptop:~$ sudo apt install vim
[sudo] password for example:
Reading package lists... Done
Building dependency tree       
Reading state information... Done
vim is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

In this example, example was denied access to install an item without being a root (or sudo) user. After adding sudo, it prompted for example's password (because example is sudo) and continued with the vim install, which happened to already be added to that user.

Su

The Su command is used to change accounts to any user on a certain system. While this is normally used to change to a superuser, it works for any user on the ssystem. All that is needed is the following:

example@example-laptop:~$ su
Password:
root@example-laptop:/home/example#

Without any given user, su assumes the root user wishes to be accessed. Note that the root user is still left in the home files for the example user. You can also change to any other user on the system given their password:

example@example-laptop:~$ su example2
Password: 
example2@example-laptop:/home/example#

Note that once again, the user is still left in the directory for example (the previous user).

Apt

Apt is the package manager in Debian and all Debian forks (Ubuntu, Mint, Elementary, etc.). Apt works by pulling all its packages from whatever repositories are in /etc/apt/sources.list. What this means is that you are never pulling a package from a potentially "shady" source. All package downloads are straight from the official Debian repository.

This method of packaging is also great for stability. With each new release, the Debian testers make sure every package works seamlessly with Debian and that nothing will crash something else. This is one of the reasons why Linux is so widely used in the server world. This style of package maintenance means the server will be rock-solid stable.

Those ideas are very common to most Linux distros. Most distros will use a package manager that pulls from a trusted repository. In fact, most package managers even work the same way with very similar commands. Because of this, commands you find here in apt will probably be applicable in other distros.

In Debian, you can use either apt or apt-get. apt-get is supported on every Debian distro, while apt is only supported since Debian 8. For this guide, I'll be using apt-get, but you could swap these for apt.

Installing a new package:

example@example-laptop:~$ sudo apt-get install figlet
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  figlet
  0 upgraded, 1 newly installed, 0 to remove and 16 not upgraded.
  Need to get 190 kB of archives.
  After this operation, 744 kB of additional disk space will be used.
  Get:1 http://us.archive.ubuntu.com/ubuntu yakkety/universe amd64 figlet amd64 2.2.5-2 [190 kB]
  Fetched 190 kB in 0s (1,508 kB/s)
  Selecting previously unselected package figlet.
  (Reading database ... 299558 files and directories currently installed.)
  Preparing to unpack .../figlet_2.2.5-2_amd64.deb ...
  Unpacking figlet (2.2.5-2) ...
  Setting up figlet (2.2.5-2) ...
  update-alternatives: using /usr/bin/figlet-figlet to provide /usr/bin/figlet (figlet) in auto mode
  Processing triggers for man-db (2.7.5-1) ...

For some packages, you will be asked to confirm you want to install them. For those, just press enter to accept. Now let's remove figlet:

example@example-laptop:~$ sudo apt-get remove figlet
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  figlet
  0 upgraded, 0 newly installed, 1 to remove and 16 not upgraded.
  After this operation, 744 kB disk space will be freed.
  Do you want to continue? [Y/n] 
  (Reading database ... 299630 files and directories currently installed.)
  Removing figlet (2.2.5-2) ...
  update-alternatives: using /usr/bin/figlet-toilet to provide /usr/bin/figlet (figlet) in auto mode
  Processing triggers for man-db (2.7.5-1) ...

Instead of remove, you can also use purge. The only difference is purge also removes all configuration files while remove keeps them.

To know what needs upgrading and what is in its current version, apt keeps a database of the current versions of all its packages and what they should be at. To refresh this list, you use update.

example@example-laptop:~$ sudo apt-get update
Hit:1 http://us.archive.ubuntu.com/ubuntu yakkety InRelease
Get:2 http://us.archive.ubuntu.com/ubuntu yakkety-updates InRelease [102 kB]   
Ign:3 http://dl.google.com/linux/chrome/deb stable InRelease                   
Get:4 http://us.archive.ubuntu.com/ubuntu yakkety-backports InRelease [102 kB] 
Hit:5 http://dl.google.com/linux/chrome/deb stable Release                     
Get:6 http://security.ubuntu.com/ubuntu yakkety-security InRelease [102 kB]    
Hit:7 http://ppa.launchpad.net/nextcloud-devs/client/ubuntu yakkety InRelease 
Get:8 http://us.archive.ubuntu.com/ubuntu yakkety-updates/main amd64 Packages [287 kB]
Get:9 http://us.archive.ubuntu.com/ubuntu yakkety-updates/main i386 Packages [281 kB]
Get:10 http://us.archive.ubuntu.com/ubuntu yakkety-updates/main amd64 DEP-11 Metadata [147 kB]
Get:11 http://us.archive.ubuntu.com/ubuntu yakkety-updates/main DEP-11 64x64 Icons [102 kB]
Get:12 http://us.archive.ubuntu.com/ubuntu yakkety-updates/universe amd64 Packages [180 kB]
Get:13 http://us.archive.ubuntu.com/ubuntu yakkety-updates/universe i386 Packages [178 kB]
Get:14 http://us.archive.ubuntu.com/ubuntu yakkety-updates/universe amd64 DEP-11 Metadata [121 kB]
Get:15 http://us.archive.ubuntu.com/ubuntu yakkety-updates/universe DEP-11 64x64 Icons [164 kB]
Get:16 http://us.archive.ubuntu.com/ubuntu yakkety-backports/main amd64 DEP-11 Metadata [3,328 B]
Get:17 http://us.archive.ubuntu.com/ubuntu yakkety-backports/universe amd64 DEP-11 Metadata [4,668 B]
Get:19 http://security.ubuntu.com/ubuntu yakkety-security/main amd64 DEP-11 Metadata [24.3 kB]
Get:20 http://security.ubuntu.com/ubuntu yakkety-security/main DEP-11 64x64 Icons [38.8 kB]
Get:21 http://security.ubuntu.com/ubuntu yakkety-security/universe amd64 DEP-11 Metadata [22.3 kB]
Get:22 http://security.ubuntu.com/ubuntu yakkety-security/universe DEP-11 64x64 Icons [33.6 kB]
Fetched 1,893 kB in 0s (2,820 kB/s)                                
Reading package lists... Done

To upgrade your system, use upgrade:

example@example-laptop:~$ sudo apt-get upgrade
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
The following packages have been kept back:
  linux-generic linux-headers-generic linux-image-generic
The following packages will be upgraded:
  click gir1.2-click-0.4 libc-bin libc-dev-bin libc6 libc6:i386 libc6-dbg
  libc6-dev libclick-0.4-0 linux-libc-dev locales multiarch-support
  python3-click-package
13 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
Need to get 16.5 MB of archives.
After this operation, 29.7 kB of additional disk space will be used.
Do you want to continue? [Y/n]

Networking

In modern-day Linux, there are two primary packages for controlling the networking of a system: iproute2 and net-tools. Some newer systems only support iproute2, and older systems only support net-tools. I'll go over both commands since they are both very important to know.

Checking the ip address information of a system using iproute2:

example@example-laptop:~$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp1s0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
    link/ether c8:5b:76:80:57:ac brd ff:ff:ff:ff:ff:ff
3: wlp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 78:45:61:c8:66:97 brd ff:ff:ff:ff:ff:ff
    inet 192.168.11.56/24 brd 192.168.11.255 scope global dynamic wlp2s0
       valid_lft 2941sec preferred_lft 2941sec
    inet6 fe80::d2cb:3dc4:3768:9609/64 scope link 
       valid_lft forever preferred_lft forever

Using net-tools:

example@example-laptop:~$ ifconfig
enp1s0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether c8:5b:76:80:57:ac  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 394230  bytes 25342896 (25.3 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 394230  bytes 25342896 (25.3 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlp2s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.11.56  netmask 255.255.255.0  broadcast 192.168.11.255
        inet6 fe80::d2cb:3dc4:3768:9609  prefixlen 64  scopeid 0x20<link>
        ether 78:45:61:c8:66:97  txqueuelen 1000  (Ethernet)
        RX packets 213388  bytes 247292973 (247.2 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 117386  bytes 17271763 (17.2 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Checking routing information using iproute2:

example@example-laptop:~$ ip route
default via 192.168.11.1 dev wlp2s0  proto static  metric 600 
192.168.11.0/24 dev wlp2s0  proto kernel  scope link  src 192.168.11.56  metric 600

Using net-tools:

example@example-laptop:~$ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.11.1    0.0.0.0         UG    600    0        0 wlp2s0
192.168.11.0    0.0.0.0         255.255.255.0   U     600    0        0 wlp2s0

Setting a route using iproute2:

example@example-laptop:~$ sudo ip route add 192.168.1.0/24 via 192.168.11.1

Using net-tools:

sudo route add -net 192.168.1.0/24 192.168.11.1

In general, you want to use iproute2 when you can because it has extra functionality like recursive routing, but net-tools works in most cases.

Symlinks

A symlink or symbolic link is a file that is just a reference to another file. For example, if you wanted to have a user be able to edit their webpage files, but you didn't want them to have to go to /var/www every time, you can add a symlink for them:

example@example-laptop:~$ ln -s /var/www www
example@example-laptop:~$ ls
Desktop  Documents  Photos  Videos  vimresults.txt  www

Now, whenever the user adds a file to www, they are actually editing in /var/www.

Bash Alias

A Bash Alias is effectively a shortcut that binds a letter or sequence of letters to a command in the Terminal. They are mainly used to change commonly used long commands into short keystrokes to save time while quickly navigating around your file system. Alias' are defined in the following format:

alias alias_name='bound_command'

alias_name is the keystroke that will trigger the bound_command.

For example:

example@example-laptop:~/home$ ls
doc1.txt  doc2.txt  doc3.txt
example@example-laptop:~/home$ alias l='ls'
example@example-laptop:~/hom

Here 'l' was binded to 'ls'. To undo a alias, you can say:

example@example-laptop:~/home$ l
doc1.txt  doc2.txt  doc3.txt
example@example-laptop:~/home$ unalias l
example@example-laptop:~/home$ l
bash: l: command not found

The unalias command removes the alias from the phrase/letter.

When manually entering alias' into the terminal, they will only last for that specific session. To avoid reentering alias every time you open a window, you can add them to the .bashrc file using your favorite text editor. For example, if I wished to add the previous 'l' command to the file:

# bash alias
alias l='ls'

Note that the comment is not pre written. To list all commands use alias with no arguments:

example@example-laptop:~$ alias
alias l='ls'

Finally, to bypass an alias, use a backslash before the command. For example:

example@example-laptop:~$ alias ls='ls -a'
example@example-laptop:~$ ls
.           .config         Downloads        Music      .ssh          .viminfo
..           dash-to-dock  .gconf        Pictures   .subversion    .vimrc
.bash_history  .dbus         .gnupg        .pki       SVN_Checkouts
.bash_logout   debian         .ICEauthority  .profile   Templates
.bashrc        Desktop         .local        Public     Videos
.cache           Documents     .mozilla        rwtrainer  .vim
example@example-laptop:~$ \ls
dash-to-dock  Desktop     Downloads  Pictures  rwtrainer      Templates
debian          Documents  Music        Public    SVN_Checkouts  Videos

Basic Commands

##Command                              ##Description
cat [filename]                         ##Display file’s contents in the terminal
cd /directorypath                      ##Change to directory.
chmod [options] mode filename          ##Change a file’s permissions.
chown [options] filename               ##Change who owns a file.
clear                                  ##Clear a command line screen/window for a fresh start.
cp [options] source destination        ##Copy files and directories.
date [options]                         ##Display or set the system date and time.
df [options]                           ##Display used and available disk space.
du [options]                           ##Show how much space each file takes up.
file [options] filename                ##Determine what type of data is within a file.
find [pathname] [expression]           ##Search for files matching a provided pattern.
grep [options] pattern [filesname]     ##Search files or output for a particular pattern.
kill [options] pid                     ##Stop a process. If the process refuses to stop, use kill -9 pid.
less [options] [filename]              ##View the contents of a file one page at a time.
ln [options] source [destination]      ##Create a shortcut.
locate filename                        ##Search a copy of your filesystem for the specified filename.
lpr [options]                          ##Send a print job.
ls [options]                           ##List directory contents.
man [command]                          ##Display the help information for the specified command.
mkdir [options] directory              ##Create a new directory.
mv [options] source destination        ##Rename or move file(s) or directories.
nano [filename]                        ##Edit a file
passwd [name [password]]               ##Change the password or allow (admin)to change any password.
ps [options]                           ##Display a snapshot of the currently running processes.
pwd                                    ##Display the pathname for the current directory.
rm [options] directory                 ##Remove/delete file(s) and/or directories.
rmdir [options] directory              ##Delete empty directories.
ssh [options] user@machine             ##Remotely log in to another Linux machine, over the network.
su [options] [user [arguments]]        ##Switch to another user account.
tail [options] [filename]              ##Display the last n lines of a file (the default is 10).
tar [options] filename                 ##Store/extract files from a .tar file or .tgz file.
top                                    ##Displays the resources being used on your system. q to exit.
touch filename                         ##Create an empty file with the specified name.
who [options]                          ##Display who is logged on.

Files