Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Linux

From Nest Guides
(Redirected from Using The Terminal)

Every computer that you use has an operating system. An operating system manages your computer's resources and makes sure that everything running on your computer, from the internal system tools to the web browser you're using to read this, has time to run. Popular operating systems include Windows, MacOS, and Linux!

Linux isn't used as much as Windows and MacOS for personal computers, but it's still popular among developers and enthusiasts. However, Linux is the standard for servers! That's why we use Linux for Nest. It's a little different from what you might be used to, but you'll be working with Linux in no time!

Linux used a text-based user interface (TUI) rather than a graphical user interface (GUI). This means that instead of moving your cursor around with a mouse or trackpad and clicking on items, you simply type commands for the computer to execute.

Using the Terminal

The default interface on Linux is the terminal. Other operating systems also have a terminal - on Windows, it's an app called cmd.exe or PowerShell, and on MacOS, it's just called Terminal.

Once you've entered the terminal, you will be greeted with a prompt like this:

username@hostname:~$

Note that for other systems, it may look different, but this is generally how terminal prompts look on Linux.

To run a command, simply type your command and press the 'Enter' or 'Return' key. Once you do, the output of the command will be displayed right below the prompt. For example, if you type:

~$ echo "Hello, world!"

and press 'Enter', your terminal will read:

~$ echo "Hello, world!"
Hello, world!
~$

The echo command 'echoes' whatever is after it:

~$ echo "I am creating a website using Nest!"
I am creating a website using Nest!
~$

Commands are usually of the format command options arguments. Options are usually prefixed with one or two dashes (ie, -o --option). One dash signifies an option that is one letter long, and allows you to chain options (ie, -al is the same as -a -l). Two dashes signify a single option which is usually an entire word or phrase (ie, --output). It is important to note that all commands follow these rules, and not all commands have the same options. You can usually check a command's manual page using man command to get a list of options, or run the command with -h or --help to get information about the command.

Notice how the ~$ is repeated at the end. Whenever you see the ~$ (or your computer's equivalent), it means that your terminal is ready for another command.

Other linux commands that are useful to know include:

  • cd, Change Directory - Notice the tilde (~) or path (C:\Users\username) in the examples above? That is known as your current working directory, or CWD. It corresponds to the folder that your terminal is in, and will affect what certain commands do. Using cd, you can change your working directory:
~$ cd Documents
~/Documents$

Folders can be nested inside other folders, indicated with a slash (/). On windows, a backslash (\) is used instead. the tilde (~) corresponds to your home directory, which is /Users/username on macOS and /home/username on Linux.

  • ls, List - This command will list what files and folders exist in the CWD or path provided:
~$ ls
Desktop  Documents  Downloads 
~$ ls Documents
Contract.pdf  Taxes  Work

Adding -l expands the list and provides more information:

~$ ls -al
drwxr-xr-x 2 username group 4096 Dec 17 06:43 Desktop
drwxr-xr-x 2 username group 4096 Dec 18 22:22 Documents
drwxr-xr-x 2 username group 4096 Nov 12 15:08 Downloads
~$ ls -al Documents
-rw-r--r-- 1 username group  524288 Dec 18 22:22 Contract.pdf
drwxr-xr-x 2 username group    4096 Apr 21 07:32 Taxes
drwxr-xr-x 2 username group    4096 Dec 18 15:43 Work
But what does something like drwxr-xrw- mean?

There are 4 parts to this: d, rwx, r-x, and rw-

d- Indicates this is a directory. Notice how Contract.pdf does not have this letter in its permission string.

rwx -> r stands for read, w stands for write, and x stands for execute. The first 3 letters indicate the permissions for the file owner. The file owner is named right after the permission string: username. rwx means the file owner can read, write, and execute the file.

r-x -> The second group is for the group, in this case just group. Group can be a bunch of users combined. r-x means people in the group can read and execute the file but can't write.

rw- -> The third and final group is for everyone else. Here, everyone else can read and write but can't execute.

  • mkdir - this command creates a new directory.
  • cat - This command reads the contents of a file
  • nano, vi - These are text editors. nano is recommended for beginners due to its ease of use.
To use nano:
~$ nano newfile.txt

This will pull up a file editor with a blank screen or the file content, based on whether the file exists or not. Once you're done, hit CTRL + X, click y to confirm you'd like to save, confirm the file name, and click enter to save.

Running File Programs in the Background

Need to keep a script running after you close your SSH session? nohup tells the process to ignore your leave and keep running.

~$ nohup [command to run] > [file.log] &