Basic Linux commands

Our server storm.cis.fordham.edu is a Fedora Linux machine. Here’s how to use your account there.

Write your temporary secret password on a piece of paper and don’t lose it. Then invent a permanent secret password for yourself and write it down too. (My permanent secret password contains uppercase letters, lowercase letters, and digits.) If you lose your password, you can request a new one with this form. But do yourself a favor and don’t lose it.

The “secure shell” ssh

To log into your account on storm.cis.fordham.edu,

In both cases, a window will appear. See if you can enlarge the font in the window. In this window (assuming your Fordham name is jsmith), give the following lowercase ssh command with a space after the ssh. The first time you use ssh, give it your temporary secret password. The characters of this password will not be echoed onto the screen as you type them: you’re flying blind. The computer will ask you to type your temporary secret password again so that you can replace it with a new password of your own choosing.

Run the date, cal, and uname programs in response to the green prompt just to verify that you’re connected to storm.cis.fordham.edu, and to build your confidence.

ssh jsmith@storm.cis.fordham.edu
Are you sure you want to continue connecting? yes
Password:

date
Tue Jan 28 05:39:04 PM EST 2025

cal
    January 2025    
Su Mo Tu We Th Fr Sa
          1  2  3  4
 5  6  7  8  9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31   

uname -a
Linux storm.cis.fordham.edu 6.12.7-100.fc40.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Dec 27 17:00:45 UTC 2024 x86_64 GNU/Linux

Travel up and down the directories

Type a space after the (lowercase) cd command. Do not type any space betwen the two dots.

pwd     (print working directory)
/home/students/jsmith

cd ..   (change directory, space after cd.  2 dots means "one level up")
pwd
/home/students

cd ..
pwd
/home

cd ..
pwd
/        (Now you're in the "root directory".  Can't go any higher.)

cd ..    (Try to go higher.  You can't.)
pwd
/        (You're still in the root directory.)

cd       (Go straight back to your home directory.)
pwd      (Make sure you returned there.)
/home/students/jsmith

cd .      (Does nothing: one dot means your current directory.)

Three distant directories you can go to

Type a space after the (lowercase) cd command.

cd /usr/bin       (the "user binary" directory)

pwd               (Make sure you arrived there.)
/usr/bin

ls                (List (lowercase LS) will list all the files and subdirectories.)
ls | more         (Dole it out one screenful at a time. Space bar or q)
ls -l | more      (Space minus lowercase L for more information about each one)
                  (Files start with dash; subdirectories start with lowercase d)

ls -l c++         (List only one file.  This is our C++ compiler.)
-rwxr-xr-x 4 root root 1209888 Sep 11 20:00 c++
cd /usr/include/c++/14
pwd               (Make sure you got there.)
/usr/include/c++/14

ls -l iostream
-rw-r--r-- 1 root root 3094 Sep 11 20:00 iostream
cd ~mmeretzky     (Go to my home directory. Tilde in front of loginname.)
pwd               (Make sure you got there.)
/home/staff/mmeretzky 

cd                (Go back to your home directory.)
pwd               (Make sure you got there.)
/home/students/jsmith

Your home directory, and your public_html directory below it

The files in your public_html directory are publicly visible. See CISC-1100-C01 and CISC-2000-E01

cd                (Go back to your home directory.)
pwd               (Make sure you got there.)
/home/students/jsmith

ls -l | more      (See what you already have there.)

cd public_html    (Go one level down to your public_html directory.)
pwd               (Make sure you got there.)
/home/students/jsmith/public_html

ls -l | more      (See what (if anything) you already have there.)

cd                (Go back up to your home directory.)
pwd               (Make sure you got there.)
/home/students/jsmith

Housekeeping: rename, copy, move, remove a file

Let's create an empty file named junk in your home directory. When you move a copy of this file down to your public_html subdirectory, can you see it in CISC-1100-C01 or CISC-2000-E01?

cd                (Go back to your home directory.)
pwd               (Make sure you got there.)
/home/students/jsmith
ls -l | more      (See what (if anything) you already have there.)

touch junk        (Create an empty file named junk.)
ls -l junk        (See if you actually created this file.)

mv junk junk2     (Change the name of the file from junk to junk2.)
ls -l junk2       (Did we actually rename the file?)

cp junk2 junk3    (Create a copy of junk2 named junk3.)
ls -l junk2 junk3  (Did we create a copy? Is the original file still there?)

mv junk3 public_html  (Move junk3 down to your public_html subdirectory.)
cd public_html    (Go down there and make sure you moved the file there.)
pwd
ls -l junk3       (Can you see this file in the class website?)

rm junk3  (Remove the file that we moved down into your public_html.)

cd                (Go back up to your home directory.)
pwd
rm junk2          (Remove the file.)

Download a text file from the class website

Let’s download the text file xanadu.txt from the class website. Before downloading the file, make sure you’re in your own home directory because you want to be in a directory in which you have permission to deposit a new file.

cd
pwd
/home/students/jsmith

wget https://markmeretzky.com/fordham/1600/src/xanadu.txt
HTTP response 200 OK
ls -l xanadu.txt     (Did we really download the file? How many bytes is it?)

A minimal set of vi commands

Practice editing the file xanadu.txt with the vi “visual” text editor:

cd
pwd
ls -l xanadu.txt
vi xanadu.txt
  1. Move the cursor around with the four arrow keys;     10G
  2. Delete individual character(s) with (lowercase) x     xxxx     4x
  3. Delete entire line(s) with (lowercase) dd     4dd
  4. Insert character(s) with (lowercase) i (before) or a (after the cursor).
    Then type as much as you want. Stop inserting with the ESCape key.
  5. Insert entire line(s) with lowercase o (below) or uppercase O (above the cursor).
    Then type as much as you want. Stop inserting with the ESCape key.
  6. Copy entire line(s) into the “unnamed buffer” with lowercase yy     4yy
    Then go somewhere else in the file and paste in the copied lines with lowercase p (below) or uppercase P (above) the cursor.
  7. Write the file to disk with (lowercase) :w folowed by RETURN or ENTER.
    But first press ESCape to make sure you’re not in the middle of an insertion.
  8. Quit vi with (lowercase) :q followed by RETURN or ENTER.

After quitting from vi, see if the file you were editing is still in your home directory. Did you change its size (its number of bytes) while you were editing?

ls -l xanadu.txt

CISC-1100-C01 students:
log out

By now, you are probably fatigued or overwhelmed. Give the exit command, followed by another exit command to close your CMD window or your Terminal.app window.

exit
exit

CISC-2000-E01 students:
Download a C++ program from the class website

Let’s download the program places.C. Point your web browser at this file and copy its link
https://markmeretzky.com/fordham/2000/src/binary/places.C
wget means “get from the web”.

cd         (Go home, because you have permission to put a new file there.)
ls -l      (Make sure you don't already have a file named places.C)
wget https://markmeretzky.com/fordham/2000/src/binary/places.C
ls -l places.C   (Make sure the file was downloaded.)

CISC-2000-E01 students:
Compile and execute a C++ program on storm.cis.fordham.edu

Assume you already have a file named prog.C in your home directory. The C must be uppercase.

cd
c++ prog.C        (Should create a file named a.out)
ls -l a.out       (Did it create a file named a.out?)
./a.out           (Execute the a.out file and see its output.)
echo $?           (See the exit status number produced by the a.out file.)

mv prog.C public_html (If you want to let everyone see your prog.C file.)
cd public_html        (Make sure you moved the file.)
pwd
ls -l prog.C

CISC-2000-E01 students:
Create a little C++ program

Create a file named prog.C (with an uppercase C) in your home directory on storm.cis.fordham.edu, containing the following nine lines:

#include <iostream>
#include <cstdlib>
using namespace std;

int main()
{
	cout << "Hello, world!\n";
	return EXIT_SUCCESS;
}

Can you compile and run this file?