UCONN

UCONN
UCONN

Linux explained

Linux


When we talk about Linux we first must understand its origins and the UNIX operating system.  Unix was born in 1969.


AT&T's Bell Laboratories in the early 1970s.


The Unix operating system was conceived and implemented by Ken Thompson and Dennis Ritchie (both of AT&T Bell Laboratories) in 1969 and first released in 1970. 

Programming language, C, to make it portable. 

 In 1977, the Berkeley Software Distribution (BSD) was developed by the Computer Systems Research Group (CSRG) from UC Berkeley, based on the 6th edition of Unix from AT&T. 

The 1960's "saw" people organizing groups and actively working for change in the social order along with the government

UNIX system code all began developing their own different versions.

Universities, research institutes, government bodies and computer companies are using the UNIX system to develop many of the technologies.

Vendors concerned about encroachment into their markets and control of system interfaces, developed the concept of "open systems."

In 1987, AT&T announced a pact with Sun Microsystems(Berkeley UNIX). 

Industry clubbed together to develop their own "new" open systems operating system, the Open Software Foundation (OSF). 


What is an Operating System?


An operating system (OS) is system software that manages computer hardware, software resources, and provides common services for computer programs.

Time-sharing operating systems schedule tasks for efficient use of the system and may also include accounting software for cost allocation of processor time, mass storage, printing, and other resources.

Linux began in 1991 as a personal project by Finnish student Linus Torvalds: to create a new free operating system kernel. 

In 1983, Richard Stallman started the GNU project with the goal of creating a free UNIX-like operating system.


GNU



GNU's not Unix

As part of this work, he wrote the GNU General Public License (GPL). 

The GNU General Public License is a free, copyleft license for software and other kinds of works.

GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. 

In 1985, Intel released the 80386, the first x86 microprocessor with a 32-bit instruction set and a memory management unit with paging.

The Operating System boots or brings up a kernel.

Linux is an operating system that allows users to control computers.

Kernel - Kernel manages hardware resources and acts as a bridge between other software components.


The kernel is the interface between hardware and software.
The user transmits commands to the kernel through the shell.

The Linux kernel is the core (hence the name "kernel") of the Linux operating system.

It’s the bridge between your computer’s hardware (CPU, memory, storage, devices) and software (apps, commands, services).

Open source - Denoting software for which the original source code is made freely available and may be redistributed and modified.

Distribution

A Linux distribution is a combination of software that comes with the Linux kernel and allows users to manage the operating system.

  • Ubuntu

  • RedHat

  • Debian


Shell

A shell is a program in which the user instructs the operating system by entering commands.

File

A file is the unit in a computer system where data is stored. 

Directory (Folder)

A directory is the unit in which files and subdirectories are organized. A directory can contain other files and subdirectories.



Tree Structure

Files and directories form a tree structure in computer systems.
At the top level, there is a root directory. 

Path

Addressing system used to specify the location of files or directories. The file path specifies the exact location of the file or directory.


 

Free - (for the most part)

When you login to a Linux system 

Access the Cloud Shell

 

 

In the upper right hand corner of the screen Click on >- symbol to activate the cloud shell.

 

Welcome to Cloud Shell! Type "help" to get started.

Your Cloud Platform project in this session is set to uconn-engr.

Use “gcloud config set project [PROJECT_ID]” to change to a different project.

john_iacovacci1@cloudshell:~ (uconn-engr)$ 

The prompt $ waits for you to type commands and also lists the random id given to your project unless when creating your project you give it a unique id.

  

Ctrl +c will always get prompt back

   

All Linux/Unix systems have a superuser account called "root".

 

This account can change passwords, delete files and do everything on the system.

Full permissions.

 

Linux is case sensitive and does not use spaces in file names.


A file system is necessary to store files on a computer.


The Linux file system starts with the root directory (like a tree)


and branches into subdirectories from the root.


Each sub-directory can have move subdirectories underneath so it is like an upside

down tree.


E.g.

To create a directory you use the mkdir command

john_iacovacci1@cloudshell:~ (sentiment-analysis-379200)$ mkdir assignment1

john_iacovacci1@cloudshell:~ (uconn-engr)$ mkdir assignment1



The cd command allows you to move into that directory


john_iacovacci1@cloudshell:~ (uconn-engr)$ cd assignment1

john_iacovacci1@cloudshell:~/assignment1 (uconn-engr)$ 


Linux File System Directories.

/bin: Where Linux core commands reside like ls, mv.

/boot: Where boot loader and boot files are located.

/dev: Where all physical drives are mounted like USBs DVDs.

/etc: Contains configurations for the installed packages.

/home: Where every user will have a personal folder to put his folders with his name like /home/john_iacovacci1 (taken from my gmail login)

/lib: Where the libraries of the installed packages located since libraries shared among all packages

/root: The home folder for the root user.

/sbin: Like /bin, but binaries here are for root user only.

/tmp: Contains the temporary files.

/usr: Where the utilities and files shared between users on Linux.

/var: Contains system logs and other variable data.

The cron command-line utility is a job scheduler on Unix-like operating systems. Users who set up and maintain software environments use cron to schedule jobs, also known as cron jobs, to run periodically at fixed times, dates, or intervals.


How it Flows


Applications make requests via system calls (e.g., read(), write()).


System libraries provide convenient programming interfaces.


The System Call Interface hands requests to the kernel.


The kernel manages:


CPU time (process scheduler)


Memory allocation


File operations


Device communication


Network transfers


The kernel uses device drivers to talk directly to hardware.



The navigation commands

cd - is change directory

 

you can change directory to an absolute path e.g.

john_iacovacci1@cloudshell:~/assignment1 (uconn-engr)$ cd /home/john_iacovacci1/assignment1

Absolute path always begins with /

 cd ..

Brings you up one directory

john_iacovacci1@cloudshell:~/assignment1 (uconn-engr)$ cd ..

john_iacovacci1@cloudshell:~ (uconn-engr)$ 

Relative path allows you to change to a directory relative to where you currently are set to.

You can move into a directory using the cd command

john_iacovacci1@cloudshell:~ (uconn-engr)$ cd assignment1

john_iacovacci1@cloudshell:~/assignment1 (uconn-engr)$ 

Note: cd $HOME

Will take you to your home directory.

john_iacovacci1@cloudshell:~/assignment1 (uconn-engr)$ cd $HOME

john_iacovacci1@cloudshell:~ (uconn-engr)$ 

 

pwd - stands for print working directory - tells you where you are

john_iacovacci1@cloudshell:~ (uconn-engr)$ pwd

/home/john_iacovacci1

The touch command allows you to create a file

john_iacovacci1@cloudshell:~ (uconn-engr)$ cd assignment1

john_iacovacci1@cloudshell:~/assignment1 (uconn-engr)$ 

john_iacovacci1@cloudshell:~/assignment1 (uconn-engr)$ touch file1

ls - lists all files and directories within the working directory (or path you provided)

john_iacovacci1@cloudshell:~/assignment1 (uconn-engr)$ ls

file1

Adding the -lt option for (for ownership and time stamp)

john_iacovacci1@cloudshell:~/assignment1 (uconn-engr)$ ls -lt

total 0

-rw-rw-r-- 1 john_iacovacci1 john_iacovacci1 0 Aug 14 01:05 file1

Linux files have 3 sets of permission attributes

read(r), write(w) and execute(x) for owner, group and everyone

 

See how the file is permissioned.

 

chmod command can change the permissions of a file or directory

john_iacovacci1@cloudshell:~/assignment1 (uconn-engr)$ chmod +x file1

john_iacovacci1@cloudshell:~/assignment1 (uconn-engr)$ ls -lt

total 0

-rwxrwxr-x 1 john_iacovacci1 john_iacovacci1 0 Aug 14 01:05 file1

john_iacovacci1@cloudshell:~/assignment1 (uconn-engr)$ 

To copy a file use the cp command

john_iacovacci1@cloudshell:~/assignment1 (uconn-engr)$ cp file1 file2

Use ls command to see the files

john_iacovacci1@cloudshell:~/assignment1 (uconn-engr)$ ls -lt

total 0

-rwxrwxr-x 1 john_iacovacci1 john_iacovacci1 0 Aug 14 01:25 file2

-rwxrwxr-x 1 john_iacovacci1 john_iacovacci1 0 Aug 14 01:05 file1

john_iacovacci1@cloudshell:~/assignment1 (uconn-engr)$ 

echo is a command to repeat what you type

john_iacovacci1@cloudshell:~/assignment1 (uconn-engr)$ echo "Hello World"

Hello World

By default the output of commands go to the standard output or display screen

Redirection is a feature in Linux such that when executing a command, you can change the standard input/output devices.

 

Redirection allows you to redirect output to a file

 

The > symbol allows you to redirect output to a file

john_iacovacci1@cloudshell:~/assignment1 (uconn-engr)$ echo "Hello World" > file3

john_iacovacci1@cloudshell:~/assignment1 (uconn-engr)$ ls -lt

total 4

-rw-rw-r-- 1 john_iacovacci1 john_iacovacci1 12 Aug 14 01:30 file3

-rwxrwxr-x 1 john_iacovacci1 john_iacovacci1  0 Aug 14 01:25 file2

-rwxrwxr-x 1 john_iacovacci1 john_iacovacci1  0 Aug 14 01:05 file1

john_iacovacci1@cloudshell:~/assignment1 (uconn-engr)$ 

cat is a command that display contents to a file

john_iacovacci1@cloudshell:~/assignment1 (uconn-engr)$ cat file3

Hello World

A wildcard allows you to use any command to pattern match to a file.

 

? - one character

* - all characters 

[] - range of characters

 

ls -lt file?

ls -lt f*

 

 

john_iacovacci1@cloudshell:~/assignment1 (uconn-engr)$ ls -lt file?

-rw-rw-r-- 1 john_iacovacci1 john_iacovacci1 12 Aug 14 01:30 file3

-rwxrwxr-x 1 john_iacovacci1 john_iacovacci1  0 Aug 14 01:25 file2

-rwxrwxr-x 1 john_iacovacci1 john_iacovacci1  0 Aug 14 01:05 file1

john_iacovacci1@cloudshell:~/assignment1 (uconn-engr)$ ls -lt f*

-rw-rw-r-- 1 john_iacovacci1 john_iacovacci1 12 Aug 14 01:30 file3

-rwxrwxr-x 1 john_iacovacci1 john_iacovacci1  0 Aug 14 01:25 file2

-rwxrwxr-x 1 john_iacovacci1 john_iacovacci1  0 Aug 14 01:05 file1

john_iacovacci1@cloudshell:~/assignment1 (uconn-engr)$ 

other file commands are

 

rm - remove a file

mv - move a file

mkdir - make directory

rmdir - remove directory

pwd — print working directory,

know which directory you are in, absolute path e.g. "/home/username".

ls — Use the "ls" files are in the directory you are in. ls -lt 

touch — command is used to create a file.

cp — copy files through the command line.

locate — locate a file in a Linux system,

echo — repeats what you type.

cat — display contents of a file.

sudo — super user do allows you to act as root use.

df — see the available disk space 

du — know the disk usage of a file in your system.

tar — work with compressed files,

zip, unzip — compress files into a zip and unzip files

chmod — change the permissions granted to it in Linux.

hostname — know your name in your host or network.

“hostname -I” gives you your IP address in your network.

ping — Use ping to check your connection to a server. 

clear - clear the terminal,

grep  - command-line utility for searching plaintext.

find - allowed you to find a command on your system 

TAB can be used to fill up the terminal command..


Ctrl+C can be used to stop any comma

The UP Arrow calls up the last linux command so the user can execute it again by hitting return.

exit terminal by using the exit command.

 Shell Script


A shell script is a computer program designed to be run by a Unix shell, a command-line interpreter. 

Use the google editor to create a file

Highlight the directory you want to create the file in

Then right click on the directory to create a new file

Click on New file and enter hw.sh

First line provides path to the shell

Use echo command to display “Hello UCONN World”

#!/bin/bash

echo "Hello UCONN World"

Go back to Open Terminal

Make the file executable

john_iacovacci1@cloudshell:~/assignment1 (uconn-engr)$ chmod +x hw.sh

Then execute using ./ to specify where the file to be executed is

john_iacovacci1@cloudshell:~/assignment1 (uconn-engr)$ ./hw.sh

Hello UCONN World

Now lets talk about variables.

A variable allows programs to store values and assign those values to a name.

We can use the shell read command to read the input from the terminal and assign the value inputted to a variable. Then we can use the echo command to display the value of that variable.

====================================================

### **Basic Arithmetic Operators**

# Addition

 

`echo $((5 + 3))   # 8`


|

| `-`      | Subtraction         | `echo $((10 - 4))  # 6`  |

| `*`      | Multiplication      | `echo $((7 * 6))   # 42` |

| `/`      | Division (integer)  | `echo $((20 / 3))  # 6`  |

| `%`      | Modulus (remainder) | `echo $((20 % 3))  # 2`  |

| `**`     | Exponentiation      | `echo $((2 ** 3))   # 8` |




### **Assignment Operators**


| Operator | Meaning             | Example                         |

| -------- | ------------------- | ------------------------------- |

| `=`      | Assign value        | `x=10`                          |

| `+=`     | Add and assign      | `x=5; ((x+=3)); echo $x   # 8`  |

| `-=`     | Subtract and assign | `x=10; ((x-=4)); echo $x  # 6`  |

| `*=`     | Multiply and assign | `x=4; ((x*=2)); echo $x   # 8`  |

| `/=`     | Divide and assign   | `x=20; ((x/=5)); echo $x   # 4` |

| `%=`     | Modulus and assign  | `x=7; ((x%=3)); echo $x   # 1`  |


---


### **Increment and Decrement Operators**


| Operator | Meaning   | Example                       |

| -------- | --------- | ----------------------------- |

| `++`     | Increment | `x=5; ((x++)); echo $x   # 6` |

| `--`     | Decrement | `x=5; ((x--)); echo $x   # 4` |


---

================================================

#!/bin/bash

# Simple addition script


num1=10

num2=5


# Perform addition

sum=$((num1 + num2))


# Display result

echo "The sum of $num1 and $num2 is: $sum"


# Perform subtraction

result=$((num1 - num2))


# Display result

echo "The result of $num1 - $num2 = $result"


# Perform Multiplication

# Using let

let result=num1*num2

echo "Using let   : $num1 * $num2 = $result"

==================================================

john_iacovacci1@cloudshell:~/assign1 (sentiment-analysis-379200)$ ./at.sh

The sum of 10 and 5 is: 15

The result of 10 - 5 = 5

Using let   : 10 * 5 = 50

john_iacovacci1@cloudshell:~/assign1 (sentiment-analysis-379200)$ 




===========================================

#!/bin/bash


# Indexed array

fruits=("apple" "banana" "cherry")

echo "First fruit: ${fruits[0]}"


# Loop through array

for fruit in "${fruits[@]}"; do

  echo $fruit

done



====================================================

john_iacovacci1@cloudshell:~/assign1 (sentiment-analysis-379200)$ ./dt.sh

Hello, World

Sum is 30

First fruit: apple

apple

banana

cherry


john_iacovacci1@cloudshell:~/assign1 (sentiment-analysis-379200)$ 


Validation


================================================

#!/bin/bash


echo "Enter your Age : "


read AGE

# Validate age: must be an integer between 1 and 120

if [[ ! "$AGE" =~ ^[0-9]+$ ]]; then

    echo "Error: Age must be a number."

    exit 1

elif (( AGE < 1 || AGE > 120 )); then

    echo "Error: Age must be between 1 and 120."

    exit 1

fi


echo "Age: $AGE"

====================================================

john_iacovacci1@cloudshell:~/assign1 (sentiment-analysis-379200)$ ./vd.sh

Enter your Age : 

65

Age: 65

john_iacovacci1@cloudshell:~/assign1 (sentiment-analysis-379200)$ 


john_iacovacci1@cloudshell:~/assign1 (sentiment-analysis-379200)$ ./vd.sh

Enter your Age : 

200

Error: Age must be between 1 and 120.

john_iacovacci1@cloudshell:~/assign1 (sentiment-analysis-379200)$ 



name.sh

#!/bin/bash

echo "Enter your full name : "

read my_name

echo "My Name is : " $my_name

john_iacovacci1@cloudshell:~/assignment1 (uconn-engr)$ chmod +x name.sh

john_iacovacci1@cloudshell:~/assignment1 (uconn-engr)$ ./name.sh

Enter your full name : 

John Iacovacci

My Name is :  John Iacovacci

john_iacovacci1@cloudshell:~/assignment1 (uconn-engr)$ 

We can redirect the standard output to a file using the > sign.

Note: the > creates a new file and the >> sign appends data to file.

====================================================

#!/bin/bash

echo "Enter your full name : "

read my_name

echo "My Name is : " $my_name > my_info.txt

john_iacovacci1@cloudshell:~/assignment1 (uconn-engr)$ ./name.sh

Enter your full name : 

John Iacovacci

john_iacovacci1@cloudshell:~/assignment1 (uconn-engr)$ cat my_info.txt

My Name is :  John Iacovacci

john_iacovacci1@cloudshell:~/assignment1 (uconn-engr)$ 

Assignment one - create a directory under your home directory called scripts and create a file called my_profile.txt

 

1. pwd

 

should be home/user_name

 

2. mkdir scripts

 

3. cd scripts

 

4. pwd - /home/user_name/scripts

 

5. Use the terminal editor to access the graphical editor

 

6. Position cursor on the directory that you wish to create the file in

 

7. Right click the mouse and select New File 

 

8. Name the file profile.sh

 

9. Enter the commands into the file

=================================================

#!/bin/bash

# My First scripts

echo "Enter your full name : "

read my_name

echo "Enter your major : "

read my_major

gradyear=2025

cyear=1



while true; do

    echo -n "Enter your class standing (Freshman, Sophomore, Junior, Senior): "

    read standing


    case "$standing" in

        [Ff]reshman)

            echo "✅ You entered: Freshman"

            cyear=4

            break

            ;;

        [Ss]ophomore)

            echo "✅ You entered: Sophomore"

            cyear=3

            break

            ;;

        [Jj]unior)

            echo "✅ You entered: Junior"

            cyear=2

            break

            ;;

        [Ss]enior)

            echo "✅ You entered: Senior"

            cyear=1

            break

            ;;

        *)

            echo "❌ Invalid entry. Please try again."

            ;;

    esac

done

# Perform addition

sum=$((gradyear + cyear))


# Display result

echo "My Name is : " $my_name
echo "My major is : " $my_major

echo "My grade is : " $standing

echo "Your Graduation year is $sum"


echo "My Name is : " $my_name > my_profile.txt

echo "My major is : " $my_major >> my_profile.txt

echo "My grade is : " $standing >> my_profile.txt

echo "I will graduate in the year : " $sum >> my_profile.txt


=================================================================


10. Go back to the Cloud Shell Terminal

12. Change the properties of the file so it can be executable

john_iacovacci1@cloudshell:~/assignment1 (uconn-engr)$ chmod +x profile.sh

john_iacovacci1@cloudshell:~/assignment1 (uconn-engr)$ ./pro.sh

john_iacovacci1@cloudshell:~/assign1 (sentiment-analysis-379200)$ ./pro.sh

Enter your full name : 

John Iacovacci

Enter your major : 

Computer Science

Enter your class standing (Freshman, Sophomore, Junior, Senior): Freshman

✅ You entered: Freshman

Your Graduation year is 2029

john_iacovacci1@cloudshell:~/assign1 (sentiment-analysis-379200)$ ./pro.sh

Enter your full name : 

John Iacovacci

Enter your major : 

Computer Science

Enter your class standing (Freshman, Sophomore, Junior, Senior): Freshman

✅ You entered: Freshman

Your Graduation year is 2029

john_iacovacci1@cloudshell:~/assign1 (sentiment-analysis-379200)$ ls -lt

total 72

-rw-rw-r-- 1 john_iacovacci1 john_iacovacci1  121 Aug 24 20:28 my_profile.txt


john_iacovacci1@cloudshell:~/assign1 (sentiment-analysis-379200)$ export PATH=$PATH:/home/john_iacovacci1/assign1

john_iacovacci1@cloudshell:~/assign1 (sentiment-analysis-379200)$ ls

assignment1  dv.sh  file1  file2  hw.sh  my_info.txt  my_profile.txt  name.sh  profile.sh

john_iacovacci1@cloudshell:~/assign1 (sentiment-analysis-379200)$ john_iacovacci1@cloudshell:~/assignment1 (uconn-engr)$ cat my_profile.txt

john_iacovacci1@cloudshell:~/assign1 (sentiment-analysis-379200)$ cat my_profile.txt

My Name is :  John Iacovacci

My major is :  Computer Science

My grade is :  Freshman

I will graduate in the year :  2029

john_iacovacci1@cloudshell:~/assign1 (sentiment-analysis-379200)$ 


john_iacovacci1@cloudshell:~/assignment1 (uconn-engr)$ 

Download the file to a local directory

Click the 3 dots located near the Open Editor button

Click Download

Click folder to locate directory where file is located

Click arrow to expand directories

Click arrow next to directory where file is located

Select file

Click Download

File will appear in your local downloads directory

Copy code and attach file

Use paper clip to attach file


No comments:

Post a Comment

Assignment #2 due Wednesday 9/24/25

  Assignment #2 due Wednesday 9/24/25 Create a web site with  main page of index.html and 2 other linked original content  html pages  At le...