CS-332 Gerbessiotis, Alex      August 21, 2026  
------------------------------------------------

    L I N U X   summary
    ===================

Note: If you see a reference to a Readme1st.txt
      or just Readme1st it is this file
      named Readmej0.txt and the 0 is a reference
      to Subject 0.

1. Introduction
--------------------------

   If you are not familiar with linux, go to 
the Course web page and navigate to section B3
"Other Reference Material".
 
   The first two links there contain a tutorial 
to Linux.  The third link points to the
YWCC@NJIT Computing Requirement document.

   The last two links are to documents  prepared 
by the instructor. One discusses connectivity to
a Unix/Linux machine at NJIT. The other is a
compact Unix and Linux tutorial.


2. What is a shell ?
--------------------------

Although Linux is a distinct flavor of the Unix 
operating system, several times we would be 
using the terms Unix and Linux interachangeably.
Beware of this.

The Linux kernel is the part of the Linux 
Operating System (OS) that runs all the time 
and maintains the data structures required for 
the proper operation of the OS. 
One can thus distinguish between the Linux 
kernel and the Linux OS.  The Android OS 
uses the Linux kernel as a kernel!

There are additional services other than 
the Linux kernel provided by the Linux OS. 
These include program execution, 
program compilation tools or toolchains, 
file management, etc.

A shell wraps around the linux kernel and 
provides an interface to users of (some) of 
the facilities of the Linux kernel and/or
the Linux OS. 
There are multiple shells available
in the Linux OS but by default the shell that 
we will be using would be the bash shell.

The bash shell runs when a user logs on a 
Linux OS system through the command line. 
For example a user logs into a computer hosting
the Linux OS by using a secure shell client
(ssh).  Such a client can be MobaXterm, a
Windows-based graphical version of ssh, or 
the Windows provided terminal-based ssh
command line, or a Mac OSX provided  Terminal 
or a similarly   Linux provided one.

In all three latter cases, you create a window
using terminal (in Linux), Terminal (in OSX),
or a Command Prompt or a PowerShell terminal
(in Windows) and then in it you connect by
typing commands in the command line.

For example if you type all the characters
below except  after the  percent % prompt 
in the appropriate OS window next to 
the blinking cursor and then press the
ENTER button,

% ssh -l abcd1234@afslogin0.njit.edu

a connection will be established between
your computer with the remote Linux machine 
whose host name is afslogin0.njit.edu. 
To do so you need to have active and
valid credentials to authenticate such 
a connection. So if you cannot provide
credentials for user abcd1234 including
a password you won't be able to establish
a connection . In that case you replace the
indicated login name with your myUCID 
NJIT login name and its password that you
and only you are familiar with. 
There will be two authentication steps.
 (a) The first one may prompt for your myUCID
login name (login:) or not but will definitely
prompt for your myUCID login name's password.
Type carefully do not used backspage or Del as
they will not work, and do not forget to press
the ENTER button.
 (b) The second authentication steps is an
additional 2FA step. 
If both are valid, you will be allowed
to connect to the remote machine from your
local machine. The remote machine, in fact
its operating system, will be
running for you a bash shell accepting
information from you and displaying information
onto the window used for establishing this
communication.

The bash shell prompts the user to 
provide input to it (bash shell).
The shell indicates so by providing a command 
prompt (a character or sequence of characters) 
that indicates that the shell is attentive to 
the user and next to the prompt where user input 
will be typed a cursor might appear in the 
form of a (bright) rectangle or a vertical bar. 

The command prompt is user modifiable: 
the command prompt that I have selected to have 
in the example earlier is the 
percent sign %. It is very likely that this is
NOT your default command prompt.

A user types in next to (on the right of) the 
command prompt a command, its options, if any, 
and the arguments of the command. 

Options are usually English alphabet letters 
preceded by a dash (-) and arguments follow the 
options and they are white space separated. 
White space is defined to be one or more space
characters or one or more TAB characters or 
similar other characters.
All those parts form the command line.

********************************************
When the command is formed the user presses 
the ENTER key to tell the shell that the 
user is done typing and that the user is
requesting the 'execution' of the user 
typed command. The shell will read and
understand the command line (i.e. interpret
it) and then attempt to execute it, utilizing
the services of the OS. A successful 
execution is noted appropriately by the
bash shell; an unsuccessful one generates
an error that is to displayed appropriately.
********************************************

A command whose execution is requested by
the user will only be executed if it is
correct and the user has the appropriate
security authorizations (credentials, privileges,
rights) to execute it.


3. An example
--------------------------

 An example of a command is given below


  % ls -lS file1 file2

    ^  ^   ^     ^
    |  |   |     |
    |  |   |- two argument to ls
    |  |      (file1 and file2)
    |  |
    |  |- option indicator is -
    |     (options typed are l and S)
    |- Command  is ls short for list

In this example % or % followed by a space is 
the command prompt and are provided/displayed 
by the bash shell, not type by the user.
The user starts the typing with the ell of ls
and ends the typing with the 2 of file2 followed
by the pressing of the ENTER key.

When the user verifies visually that all is 
syntactically correct, then and only then 
does the user presses (rather than types) 
the ENTER button immediately after completing
the typing of file2.

The command typed is ls short for list. 
It lists the contents of the file arguments 
of ls.
There are two file arguments and these are
file1 and file2. Note the space or spaces
between ls, -lS, file1, and file2. 
The number of white space is irrelevant. 
It is not clear whether
there is or are spaces after file2 or other
non visible characters such as the Tab in 
between the four parts of the command. 
Another invisible character is the one
generated by the Enter button (a newline
as it is known).

The character - indicates the presence of
letter options following it for command ls:
these options are l and S in this example.
Option l means a long listing of information
is requested  and ls interprets this by
printing one full line of information about each
one of its (file) arguments.
Option S is a request that the file arguments are
sorted/ordered by file size.

The two arguments of command ls are file1 and
file2. If the files with aliases (some call
them filenames) file1 and file2 do not exist
an error message will be reported when the 
command is processed by the shell.
The files are expected to be available in the
current directory in which the user is located.
By default when a user logins on a Unix/Linux
system the default location of the filesystem
in which the user is located is the user's
home directory. On an NJIT linux machine that
supported the AFS (Andrew File system) the
home directory is described by the path 
(also, path name)
 /afs/cad/u/a/b/abcd1234
            ^ ^ ^
            | | |___  myUCID
            | |_______2nd letter of myUCID
            |_________1st letter of myUCID

One reads it as follows
/          : is the root (top, not bottom) 
             of the file system
/afs       : the root has a directory in it
             named afs; sometimes we say afs
             is a subdirectory of the root /
/afs/cad   : directory afs has a directory in it
             (a.k.a. subdirectory named cad)
and so on cad has directory u, that has 
directory a, that has directory b and in it
a directory named after your myUCID can be
located.

One could move to this location (the example
home directory) manually as follows

  Method 1: the complicated way (multi step)
  -----------------------------
% cd /
% cd afs
% cs cad
% cd u
% cd a 
% cd b
% cd abcd1234

    and if one types
% pwd
    the output would be 
/afs/cad/u/a/b/abcd1234

cd  stands for "change directory"
pwd stands for "print  working directory"
    (also known as the current directory)


  Method 2: the easy way 
  ------------------------
% cd /afs/cad/u/a/b/abcd1234

  Method 3: the easier way 
  ------------------------
% cd ~

  Method 4: the easiest way 
  ------------------------

% cd


Using Method 1 you traverse the path from
the root to the home directory abcd1234
one directory at a time starting from the root
Using Method 2 you do it in one command.
Using Method 3 you use an alias for your home
directory, the tilde.
Using Method 4 you use the default action of
a no argument cd.

Confirm the alias of ~ by typing
% echo ~
  with the output displayed becoming
/afs/cad/u/a/b/abcd1234
  if your myUCID is abcd1234

If you want to backtrack the path you
traversed in Method 1 do a
 % cd ..
 % cd ..
 % cd ..
 % cd ..
 % cd ..
 % cd ..

 .. is an alias for the parent of
 current directory.
So the parent of /afs/cad/u/a/b/abcd1234
is /afs/cad/u/a/b
   The parent of /afs/cad/u/a/b
is /afs/cad/u/a
   The parent of /afs/cad/u/a/
is /afs/cad/u
   The parent of /afs/cad/u/
is /afs/cad
   The parent of /afs/cad/
is /afs
   The parent of /afs
is /

   The parent of the root is the root so
additional 
 % cd ..
won't generate anything new.


The simplest form of ls is
 %  ls

In this case ls PRINTS short information about
all the files that reside in the CURRENT DIRECTORY.
The current (or working) directory is the directory 
associated with the location of the execution 
of command ls.  When we login to Linux or Unix our 
default location for current directory
is our home directory.

If one types
 % ls .

the output would be the same. 
In linux a period is an alias for the
CURRENT (working) DIRECTORY. 
Thus ls and ls .  do the same thing, they list 
the contents (files of any type) of the 
current directory.
An

 % ls ..

lists the contents of the parent directory
to the current directory. And

 % ls ../..

prints the contents  of the parent of the
parent to the current directory. There is a
hierarchical structure in the file system
in the form of a tree


 Finally, an

 % ls ~

prints the contents(files) of the HOME directory.

  .  : alias for CURRENT WORKING directory
 ..  : alias for parent of CURRENT WORKING directory
  ~  : alias for HOME DIRECTORY

If you do not know where you are, type

 % pwd

 % cd
i.e.
 % cd ~
changes directory (cd): in both cases we move to
the user's home directory.

Other variations
  % ls
  % ls .
  % ls -l
  % ls -a
  % ls ~


Note that if i type
  % ls  # hi ho hello
the system would ignore any character typed
beyond the sharp symbol (also known as the hash
symbol) #, because # is the comment symbol for
bash and works the same way a // works in C++
or Java. Thus the previous command is
equivalent to
  % ls


Explore now
  % ls -al
  % ls -alrt
      a: hidden files
      l: long listing for ls
      r: reverse order
      t: order based on time
  % ls -i
      i: shows how the OS (and its filesystem)
         identify a given file

5. Other examples
--------------------------
 A useful command
 %  man
 %  man man

 man stands for manual and its job is obvious
 %  man cd
 %  man ls
 %  man pwd

 A simple command is

  %  date

Type it in and press Enter when you are done with
typing. Explore also

  % hostname             
    may be afslogin0.njit.edu

  %  who

  %  w
     w stands for what is going on (in the system)?

  % ps
    ps stands for process status (in current Terminal)

  % top
    and you exit by pressing the q button (q for quit)





6. Executing a command
--------------------------------------------------------

  % date

In the previous section I asked you to type a command.
The name of the command was date.

This means following the command prompt of the 
bash shell (in the examples above my command prompt 
is the percenet % sign) you type date and after you 
complete the typing you press the Enter button. 

If you do not press the Enter button of the
keyboard nothing will happen.

The shell accepts your command along with its
options and arguments, interprets it and if no
errors are found it runs a program named after
the command (program date)
by feeding to it   the options
and argument information as provided and needed. 

In OS terminology a program in execution is 
called a process. Nowadays linux prefers 
the more general term task that includes 
a process but also a  thread which is 
a lightweight process.

Before you press the Enter button, date is a
program on a disk drive (hard disk drive for NJIT
host machines).  It is an executable program.
You may locate its  (file system) location by
typing
  % which date

The moment you press Enter and bash interprets
the command and confirms no errors or no problems
the program  on the disk (in secondary memory)
moves to main memory (a.k.a. RAM or primary memory)
and becomes a PROCESS. A process is a program in 
execution. The OS through the bash shell's
request to run date on your behalf wil execute
the program (process) date for the bash shell and
when execution completes (successfully) you will
realized this either from the output generated or
from the new command prompt line displayed by the
bash shell and next to it you will see
the ubiquitous blinking cursor.


7. Unix connectivity
------------------------------

If you plan to use NJIT resources
connect to one of afslogin0.njit.edu or
afslogin1.njit.edu

For specific classes such as ours, alternatives
host names such as 
 osl1.resource.campus.njit.edu
might be used. And the 1 of osl1 can be replaced
by other digits or numbers in the range 1-32.
Some of them might be working, some of them not,
at any given moment.

This assumes you are alread inside NJIT. If you
are outside of NJIT, download install and activate
the CISCO VPN client and connect to NJIT.

More information is provided in section B3 of
the course Web-page link 
"Connecting to Unix/Linux at NJIT".

From the command line of
the Microsoft Windows command prompt or 
Powershell terminal,
or the window of a Linux terminal,
or the window of a Mac OSX terminal, 
or the window of a MobaXterm terminal you
type

    ssh  UCID@afslogin0.njit.edu

where UCID is your specific NJIT UCID.
Note that your myUCID credentials consist of 
a login name (also known as UCID) and your
corresponding UCID password (or just password).

If for example your UCID is abcd1234 then you would type

    ssh  abcd1234@afslogin0.njit.edu

as also previously indicated.
Note that 
  (a) first you will be prompted to type your
      UCID password,
  
then
  (b) you  might be prompted for DUO 2FA 
      (two factor authentication),
and then 
  (c) an additional window might pop up requesting your
      UCID password again,
and
  (d) an additional window might pop up requesting a 
      DUO 2FA again.

The last two are if you want to be able to transfer files
to/from the Linux remote machine from/to you local machine
(Windows, or Apple, or even Linux).

8. More commands
------------------

  % touch x
    creates in the current directory a file named
    x (i.e. with an alias x) of 0 byte size

  % touch y
  % echo "abcd" >>y
    creates a zero byte size file y and then
    stores in it 4 visible characters a,b,c,d
    and one invisible  character the notorious newline

  Confirm this with
  % ls -l y
    you see a file of size 5B (five byte)

  % od -c y
    you see five character listed and these are
     a, b, c, d, and \n
    \n is one character the newline character

  % cp y z
    copy y to z
  % mv y w
    rename y as w or more appropriately move y to w.

  % mkdir adir
    create a new directory in the current directory
    named adir

  % pwd
  % ls
    confirm its creation; confirm x, z, w are also
    present
  % mv x adir
    mv x inside adir
  % ls adir
    to confirm x is there
    or
  % cd adir
  % ls
    and then
  % cd ..
  % pwd
  % rm -r  adir   # THIS IS THE 2nd most DANGEROUS COMMAND
  % rm -rf adir   # THIS IS THE     MOST DANGEROUS COMMAND
    the latter won't work if the formed worked
    -r : means recursively delete everything inside adir
         (thankfully: adir has only one empty file)
    -f : do not ask for confirmation
  If directory adir was empty of files of any type
  % rmdir adir
    would have worked deleting adir

  % cat  z
  % more z
  % less z

  if z was a very long file less would allow you to
  navigate in it through the following single character
  commands that can be typed

  f  : move forward one screen page
  spacebar:  same as f above
  b  : move backwards one screen page
  q  : quit

  % md5sum z
    crypto fingerprint of z is displayed
  % md5sum w
    w should have the same fingerprint as z!


The magic of
  % echo $$

    the PID (Process ID) of the bash shell running
    Confirm it with
  % ps
  % echo $?
    the return value of the previous command's execution
    0 : everything went fine

  % afsawhj
  % echo $?
  127
 
    command afsawhj does not exits; figure out what 127
    means

  % gcc x.c -o x
    compile C program x.c and generate 
    executable named x
  % gcc y.c 
    by default name of executable is a.out
  % ./x
    run x
    ./x  means
    in the current directory i.e. . find a file
    named x and run it (i.e. turn it into a process).


    WHAT is GOING on in the system

  % ps -ef 

  Phew too many lines...

  % ps -ef | egrep 857408
    
  The symbol | is for an UN-NAMED PIPE
  A PIPE | is a FIFO queue

  Input to  |  is the output of ps -ef
  Output of |  is the input  to egrep
  That is   | allows the communication of two processes
  Process  A is  "ps -ef"
  Process  B is  "egrep 857408"

  The output below
% ps -ef |egrep 857408 
abcd1234  857408  857394  0 18:11 pts/3    00:00:00 bash
abcd1234  863743  857408  0 18:19 pts/3    00:00:00 ps -ef
abcd1234  863744  857408  0 18:19 pts/3    00:00:00 grep -E --color=auto 857408

  also explains what egrep 857408 does:
  it filters our all lines THAT DO NOT CONTAIN 857408 i.e.
  it only displays lines   THAT DO     CONTAIN 857408 !

9. List of items to practice with
-----------------------------------

Even if you are familiar with Unix and Linux,
it does not hurt to go through this list to
confirm familiarity with the commands
and their options listed.


1. Connect with an ssh client to Linux machine

   Identify the bash shell (shell to the kernel).
   It is one of possible shells that interact with
   the kernel. 

2. Identify the prompt of the shell
   Though mine is % yours might be different!

3. Type date and observe its output
   This means do the following or observe the
   output generated

 % date
Tue Jul  1 05:56:11 PM EDT 2025

4. Type which date 
   and observe its output
5. Type man date 
   for a manual on the command date
6. Type man man 
   for the obvious!
7. Type w
8. Type ps
9. Type ps  -ef
    ps is the command  and
    e,f are its two options that will be used.
10. Type  ps  -ef | more
11. Type  ps  -ef | less
   more or less control the flow of the output of
   ps -ef. The pipe symbol | defines an UNNAMED
   PIPE in Unix. The output of ps -ef goes through
   the pipe and is sent to become the input of
   more or less. ps -ef maps to a Unix process;
   mor or less also maps to a Unix process. Thus
   the unnamed pipe allows the communication of 
   two Unix processes!

   One screen-full of ps -ef output  at a time 
   is displayed.  

   Control the flow with b (back) or SPACE (forward).
   Keyboard q allows you to quit i.e. stop the flow.

12. Type pwd
    pwd stands for print working directory

13. Type cd ~
    cs stands for change directory

14. Type pwd
15. Type cd ..
16. Type pwd
17. Type cd .. ; pwd
17. Type cd .. ; pwd
18. Type cd    ; pwd
19. Type cd /  
20. Type pwd
    By now you know you may type two 'commands' 
    in a line if you separate them with a 
    semicolon ;
21. Type  cd .  ; pwd
22. Type ls
     ls stands for list
23. Type ls -l
24. Type ls -al
25. Type ls -ial
     Option l is long listing
     Option a prints hidden files (usually . and ..)
     . is current directory
     .. is parent directory
     Option i prints the inode number (inode#) of 
     a file.  The inode# is the filename 
     (or namefile) of the file according to the 
     filesystem.

Example.
--------
  (in my file area)

% ls -ali example
315164982 -rw------- 1 alexg users 0 Dec 21 15:56 example

 315164982 : is the inode# ; the filesystem refers to 
             a file using this inode#.
             An inode# is an index into the inodeTable
             maintained on the disk where the file is
             stored. Index or offset 315164982 of the
             inodeTable contains metadata about the
             file in question.
 example  : is MY alias for 315164982 (we call it filename!)
 1        : The number of aliases to 315164982 is 1 
            indicated by the number one the left side of 
            alexg
  alexg   : the USER OWNER of the file (u)
  users   : the GROUP of the USER OWNER of the file (g)

26.  I have just created a second alias for the file.
     If one could type
% ls -lai example ex2
315164982 -rw------- 2 alexg users 0 Dec 21 15:56 ex2
315164982 -rw------- 2 alexg users 0 Dec 21 15:56 example

 Both ex2 and example are two aliases to the same 
 file 315164982 The number on the left of alexg is 2 now.

27. Type  man rm
    rm stands for remove (an alias) though some think
    that it stands for remove a file.
  % rm example
  % rm ex2
  if files example and ex2 exist for you, you may
  carefully delete them. If they do not exist an
  error will be reported by the bash shell.

28. DO NOT TYPE rm -rf  
    IT IS A DANGEROUS VERSION of rm !!!
    YOU HAVE BEEN WARNED

29. Type  touch afile
   creates a file afile (if it doesnot exist) of size 
   0 bytes.
  % touch example ex2
  will set you up to repeat step 27 without errors.

30. Type cp ex2 ex1
   cp  stands for copy ex2 into ex1. 
   (ex2 still exists.)

31. Type mv ex1 ex3
   ms stands for  mv (rename) ex1 into ex3.
   (ex1 disappears as it re-appears under 
   the alias ex3.)

32. Type gvim afile 
    to edit afile  with the gvim visual editor
    (Effective 2024 Fall this step might not work.)
33. Avoid using vi or vim instead of gvim.
    The first two use a disorienting non graphical
    interface that takes time to get used to.

34. Type md5sum afile
    It generates a cryptographic fingerprint of 
    file afile

35. Type mkdir aa
    mkdir stands for make directory
36. Type rmdir aa
    rmdir stands for remove (an empty) directory
    if not empty, empty it first and then rmdir
    or do a dangerous  rm -rf aa

37. Type tar  cvf  a.tar  a.txt b.txt
 or
    Type tar -cvf  a.tar  a.txt b.txt
    Archive into a tar (Tape ARchive) file the two files
    a.txt b.txt (if they both exist)
38. Type tar xvf a.tar
 or Type tar -xvf a.tar
    Unarchive i.e. obtain from a.tar all its
    constituent files (eg. a.txt b.txt)
39.  cvxf options of tar
     c : create
     v : verbose
     x : extract
     f : filename follows 

40. more , less, cat
  %  cat x     
    cat stands for catenate i.e. display contents
    of file (e.g. x) no flow control
    more, 
    less  are cat equivalent with flow control.

  % cat x y >>z
    z contains (the contents of) x followed by 
               (the contents of) y

41. Type  echo "mymy"
42. Type  echo $?
43. Type  echo $$
     Process ID of the 'current process running'
     is displayed: it is the Process ID of the bash
     shell. Yes the bash shell is a process just like
     those rm, ps, more, echo you have been running!
44. Type top
    to exit CTRL-Z
    CTRL-Z  means press the CTRL button and with the 
    button depressed press also the Z button of the 
    keyboard.
    The proper way to exit is a q (for quit)

    You see a 
 [1]+ Stopped    top
     
 Do a
 
   % jobs
 to confirm it is stopped

   % fg
 to unstop it i.e. bring it into the foreground
 fg : foreground

  METHOD 1 to KILL top (you are in top)
 -----------------------
   Type CTRL-Z and do jobs
 % jobs
[1]+  Stopped                 top

   you can kill it with

 % kill -9  %1
[1]+  Killed                  top

   OR

  METHOD 2 to KILL top (you are in top)
 -----------------------

   Type CTRL-C  in top


45. Type echo $path

46. Some fun with bash itself
  % echo $$
  % bash
  % echo $$
  % bash
  % echo $$

  We are running bash within bash!
  % exit 
  % echo $$
  % exit
  % echo $$
  You are back to the original bash

47. If you are done
  type an extra exit
  % exit
and you have terminated the bash shell that was
created by  ssh (secure shell).

48. You should be out of the system.
---------------------------------------------------------
