Linux Basics

Unix/Linux

They are a powerful class of operating systems, designed to support the needs of programmers. They are multiuser, uses a unified file system, and are heavily based on the command-line interface called the "shell." They are designed to automate tasks. Putting in upfront effort reduces the manual effort needed later, which is called "long-term lazy" (slower to learn, faster to use).

Directory means the same thing as folder. All files and directories are referred as "paths".

Connecting to ugrad from your own computer

Windows: download PuTTy, set Host Name as ugradx.cs.jhu.edu, type account name (JHED), and password. Mac: open Terminal, then type the command ssh <your-username>@ugradx.cs.jhu.edufont-family: monospace; Linux: open terminal and use ssh <your-username>@ugradx.cs.jhu.edu.

Command Line

Unix/Linux commands are case-sensitive. Learn Unix/Linu command line from this boot camp.

Basic Commands

Copying Files

cp command in Unix is how we copy files within one machine. scp and pscps command is secure copy, a way to transfer copies from one machine to another.

In Mac Terminal or Windows Power Shell, use scp <source> <destination>.

In Windows with PuTTY, use pscp <source> <destination> in Command Prompt.

Ugrad to Local

scp <username>@ugradx.cs.jhu.edu:<filename>.c .

(in Mac Terminal or Windows Power Shell).

For example,

scp ltran29@ugradx.cs.jhu.edu:HW1/file.c xyz/

Zipping

zip zipped_files.zip file1.c file2.c gitlog.txt

Packs up three files into a zipped_files.zip.

To confirm that it contains what you want,

unzip -1 zipped_files.zip

To unpack the zip file (i.e., extract its file),

unzip zipped_files.zip

Move and unpack in a new/different folder to avoid overwriting the original files.

I/O Redirection

When executing a command that produces output, redirect the result to a textfile (instead of on screen) by using '> outfile':

ls > myfiles.txt

When executing a command that takes input, redirect input from a plain txt file by using '< infile':

less < infile.text

Use both at once, or use a pipe command '|' to send the standard output of one command directly into standard inputfor another command. For example, to list your files but view the list one screenful at a time use:

ls | less

Homework workflow

  1. Write code, compile, test, and edit while continuously adding, committing, and pushing changes to personal git repo.
  2. Generate gitlog.txt file to document your commits using git log > gitlog.txt.
  3. Bundle files for submission with zip hw0.zip file1.c file2.c gitlog.txt.
  4. Confirm that your zip files contains everything with unzip -1 hw0.zip.
  5. Transfer the bundle onto local machine using scp <username>@ugradx.cs.jhu.edu:<HW0/hw0.zip .
  6. Upload hw0.zip to Gradescope. Wait for feedback and resubmit (only last one is graded).

Tips