COMMANDS:

 1. ls, cd, touch, mv, rm

  •  ls: Stands for "list." It's a command used in Unix-based systems to list the files and directories in the current directory. ex: ls  file1.txt file2.txt directory1 directory2
  • cd: Stands for "change directory." It's used in command-line interfaces to change the current working directory. 
  • For example, cd Documents would move you into the "Documents" directory.
  • ex: cd Documents
  • touch: Creates a new file in Unix-based systems. For instance, touch newfile.txt will create a new, empty file named "newfile.txt". ex: touch newfile.txt
  • mv: Stands for "move." It's used to move or rename files and directories in Unix-based systems. For example, mv file.txt directory/ moves the file "file.txt" into the directory                                               ex:  mv oldfile.txt newfile.txt
  • rm: Stands for "remove." It's used to delete files or directories in Unix-based systems. For example, rm file.txt will delete the file "file.txt". Use with caution as deleted files are typically not recoverable. ex: rm file.txt

2.  man, mkdir, rmdir, tar, gzip

  • man: This command is used to display the manual of other commands in the terminal. For example, man ls will display the manual (documentation) for the ls command, showing its usage, options, and examples.
  • mkdir: Stands for "make directory." It's used to create a new directory or folder in the file system. For example, mkdir new_directory will create a directory named "new_directory".
  • rmdir: Stands for "remove directory." It's used to delete an empty directory from the file system. For example, rmdir old_directory will remove the directory named "old_directory", but it only works if the directory is empty.
  • tar: Stands for "tape archive." It's used to create and manipulate tar archives, which can be collections of files or directories. For example, tar -cvf archive.tar directory will create a tar archive named "archive.tar" containing the contents of the "directory".
  • gzip: This command is used to compress files. It's often used in combination with the tar command to create a compressed tar archive. For example, gzip file.txt will compress the file "file.txt" and create a compressed file named "file.txt.gz".

3.  cat, more, less, ps, sudo

  • cat: Concatenates and displays the contents of files. ex:  cat example.txt
  • more: Allows viewing the contents of a file one page at a time. ex:  more example.txt
  • less: Similar to more but with additional capabilities like backward scrolling. ex: less example.txt
  • ps: Displays information about processes running on a system. ex: ps 
  • sudo: "Superuser do," used to execute commands with elevated privileges, often requiring a password for authentication. ex: sudo apt install package_name

4.   sudo, cron, chown, chgrp, ping

  • sudo: Stands for "superuser do." It's used to execute commands with elevated privileges, often as the root user, allowing users to perform administrative tasks.
  • cron: This is a time-based job scheduler in Unix-like operating systems. It allows users to schedule jobs (commands or scripts) to run periodically at fixed times, dates, or intervals.
  • chown: Stands for "change owner." It's a command used to change the owner of a file or directory in Unix-like operating systems. This changes the user who has ownership rights over the file or directory.
  • chgrp: Stands for "change group." Similar to chown, this command is used to change the group ownership of a file or directory in Unix-like operating systems.
  • ping: A network utility used to test the reachability of a host on an Internet Protocol (IP) network. It sends ICMP (Internet Control Message Protocol) echo request packets to the target host and waits for an ICMP echo reply.

1b: Read your name and print Hello message with name

name = input("Enter your name: ")
print("Hello, " + name") 
    

2b, 6b: Read two numbers and print their sum, difference, product and division.

num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
sum_result = num1 + num2
difference = num1 - num2
product = num1 * num2
division = num1 / num2
print(f"Sum: {sum_result}")
print(f"Difference: {difference}")
print(f"Product: {product}")
print(f"Division: {division}")

3b: Word and character count of a given string

input_string = "Your string goes here."
word_count = len(input_string.split())
character_count = len(input_string)
print(f"Word count: {word_count}")
print(f"Character count: {character_count}")
    

4b: Area of a given shape (rectangle, triangle and circle) reading shape and appropriate values from standard input

import math

def rectangle_area(length, width):
    return length * width

def triangle_area(base, height):
    return 0.5 * base * height

def circle_area(radius):
    return math.pi * radius * radius

# Reading shape and values from the user
shape = input("Enter shape (rectangle, triangle, circle): ")

if shape == "rectangle":
    length = float(input("Enter length: "))
    width = float(input("Enter width: "))
    area = rectangle_area(length, width)
    print(f"The area of the rectangle is: {area}")

elif shape == "triangle":
    base = float(input("Enter base: "))
    height = float(input("Enter height: "))
    area = triangle_area(base, height)
    print(f"The area of the triangle is: {area}")

elif shape == "circle":
    radius = float(input("Enter radius: "))
    area = circle_area(radius)
    print(f"The area of the circle is: {area}")

else:
    print("Invalid shape entered.")

    

5b. Print a name n times, where name and n are read from standard input, using for and while loops.

# Using for loop
name = input("Enter a name: ")
n = int(input("Enter the number of times to print the name: "))

print("Printing using for loop:")
for _ in range(n):
    print(name)

# Using while loop
count = 0
print("Printing using while loop:")
while count < n:
    print(name)
    count += 1
    

7b. Handle Divided by Zero Exception.

try:
    numerator = 10
    denominator = 0
    result = numerator / denominator
    print("Result:", result)

except ZeroDivisionError:
    print("Error: Division by zero is not allowed.")
    

8b. Print current time for 10 times with an interval of 10 seconds.

import time
# Repeat for 10 times with a 10-second interval
for _ in range(10):
    current_time = time.strftime("%H:%M:%S", time.localtime())
    print("Current time:", current_time)
    time.sleep(10)  # Wait for 10 seconds
    

9b. Read a file line by line and print the word count of each line

file_path = 'your_file.txt' 
with open(file_path, 'r') as file:
    for line in file:
        words = line.split()  # Split the line into words
        word_count = len(words)  # Count the number of words
        print(f"Word count in this line: {word_count}")
    

EXPERIMENT

 Pdf - click on week to download 




Week 4,6,7,8---> click here 

Week-5 for week 5 refer to manual given below

  1.   Light an LED through Python program---->  see week 3
  2.   Get input from two switches and switch on corresponding LEDs-->see week 4
  3.   Flash an LED at a given on time and off time cycle, where the two times are taken  from a file.:    exp--> see week 5
  4.   Flash an LED based on cron output (acts as an alarm)---> see week 6
  5.   Switch on a relay at a given time using cron, where the relay contact terminals are  Connected to a load.---> see week 7
  6.   Get the status of a bulb at a remote place (on the LAN) through web.--> see week 8