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 Operating System



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.

 

Hit Authorize


Welcome to Cloud Shell! Type "help" to get started, or type "gemini" to try prompting with Gemini CLI.

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

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

john_iacovacci1@cloudshell:~ (vertex-uconn)$ 

Your email address is and project name are part of the prompt

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.


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 default directory you are positioned under would be /home/email name

The pwd command (print working directory) will display your full path name on the disk location you are working on.

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

/home/john_iacovacci1

john_iacovacci1@cloudshell:~ (vertex-uconn)$ 





To create a directory you use the mkdir command

john_iacovacci1@cloudshell:~ (vertex-uconn)$ mkdir assign


The navigation commands


The cd command allows you to move into that directory


john_iacovacci1@cloudshell:~ (vertex-uconn)$ cd assign

john_iacovacci1@cloudshell:~/assign (vertex-uconn)$ 


Note: Each assignment should have its own directory


cd .. brings you up none level to previous directory


john_iacovacci1@cloudshell:~/assign (vertex-uconn)$ cd ..

john_iacovacci1@cloudshell:~ (vertex-uconn)$ 


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




cd $HOME will bring you to your default home directory


john_iacovacci1@cloudshell:~ (vertex-uconn)$ cd $HOME

john_iacovacci1@cloudshell:~ (vertex-uconn)$ 





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

john_iacovacci1@cloudshell:~ (vertex-uconn)$ cd /home/john_iacovacci1/assign

john_iacovacci1@cloudshell:~/assign (vertex-uconn)$ 


Absolute path always begins with /

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

Note: cd $HOME

Will take you to your home directory.

john_iacovacci1@cloudshell:~/assign (vertex-uconn)$ cd $HOME

john_iacovacci1@cloudshell:~ (vertex-uconn)$ 


The touch command allows you to create a file

john_iacovacci1@cloudshell:~ (vertex-uconn)$ cd assign

john_iacovacci1@cloudshell:~/assign (vertex-uconn)$ touch file1

john_iacovacci1@cloudshell:~/assign (vertex-uconn)$ 



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


john_iacovacci1@cloudshell:~/assign (vertex-uconn)$ ls

File1

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

john_iacovacci1@cloudshell:~/assign (vertex-uconn)$ ls -lt

total 0

-rw-rw-r-- 1 john_iacovacci1 john_iacovacci1 0 Jan 15 23:17 file1


john_iacovacci1@cloudshell:~/assign (vertex-uconn)$ 


The ls -lt command is a powerful combination used to list files in a directory while sorting them by time. It helps you quickly see which files were recently created or modified.

To understand it, let’s break down the command into its individual parts:

  • ls: The base command, short for "list." It displays the contents of a directory.

  • -l: The "long format" flag. Instead of just showing filenames, it provides detailed information like permissions, owner, file size, and the last modified date.

  • -t: The "time" flag. This tells Linux to sort the list by the modification time, placing the newest files at the top.


What the Output Looks Like

When you run ls -lt, the output is organized into columns. Here is a breakdown of what each column represents:

Column

Meaning

Example

Permissions

Who can read, write, or execute the file.

-rw-r--r--

Links

Number of hard links to the file.

1

Owner

The user who owns the file.

tony

Group

The group the file belongs to.

staff

Size

File size in bytes (by default).

4096

Timestamp

The last time the file was modified.

Jan 15 14:30

Name

The actual name of the file or folder.

report.pdf


Useful Variations

You can add more flags to ls -lt to make it even more helpful:

  • ls -lth: Adding the -h (human-readable) flag converts file sizes from bytes into KB, MB, or GB, making them much easier to read.

  • ls -ltr: Adding the -r (reverse) flag flips the order. This puts the newest files at the bottom of the list, which is very useful if you have a long list and want to see recent changes without scrolling up.

  • ls -lta: Adding the -a (all) flag ensures that "hidden" files (those starting with a dot, like .bashrc) are also included in the sorted list.


john_iacovacci1@cloudshell:~/assign (vertex-uconn)$ 


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:~/assign (vertex-uconn)$ chmod +x file1

john_iacovacci1@cloudshell:~/assign (vertex-uconn)$ ls -lt

total 0

-rwxrwxr-x 1 john_iacovacci1 john_iacovacci1 0 Jan 15 23:17 file1

john_iacovacci1@cloudshell:~/assign (vertex-uconn)$ 

The file mask has added execution permission which will allow us to create linux shell script later on. Also, files with execution permissions display on the screen in green.


To copy a file use the cp command

john_iacovacci1@cloudshell:~/assign (vertex-uconn)$ cp file1 file2

john_iacovacci1@cloudshell:~/assign (vertex-uconn)$ ls -lt

total 0

-rwxrwxr-x 1 john_iacovacci1 john_iacovacci1 0 Jan 15 23:46 file2

-rwxrwxr-x 1 john_iacovacci1 john_iacovacci1 0 Jan 15 23:17 file1

john_iacovacci1@cloudshell:~/assign (vertex-uconn)$ 

echo is a command to repeat what you type

john_iacovacci1@cloudshell:~/assign (vertex-uconn)$ 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.

john_iacovacci1@cloudshell:~/assign (cloud-project-examples)$ echo "Hello World" > file3

 

Redirection allows you to redirect output to a file

 

The > symbol allows you to redirect output to a file

john_iacovacci1@cloudshell:~/assign (vertex-uconn)$ ls -lt

total 4

-rw-rw-r-- 1 john_iacovacci1 john_iacovacci1 12 Jan 15 23:49 file3

-rwxrwxr-x 1 john_iacovacci1 john_iacovacci1  0 Jan 15 23:46 file2

-rwxrwxr-x 1 john_iacovacci1 john_iacovacci1  0 Jan 15 23:17 file1

cat is a command that display contents to a file

john_iacovacci1@cloudshell:~/assign (vertex-uconn)$ 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*

 First lets create a file called filtest

 john_iacovacci1@cloudshell:~/assign (vertex-uconn)$ touch filtest

john_iacovacci1@cloudshell:~/assign (vertex-uconn)$ ls -lt

total 4

-rw-rw-r-- 1 john_iacovacci1 john_iacovacci1  0 Jan 15 23:54 filtest

-rw-rw-r-- 1 john_iacovacci1 john_iacovacci1 12 Jan 15 23:49 file3

-rwxrwxr-x 1 john_iacovacci1 john_iacovacci1  0 Jan 15 23:46 file2

-rwxrwxr-x 1 john_iacovacci1 john_iacovacci1  0 Jan 15 23:17 file1

Now lets look for all files that match the pattern file?

john_iacovacci1@cloudshell:~/assign (vertex-uconn)$ ls -lt file?

-rw-rw-r-- 1 john_iacovacci1 john_iacovacci1 12 Jan 15 23:49 file3

-rwxrwxr-x 1 john_iacovacci1 john_iacovacci1  0 Jan 15 23:46 file2

-rwxrwxr-x 1 john_iacovacci1 john_iacovacci1  0 Jan 15 23:17 file1

We can now use the wildcard * to match the pattern fil*

john_iacovacci1@cloudshell:~/assign (vertex-uconn)$ ls -lt fil*

-rw-rw-r-- 1 john_iacovacci1 john_iacovacci1  0 Jan 15 23:54 filtest

-rw-rw-r-- 1 john_iacovacci1 john_iacovacci1 12 Jan 15 23:49 file3

-rwxrwxr-x 1 john_iacovacci1 john_iacovacci1  0 Jan 15 23:46 file2

-rwxrwxr-x 1 john_iacovacci1 john_iacovacci1  0 Jan 15 23:17 file1

other file commands are

Linux commands are the primary way to interact with the system's kernel. While there are thousands of commands, they generally fall into a few core categories: file management, system information, and networking.

File and Directory Management

These are the most common commands used to navigate the "tree" structure of the Linux file system.

  • ls (List): Shows the contents of a directory.

    • Tip: Use ls -la to see hidden files and detailed information like permissions.

  • cd (Change Directory): Moves you between folders.

    • Example: cd /home/user/Documents

  • pwd (Print Working Directory): Displays the full path of the folder you are currently in.

  • mkdir (Make Directory): Creates a new folder.

  • rm (Remove): Deletes files or directories.

    • Warning: rm -rf deletes folders and their contents permanently without a trash bin.

  • cp (Copy): Copies files or directories from one location to another.

  • mv (Move): Moves files, but is also used to rename files.

Viewing and Editing Files

These commands allow you to look inside files or modify their text without leaving the terminal.

  • cat (Concatenate): Displays the entire content of a file on your screen.

  • less: Similar to cat, but allows you to scroll through long files one page at a time.

  • head / tail: Displays the first 10 or last 10 lines of a file, respectively.

  • nano / vi: These are text editors built into the terminal. Nano is beginner-friendly, while Vi (or Vim) is powerful but has a steeper learning curve.

  • grep (Global Regular Expression Print): Searches for specific text within a file or output.

    • Example: grep "error" logfile.txt


System Permissions and Ownership

Linux is built on a strict security model where every file has an owner and specific permissions.

  • sudo (SuperUser Do): Runs a command with administrative (root) privileges.

  • chmod (Change Mode): Changes the read, write, and execute permissions of a file.

  • chown (Change Owner): Changes which user or group owns a file.

System Information and Management

Use these to check how your computer is performing or to manage software.

  • top / htop: Displays real-time information about running processes and CPU/RAM usage.

  • df (Disk Free): Shows how much space is left on your hard drives.

  • free: Displays the amount of free and used memory (RAM).

  • ps (Process Status): Lists the processes currently running on your system.

  • apt / yum / pacman: These are Package Managers used to install, update, or remove software (the specific command depends on your Linux distribution).

Networking

  • ping: Checks the connection between your machine and a domain/IP address.

  • ip addr: Shows your network interfaces and IP addresses.

  • ssh (Secure Shell): Allows you to securely log into a remote Linux computer.


TAB can be used to fill up the terminal command.

Example I can partially enter a file name or directory and use tab to fill it up as long as no other matching pattern exists. Can’t partially enter fil because too many choices but filt only has one.


john_iacovacci1@cloudshell:~/assign (vertex-uconn)$ ls -lt filt

Hit tab and it finishes the command

john_iacovacci1@cloudshell:~/assign (vertex-uconn)$ ls -lt filtest 


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.

Linux keeps a history of entered commands so you can hit UP until you find the previous command entered you want to execute.

exit terminal by using the exit command.

 The Shell Scripting Tutorial

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


Click on the file icon 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:~/assign (vertex-uconn)$ chmod +x hw.sh

john_iacovacci1@cloudshell:~/assign (vertex-uconn)$ ls -lt

total 8

-rwxr-xr-x 1 john_iacovacci1 john_iacovacci1 37 Jan 16 00:19 hw.sh

To execute the shell command you need to use the ./hw.sh which instruct linux to execute the command in the current directory. 

john_iacovacci1@cloudshell:~/assign (vertex-uconn)$ ./hw.sh

Hello UCONN World


Now let's 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:~/assign (vertex-uconn)$ chmod +x ao.sh

john_iacovacci1@cloudshell:~/assign (vertex-uconn)$ ./ao.sh

The sum of 10 and 5 is: 15

The result of 10 - 5 = 5

Using let   : 10 * 5 = 50



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

#!/bin/bash


#String Variables

greeting="Hello, World"

echo $greeting


x=10

y=20


# Arithmetic expansion

sum=$((x + y))

echo "Sum is $sum"


# Indexed array

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

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


# Loop through array

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

  echo $fruit

done


# Associative Arrays


declare -A capitals

capitals[France]="Paris"

capitals[Germany]="Berlin"

capitals[Italy]="Rome"


echo "Capital of Germany is ${capitals[Germany]}"


# Check if variable is set

if [ -z "$name" ]; then

  echo "Name is not set"

else

  echo "Name is $name"

fi


# Declare integer type explicitly

declare -i count=5

count+=2

echo "Count is $count"

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

john_iacovacci1@cloudshell:~/assign (vertex-uconn)$ chmod +x dt.sh

john_iacovacci1@cloudshell:~/assign (vertex-uconn)$ ./dt.sh

Hello, World

Sum is 30

First fruit: apple

apple

banana

cherry

Capital of Germany is Berlin

Name is not set

Count is 7



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:~/assign (vertex-uconn)$ chmod +x vd.sh

john_iacovacci1@cloudshell:~/assign (vertex-uconn)$ ./vd.sh

Enter your Age : 

25

Age: 25

john_iacovacci1@cloudshell:~/assign (vertex-uconn)$ ./vd.sh

Enter your Age : 

300

Error: Age must be between 1 and 120.

john_iacovacci1@cloudshell:~/assign (vertex-uconn)$ 



name.sh terminal input

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


#!/bin/bash

echo "Enter your full name : "

read my_name

echo "My Name is : " $my_name

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

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

john_iacovacci1@cloudshell:~/assign (vertex-uconn)$ ./name.sh

Enter your full name : 

John Iacovacci

My Name is :  John Iacovacci


Now add redirection to name.sh

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

#!/bin/bash

echo "Enter your full name : "

read my_name

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

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

john_iacovacci1@cloudshell:~/assign (vertex-uconn)$ ./name.sh

Enter your full name : 

John Iacovacci

john_iacovacci1@cloudshell:~/assign (vertex-uconn)$ ls -lt

total 28

-rw-rw-r-- 1 john_iacovacci1 john_iacovacci1  29 Jan 16 01:03 my_info.txt

-rwxr-xr-x 1 john_iacovacci1 john_iacovacci1  99 Jan 16 01:02 name.sh

-rwxr-xr-x 1 john_iacovacci1 john_iacovacci1 310 Jan 16 00:33 vd.sh

-rwxr-xr-x 1 john_iacovacci1 john_iacovacci1 670 Jan 16 00:31 dt.sh

-rwxr-xr-x 1 john_iacovacci1 john_iacovacci1 375 Jan 16 00:25 ao.sh

-rwxr-xr-x 1 john_iacovacci1 john_iacovacci1  37 Jan 16 00:19 hw.sh

-rw-rw-r-- 1 john_iacovacci1 john_iacovacci1   0 Jan 15 23:54 filtest

-rw-rw-r-- 1 john_iacovacci1 john_iacovacci1  12 Jan 15 23:49 file3

-rwxrwxr-x 1 john_iacovacci1 john_iacovacci1   0 Jan 15 23:46 file2

-rwxrwxr-x 1 john_iacovacci1 john_iacovacci1   0 Jan 15 23:17 file1

john_iacovacci1@cloudshell:~/assign (vertex-uconn)$ cat my_info.txt

My Name is :  John Iacovacci

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 "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

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

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

john_iacovacci1@cloudshell:~/assign (vertex-uconn)$ ./profile.sh

Enter your full name : 

John Iacovacci

Enter your major : 

Computer Science

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

✅ You entered: Senior

Your Graduation year is 2026

john_iacovacci1@cloudshell:~/assign (vertex-uconn)$ ls -lt

total 36

-rw-rw-r-- 1 john_iacovacci1 john_iacovacci1  119 Jan 16 01:08 my_profile.txt

-rwxr-xr-x 1 john_iacovacci1 john_iacovacci1 1149 Jan 16 01:07 profile.sh

-rw-rw-r-- 1 john_iacovacci1 john_iacovacci1   29 Jan 16 01:03 my_info.txt

-rwxr-xr-x 1 john_iacovacci1 john_iacovacci1   99 Jan 16 01:02 name.sh

-rwxr-xr-x 1 john_iacovacci1 john_iacovacci1  310 Jan 16 00:33 vd.sh

-rwxr-xr-x 1 john_iacovacci1 john_iacovacci1  670 Jan 16 00:31 dt.sh

-rwxr-xr-x 1 john_iacovacci1 john_iacovacci1  375 Jan 16 00:25 ao.sh

-rwxr-xr-x 1 john_iacovacci1 john_iacovacci1   37 Jan 16 00:19 hw.sh

-rw-rw-r-- 1 john_iacovacci1 john_iacovacci1    0 Jan 15 23:54 filtest

-rw-rw-r-- 1 john_iacovacci1 john_iacovacci1   12 Jan 15 23:49 file3

-rwxrwxr-x 1 john_iacovacci1 john_iacovacci1    0 Jan 15 23:46 file2

-rwxrwxr-x 1 john_iacovacci1 john_iacovacci1    0 Jan 15 23:17 file1


Environmental variables and PATH


In Linux, environment variables are dynamic "placeholders" that store information about the system environment. They are used by the shell and other processes to determine how the system should behave and where to find specific files.


Think of them as a global dictionary of settings that any program can look up when it starts.


How They Work

Every time you open a terminal session, the system initializes a set of variables. These variables exist in the background and guide the operating system's interaction with the user.

Common Examples

  • $PATH: Perhaps the most important variable. It contains a list of directories where the system looks for executable files (commands).

  • $USER: Stores the username of the current logged-in user.

  • $HOME: Points to the path of the current user's home directory.

  • $SHELL: Identifies which shell program you are currently using (e.g., /bin/bash or /bin/zsh).

  • $PWD: Stores the current working directory path.

Key Commands

You can interact with environment variables using these basic commands:

Command

Purpose

printenv

Lists all current environment variables.

echo $VARIABLE_NAME

Displays the value of a specific variable (the $ is required to reference it).

export VAR=value

Sets a new environment variable for the current session and child processes.

unset VAR

Removes an environment variable.


Why They Matter

Environment variables allow for portability and automation. Instead of hard-coding a specific file path into a script, a developer can use $HOME. This ensures the script works for every user on the system, regardless of their specific username or directory structure.

By putting the directory in the PATH, you do not have to use the ./ that tells linux the script is in the local directory. If it is not in the PATH it you need the ./

john_iacovacci1@cloudshell:~/assign (vertex-uconn)$ export PATH=$PATH:/home/john_iacovacci1/assign

john_iacovacci1@cloudshell:~/assign (vertex-uconn)$ hw.sh

Hello UCONN World


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

Cloud run exercise

  To all: Please try to get the Hello World Hello World Cloud run  part of the Blog. https://uconnstamfordslp.blogspot.com/p/google-cloud-ru...