Linux and CS Systems - Getting Started

From Computer Science
Jump to: navigation, search

This page is meant to help a new student in a CS course at ISU to get familiar with using Linux (in particular using the text-based terminal to interact with the system).

Getting Started

  1. Read - Ubuntu Linux Command Line Tutorial or Linux Tutorial - this gives you some background and introduces you to some of the terms that we use. After reading through the tutorial you have a better chance of being able to follow along the rest of the steps in this Getting Started.
  2. System Setup - Linux - System Setup - to get your computer setup (programs installed, etc.).
  3. Using the Terminal
    1. Linux Terminal - Files and Directories and Getting Around
    2. Linux Terminal - System Information
    3. Linux Terminal - Text Editors
    4. Using Linux - Large Text Files
    5. Linux Terminal - More Commands to Know

Common Mistakes

  • When logging in remotely to the CS server, when you are typing your password you might not see anything printed on your screen while you type. That is a security feature so that someone watching your screen would not know how many characters are in your password. Just finish typing your password and type enter when finished.
  • Note that all commands and file names in Linux are case sensitive. hello.txt is different than Hello.txt. The copy command is cp, Cp would not work, and neither would cP or CP.
  • The characters _ and - are different, and having a space in a file name is different than not having one ("hello world.txt" is different than "helloworld.txt").
  • For Linux directories and filenames, the "/" character is used to separate directories. On Windows, the "\" character is used instead. If you typed
    cd /u1/class
    then this changes the directory to the class directory that is inside of the u1 directory. If you instead typed
    cd \u1\class
    you would get an error.
  • The "top" or "highest level" of the Linux file system is the directory / and this is comparable to the "C:\" that was traditionally the top of the file system in Windows. In Windows there can be multiple drives (so D:\, E:\, etc.), but in Linux everything is underneath / (including additional drives, they will show up at a certain location under /).
  • On Linux, ~ is a shortcut for your home directory. User cs15100's home directory is in /u1/class/cs15100/, so if cs15100 is logged in and types
    cd ~
    then this means to change directories to /u1/class/cs15100/. If user jkinne types
    cd ~
    then this means to change directories to jkinne's home directory (which happens to be /u1/h0/jkinne/).
  • Not all sequences of commands are idempotent - this is a technical term that means that the sequence of commands gives the same results if executed more than once. For example, executing echo "hello world!" >> hello.txt once creates a file hello.txt that has one line in it, but executing again makes the file have two lines. When you see a sequence of commands to run to complete some task (e.g., from an online tutorial) be careful to execute one command after the other, all the way through, stopping after each to make sure you know what that step was supposed to do.
  • Sometimes the precise syntax of commands might depend on which shell program you are using. tcsh is the default shell program on the CS server, but bash and zsh are also commonly used instead. You can see which shell you are running by executing the ps command and seeing which one is in the printed output from that command. For example, the command for displaying your resource limits is ulimit -a in bash and zsh, but is limit in tcsh. When looking up how to do things online, it is good to include your shell in the search terms (e.g., search for - bash get resource limits - rather than just - get resource limits).

More Reading

Read through another tutorial about Linux. Some options include the follow.

Self Test

Note: a practice quiz over linux commands and the terminal is here - https://indstate.instructure.com/courses/12565/quizzes/244584

Here we give small tasks for you to complete. These are numbered so that we can refer to them. For each you would need to be logged into one of the CS systems (remotely logged into the CS server or using one of the CS lab computers).

Linux.0 Log in to the CS server, and run the chfn command to put your name into the system. You can leave all the other fields blank (just type enter). Also, use the chsh command to change your default shell from /bin/tcsh (or whatever it is) to /bin/bash

Linux.1 Log in to the CS server, create a directory named aboutMe in your home directory, and create a text file name.txt. In the name.txt file, give your full name.

Linux.2 In your aboutMe directory, create a file courses.txt and list which CS courses you are currently taking or plan to take in the upcoming term.

Linux.3 Log in to the CS server, create a directory named notes in your home directory, and create a text file named linux.txt and put in some links to linux tutorials or information that you have found helpful.

Linux.4 Log in to the CS server, create a directory named linux-bootcamp in your home directory.

Linux.5 In your linux-bootcamp directory, create a text file shake.txt. In shake.txt, put how many lines are in the shakespeare.txt file mentioned in the information above.

Linux.6 In your shake.txt file, add information about how many times "the" appears in shakespeare.txt. Use the command grep, add to what you had how many lines "the" appears in shakespeare.txt. Hint - use the -c option for grep, also use the -i option so your count will also include "The", "THE", etc. In your shake.txt, you should have the number of lines that contain "the" (including "The", etc.), and also the percentage of the lines that contain the.

Linux.7 In your linux-bootcamp directory, create a text file weather.txt. Copy the Indianapolis weather csv file from /u1/junk/weather/ into your linux-bootcamp directory. In your weather.txt file, put how many rows of data are in the csv file (use wc, head, and tail). Assuming 365 days per year, put in your weather.txt file how many years of data are in the csv file.

Linux.8 In your weather.txt file, put the maximum PRCP, SNOW, SNWD, TMAX, TMIN, MEAN from the csv file. Hint - use the sort command, and use the options -t, -k, -n, -o.

Assignment 0

The following is a typical first assignment to get started in Linux on the CS server. Here we assume your login on the server is YOUR_LOGIN (this would typically be something like cs15100 for a class account or something like jkinne for a permanent CS account).

Account Configuration

Update your password, change your "finger" information (put your true name and can leave the rest blank), and set your normal shell. You execute each of these commands, one after another.

passwd
chfn
chsh -s /bin/bash YOUR_LOGIN

You can see which other shells you can choose from (other than bash) with cat /etc/shells. Bash reads configuration information from a file ~/.bashrc. A file with good defaults for the CS server are at .bashrc. More help on bash - bash manual.

If you want to see what commands you have run in the current login session you can run the command history. Bash also keeps history from previous sessions in the file ~/.bash_history.

If you use your account to login to the GUI on one of the CS lab computers then some directories will be created in your account (e.g., Downloads, Documents, etc.). You should create the following as well and use (a) your bin directory to put programs or scripts that you have downloaded or created that you want to be able to use, (b) your programs directory to put installation files for programs that you might need, (c) your private directory to keep files you want to make sure to keep private from other users, and (d) your public_html directory to store files that you want to be accessible on the web (at https://cs.indstate.edu/~YOUR_LOGIN).

mkdir ~/bin/
echo "export PATH=$PATH:~/bin/" >> .bashrc  # add the ~/bin/ directory to where shell looks for programs
mkdir ~/programs/
mkdir ~/private/
chmod go-rwx ~/private/    # makes that directory not accessible to other users
mkdir ~/public_html/
chmod go+rx ~/public_html/ # so the web server can access this directory
chmod go+x ~               # so the web server can access your public_html

Copying/Creating/Editing Files

Create a file in your public_html directory, and practice copying a file from somewhere else on the system.

cd ~/public_html
nano hello.txt  # or use your preferred editor - vim, emacs, jove, ...
# type something in your hello.txt file, save it, and
#  check that you can view it at https://cs.indstate.edu/~YOUR_LOGIN/hello.txt
cp /usr/dict/words . # copies that file into current directory, which should still be your public_html
# now check https://cs.indstate.edu/~YOUR_LOGIN/words

Create a sub-directory within your public_html directory, put some file there, edit the Apache configuration file (.htaccess) to allow directory listing of this directory (turned off by default for security reasons).

cd ~/public_html
mkdir files_public
cd files_public
echo "Options +Indexes" >> .htaccess
ls -a         # verify that the .htaccess file exists now
cat .htaccess # see what is in the file now
cp /u1/junk/kinne/text-samples/shakespeare.txt .
cp /u1/junk/kinne/text-samples/austen.txt .
# Now browse to https://cs.indstate.edu/~YOUR_LOGIN/files_public