What is a Shell

A shell is a tool we use to interact with a computer. It is pretty powerful. There are a few basic commands that will help you navigate the computer using a shell.

Frequently Used Shell Commands

ls

ls is a command that lists all files in the current directory. If you had a directory that had three files in it, file1.txt, file2.txt, and file3.txt, and you ran ls, you would see something like:

    (trusty)root@localhost:~# ls
    file1.txt  file2.txt  file3.txt

cd

cd is a command that changes what directory you are currently in. If you are currently in directory A, and want to go up one level, you would use ‘../’ as the directory you want to change to. For example, if you have a folder called ‘Downloads’, you could access that directory contents by running cd Downloads:

    (trusty)root@localhost:~# cd Downloads/
    (trusty)root@localhost:~/Downloads#

mkdir

mkdir is a command that creates a new directory. For example, to create a new directory called ‘files’ you would run ‘mkdir files’ as seen here:

    (trusty)root@localhost:~# ls         
    Desktop  Documents  Downloads  Music  Pictures  Public  Templates  Videos
    (trusty)root@localhost:~# mkdir files
    (trusty)root@localhost:~# ls
    Desktop    Downloads  Pictures  Templates  files
    Documents  Music      Public    Videos

nano

nano opens a file in the nano text editor. If you want to create a file, you can run nano to create that file, and open it.

We can see a demo of nano in action in the below demonstration.

cat

cat prints the contents of a file. If we have a file named ‘file.txt’ which contains the words ‘this is a file’, we can see its contents using cat.

(trusty)root@localhost:~# ls
Desktop    Downloads  Music     Public     Videos
Documents  file.txt   Pictures  Templates
(trusty)root@localhost:~# cat file.txt
this is a file

rm

rm is a dangerous command. It removes files. If we have a text file named ‘file.txt’ we can remove it with rm:

(trusty)root@localhost:~# ls
Desktop    Downloads  Music     Public     Videos
Documents  file.txt   Pictures  Templates
(trusty)root@localhost:~# rm file.txt
(trusty)root@localhost:~# ls
Desktop  Documents  Downloads  Music  Pictures  Public  Templates  Videos
(trusty)root@localhost:~#

Demonstration

Here is a short demo making use of all of these commands.

This terminal recording can be found at asciinema.org.
  Previous: Intro to Git