Introduction

Welcome to the Linux playground server. This guide will get you comfortable with the Linux command line and familiar with some basic tools. Commands and other technical references will be formatted as monospace text.

Connecting

If you’re using macOS or Linux, open the terminal and type the following command: ssh [user]@[server]. Replace [user] with the username you were assigned. If you’re on Windows, install PuTTY. Open the application and type [user]@[server] into the hostname field, then click Open.

Once connected, type or click yes when asked if you want to confirm the host key verification. This is shown whenever you connect to a new machine to ensure it’s authenticity. Type in the password given in the email and press enter. As a security measure, nothing you type will be shown, not even asterisks.

Navigating

Once you get a long system message and a prompt that looks something like [user]@[server]:~$, you’re in! You start off in your home directory, type pwd to check that you’re in your home directory of /home/[user]. Type ls to list the files in the current directory. Type cd [folder] to move into a new directory, cd - to move to the previous directory, and cd .. to move out of a folder. To read files, type cat [file]. This will print the contents of the file directly to the terminal.

Before we go any further, we should learn how to look up documentation for commands right within the system. To access the manual pages, type man [command] to get a command’s usage manual. RTFM! Reading the entry for cat, you’ll notice letters and words with dashes preceding them. These are called arguments, and are used to modify the behavior of a command. Some arguments take parameters, while some can be used alone like switches. Try using cat with the -n argument, as cat -n [file]. Figured out its function yet?

Web

The first thing we’ll show you is user-level web hosting. Notice the web folder in your home directory. Anything you place in here will be publicly accessible on the web at linux.clementscsnhs.org/~[user]. To show a custom page instead of a file list, create an index.html file. It’s okay if you don’t know any HTML, filling it with plain text will also work, but lack any styling. Feel free to make your personal page as simple or complex as you like.

Files

Create a new file with the touch command (be careful about spaces). To edit a file, type nano [file]. Once inside, move around with the arrow keys and type as you normally would. Try typing your name. To exit, press Ctrl-X and choose whether or not to save. If saving, you will be asked to confirm the filename again. You can create, move, copy, and remove files with touch, mv, cp, and rm, respectively.

Users

Let’s see who else is logged in right now. Type finger to list the currently logged in users. Add a username to the command to get detailed information. By default, every user’s home directory is publicly accessible at /home/[user]. You’ll have to adjust permissions in order to make files inaccessible.

Mail

Let’s try sending an email to another user on the system. The original mail command is archaic and hard to use, so we’ll be using the alpine mail client. Usage is pretty self-explanatory with navigation keys shown throughout the program. Once you get to the compose screen, simply enter another user’s username, no @ or domain required. The system isn’t configured to send external mail, and will fail if you try to do so. Check back later to see if anyone sent you a message, or to discover that you have no friends.

Standard Input/Output

Essential to understanding the shell are concepts of standard input (stdin) and standard output (stdout). This refers to input and output that a program is given or produces, if any. By default, these read and write directly from and to the shell, but we can also direct programs to set stdin or stdout to read from or write to files. The character representing standard input is < and the character representing standard output is >. Let’s use figlet, a simple program that produces large text, to demonstrate.

If you run figlet alone, you’ll be given a blank prompt in which anything you enter will be printed back to you in large text. Press Ctrl-C to exit (a common way to end processes). Now try taking input from the text file you created with figlet < file.txt. Now try redirecting output of another program into a file. For example, you could create a file with a random fortune by typing fortune > fortune.txt. If the specified file does not exist, it will be created; if it does exist, it will be overwritten. To append to files instead of overwriting them, use >>. Run figlet a few times while appending the output into a file and check the result.

Piping

This kind of output redirection can be very useful when combining several commands. However, the output redirection we’ve shown so far can only connect a single command to a single file. To "pipe" multiple commands together, we use the | character (located above the enter key on most keyboards). The pipe takes the output of a command and redirects into the input of another command. To display the current date and time as large characters, type date | figlet.

Understanding how to pass text between commands is the most important shell concept. Because plain text is the medium over which information is transferred, being able to edit and filter this text is very important. We’ll teach you five useful commands for processing text.

Text Analysis

The head and tail commands are some of the simplest commands for modifying input. Supplying head with input exceeding ten lines will result in only the first ten lines being outputted. You can modify the number of lines outputted by providing the number as an argument, like so: head -5. Hopefully you can guess how many lines that will keep. Usage of the tail command is identical to that of head.

The next command we’ll cover is sort. I really don’t feel like explaining what a command named sort could possibly do, so experiment and figure it out yourself. A less intuitive command is uniq, which removes identical lines with one condition: it only removes adjacent duplicate lines. I wonder if there’s any command that would result in the same lines being placed next to each other? See if you can combine several commands together with pipes to remove all duplicates in names.txt.

Perhaps the most powerful command in your Unix toolbox is grep, a powerful pattern-matching utility that uses regular expressions to search text. No worries if you don’t know regex, it’s still useful for matching literal strings. A variety of modifiers exist, such as -i, which will ignore differences in case. If you find grep useful, you’ll also want to take a look at sed, the editing equivalent. Try searching seuss.txt for every line containing a certain word, such as car.

Extra

If you’ve gotten to the end and still want to explore more, check out the following commands. We won’t provide instructions, so you’ll have to check the manual pages to learn how to use them yourself. Beyond that, just play around and experiment however you wish.

history - Command history

tldr - Simplified man pages

tree - Visualize file hierarchy

cal - Show a visual calendar

less - Scroll through large files

file - Determine a file’s type

wc - Line/word/character counter

curl - Download files

w3m - Browse the web

vimtutor - Learn a powerful text editor (abandon all hope ye who enter here)