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. (A good 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. When you do this, 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 hostname 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 May 27 09:29:24 AM EDT 2025

cal
      May 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

hostname
storm.cis.fordham.edu

Travel up and down the directories

Type a space after the (lowercase) cd command. No 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.)

Two 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 1333320 Apr 24 20:00 c++
cd /usr/include/c++/15
pwd               (Make sure you got there.)
/usr/include/c++/15

ls -l iostream
-rw-r--r-- 1 root root 3125 Apr 24 20:00 iostream
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-L11

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-L11?

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.)
ls -l junk3       (Is it gone?)

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    (See how many bytes are in the file.)
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 lowercase a (after the cursor).
    Then type as much as you want, maybe even more than one line. Stop inserting with the ESCape key in the upper left corner of your keyboard.
  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. But first press ESCape to make sure you’re not in the middle of an insertion.

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-2000-L11 students:
Download a C++ program from the class website

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

cd         (Go home, because you have permission to put a new file there.)
pwd
ls -l      (Make sure you don't already have a file named variable.C)

wget https://markmeretzky.com/fordham/2000/src/review/variable.C
ls -l variable.C   (Make sure the file was downloaded.)

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

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

cd
pwd

ls -l variable.C
c++ variable.C    (c++ should create a file named a.out)
ls -l a.out       (Did c++ 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 variable.C public_html (If you want to let everyone see your variable.C file.)
cd public_html            (Make sure you moved the file.)
pwd
ls -l variable.C

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

Use vi to create a file named helloworld.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?

Log out from storm.cis.fordham.edu

By now, you are probably fatigued or overwhelmed. Give the exit command, followed by another exit command to close your CMD window (on a Windows PC) or your Terminal.app window (on an Apple Macintosh).

exit
exit

Your $PATH environment variable on storm.cis.fordham.edu

echo $HOME
/home/students/jsmith

echo $PATH
/home/students/jsmith/.local/bin:/home/students/jsmith/bin:/usr/local/bin/anaconda3/bin:/usr/local/bin/oclint-22.02/bin:/usr/share/Modules/bin:/opt/maven/bin:/usr/local/bin/miniconda3/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin]:/opt/dell/srvadmin/bin

echo $PATH | tr ':' '\n'
/home/students/jsmith/.local/bin
/home/students/jsmith/bin
/usr/local/bin/anaconda3/bin
/usr/local/bin/oclint-22.02/bin
/usr/share/Modules/bin
/opt/maven/bin
/usr/local/bin/miniconda3/bin
/usr/local/bin
/usr/bin
/usr/local/sbin
/usr/sbin]
/opt/dell/srvadmin/bin

echo $PATH | tr ':' '\n' | cat -n
     1	/home/students/jsmith/.local/bin
     2	/home/students/jsmith/bin
     3	/usr/local/bin/anaconda3/bin
     4	/usr/local/bin/oclint-22.02/bin
     5	/usr/share/Modules/bin
     6	/opt/maven/bin
     7	/usr/local/bin/miniconda3/bin
     8	/usr/local/bin
     9	/usr/bin
    10	/usr/local/sbin
    11	/usr/sbin]
    12	/opt/dell/srvadmin/bin

which bash     (the Bourne Again shell)
/usr/bin/bash

Make a bin subdirectory of your home directory

cd
pwd

mkdir bin
ls -ld bin
ls -l bin

c++ -o ~/bin/myprog myprog.C

Create a Bourne Again shellscript, and make it executable

cd ~/bin
pwd

vi compile

Here is the shellscript named compile that you will put into the bin subdirectory of your home directory. The first two characters on the first line must be #!.
$# is the number of command line arguments received by the shellscript.
$0 is the name of the shellscript.
$1 is the first command line argument received by the shellscript.

#!/usr/bin/bash
#The command line argument is the name of a C++ program, without the final .C
#Compile the program, and put the executable file in the user's ~/bin directory.
#Sample usage: compile myprog

if [[ $# -ne 1 ]]
then
	echo $0: requires 1 command line argument 1>&2
	exit 1
fi

c++ -o ~/bin/$1 $1.C && ls -l ~/bin/$1
ls -l compile
-rw-r--r-- 1 jsmith students 329 May 29 10:20 compile

chmod 755 compile        (Change mode: 755 means 111 101 101)

ls -l compile
-rwxr-xr-x 1 jsmith students 329 May 29 10:20 compile

compile myprog
-rwxr-xr-x 1 jsmith students 13024 May 29 12:29 /home/students/jsmith/bin/myprog

myprog      (Executes the myprog that's in your bin directory.)