Posts

Assignment-4 Learn to Write Advanced Scripts

1.Create a script that accepts a filename as input and checks if it exists. 2.List the empty files in the current directory. 3.Write a script to copy files from one directory to another.(backup files) 4.Develop a script to delete all files with a specific extension in a directory.(cleaning up) 5..List the name,file size of ordinary files( avoid directories) in the current directory in the descending order of file size. ( Hint:Use tr,grep,tail,cut and sort command) 6.Display the contents of the smallest file( file size is lowest) 7.List the pid(process id), start time and process (command) of all running process.( Hint: use ps –aux command) 8.List the details of the process with process id 1.(Hint use ps command and grep) 9.List the permissions of user and file name of ordinary files in the current directory( avoid directories). (hint use grep, tr –s,cut –c ,paste. Cut the required fields and store in temporary files.Paste them together using paste.) 10.List the directories only with pe...

Assignment-2 Learn Control Statements

  Learn Control Statements- Write the shell scripts 1.Check whether the number is even or odd(if else) 2. Check the quadrant of a given point(x,y) ( if else with multiple conditions) 3. Find the biggest of 3 numbers ( if elif) 4.Enter a month number and print its name( case) 5. Check whether the given number is prime or not ( while) 6.Find sum of the digits of a number.( until) 7.Print all odd numbers less than 50. ( for) 8.Print all the words and its length from a file f. ( for) 9.Check whether the given string is palindrome.(string functions) 10.Print palindrome words from a file(nested loops - for ) 11.Print all prime numbers less than 100 ( nested loop -while) 12.Print the words starting with letter ‘a’ in sorted order from a file f.( Hint:use for loop to extract words and write it to another file. Use sort command to sort and then use grep command to extract words starting with letter ‘a’) Note: We do these programs to learn the syntax of control statements. Shell scripts ...

Assignment-1 Simple Shell Scripts

  Write shell scripts to show the following ( you can write menu driven programs) 1. a)Display the date and time b)Current month calendar c)contents of the home directory of a user 2. a)Currently logged user and his logname b) Your current shell c) Your home directory 3. a)Your operating system type b) Your current path setting c) Your current working directory . 4. a)Show Currently logged users b)Show only the user name of logged users in the host. c)Details of last login 5. a) About your OS and version, release number, kernel version b) Show all available shells c) Show mouse settings 6. a)CPU details b) Show information on CPU architecture c)Number of Processor core 7. a)Memory details b) Display file system disk usage c)Display the amount of free and used memory d)Virtual memory statistics e) File system Mounted Write shell scripts 1. Menu ( GUI) driven program to display long listing of files in the current directory ( ls –l) list of users currently logge...

Assignment-3 Learn Filter Commands and Data Processing

  Write shell scripts to do the following on a “stud” data file which contains rno,name,dob ( date of birth),m1,m2,m3 ( mark in three subjects out of 50). Create the “stud” file in the following format using any editor. 101|hari | 06-05-1985|30|40|35 102|devi | 03-08-1982|40|35|28 ................................................................add more data in the same format ( you can write menu driven programs) 1. ( Hint :Use sort command ) a) List the students in the order of roll number b) list the students in the order of name c) list the students in the order of year of birth 2.( Hint: Use cut command ) a) List the roll number and name of all students. b) List the roll number, name and m3. c) List roll number, name and dob of all students. 3.(Hint :use cut ,and sort command) a) List roll number, name m1 in the descending order of m1. b)List the roll number , name and m2 of the top 5 performers in subject 2. ( use head) c)List the roll number , name an...

fork

The fork() function in C is used for creating a new process in Linux and Unix systems. It allows you to create a child process that runs concurrently with the process that makes the fork() call (which is the parent process).  Here’s the basic syntax: #include <unistd.h>   pid_t fork(void); The unistd.h header file, commonly used in C and C++ programming languages, provides access to the POSIX operating system API. Let’s break down its significance: Definition and Purpose: unistd.h stands for “Unix Standard Header”. It serves as a bridge between your program and the underlying operating system, enabling interaction with system resources and services. The header file contains function prototypes, macros, and constants that allow your program to communicate with the operating system. Functionality:The interface defined by unistd.h includes various system call wrapper functions and I/O primitives. Some notable functions and features provided by unistd.h: fork: Creates ...

I/O Operations Reading/writing Files

Let’s explore how to perform file I/O using system calls in Linux. We’ll cover creating, opening, reading, writing, and closing files using low-level system calls. Creating a New File: To create a new file, you can use the open() system call. Syntax:       int open(const char *pathname, int flags, mode_t mode); Parameters:      pathname: The path to the file you want to create.      flags:Flags specifying the file access mode (e.g., O_CREAT | O_WRONLY for write-only).      mode: Permissions for the new file (e.g., 0644 for read-write permissions for the owner and read-only                     permissions for others). Example: #include <fcntl.h>  #include <stdio.h>  #include <stdlib.h>   int main()  { const char *filename = "new_file.txt";   int fd = open(filename, O_CREAT | O_WRONLY, 0644);   if (fd =...

Reading The File Status

The important steps in Reading the file status Open the File: Use the fopen() function to open the file in read mode. The file path and mode (e.g., "r") are required parameters. Read File Properties: Use the stat() function to retrieve information about the file. The stat structure contains details such as file size, permissions, creation time, and modification time. Print File Properties: Extract relevant information from the stat structure. Print details like file size, creation date, and modification date.  #include <stdio.h> #include <sys/stat.h> #include <unistd.h> #include <errno.h> #include <string.h> #include <time.h> int main() { char filename[50]; struct stat fileStat; printf("Enter the filename:"); scanf("%s",filename); // Call stat() to get file status if (stat(filename, &fileStat) == -1) { perror("Error"); return 1; } printf("Information for %s\n",filename); printf("-------------...