INDEX S.NO PRACTICALS SIGN 1. Shell Commands 2. Shell Commands For Processes 3. File Commands 4. Script that displays a simple Welcome Message 5. Shell script to display calendar, date and process status. 6. Shell script to print the multiplication table of any number. 7. Shell script to enter the age and declare it on the screen. 8. Shell script to find factorial of a given number. 9. Shell script to count the no. of words and chars in a file. 10. Shell script to print Fibonacci series. 11. Shell script to sort a given list of integers 12. Shell script to find whether the entered number is even or odd. 13. Shell script to calculate simple interest. 14. Shell script to generate odd numbers between 1 and 50. 15. Shell script to accept a number from user, n and display square of all numbers from 1 to n.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
INDEX
S.NO PRACTICALS SIGN
1. Shell Commands
2. Shell Commands For Processes
3. File Commands
4. Script that displays a simple Welcome Message
5. Shell script to display calendar, date and process status.
6. Shell script to print the multiplication table of any number.
7. Shell script to enter the age and declare it on the screen.
8. Shell script to find factorial of a given number.
9. Shell script to count the no. of words and chars in a file.
10. Shell script to print Fibonacci series.
11. Shell script to sort a given list of integers
12. Shell script to find whether the entered number is even or odd.
13. Shell script to calculate simple interest.
14. Shell script to generate odd numbers between 1 and 50.
15. Shell script to accept a number from user, n and display square of all numbers from 1 to n.
16. Shell script to generate the series 1,3,2,4,3,5,4,6……100.
17. Shell script to check if a given string is a palindrome or not (without reversing the string).
18. Shell script to reverse a string.
1. SHELL COMMANDS
1) Exit
This command is used to exit from the shell.
2) Log out This command is used to log out from the shell.
3) echo
This command is used to print text on the screen.
4) echo $PATH
This command gives the path of the shell.
5) Cal This command shows the calendar of present month.
6) Cal 2009
This command shows the calendar of 2009.
7) Cal 2009 | move
This command shows the calendar of year 2009 pagewise and we have to press enter to see next page. “ | ” is known as the pipe. It transfer the output of Cal command to the move command.
8) Date
This command shows the current date.
a) Date +%m
This gives the number of current month.
b) Date +%n
This gives the name of the current month.
9) who
This command shows how many users are log in.
10) tty
This command shows the current terminal on which we are working
11) wall
This command broadcasts the message on all the terminals.
12) write system_number
This command send the message to a particular system specified by system number.
2. Shell Commands For Processes
1) ps
This command list all the processes that are currently running giving details such as process id, terminal, time and command.
2) pstree
This command lists all the processes in a tree structure.
3) pstree -p
This command in addition to displaying the processes in a tree structure also displays process ID.
4) pgrep
This command gives ID of the mentioned process.
For eg pgrep date:- This will show the process ID of the process. If we use option –l then in addition to PID it also shows process name.
5) top
This command displays all the top processes. It give more details than ps command. It refreshes all the process after every five seconds.
6) kill PID
It simply kills a process by mentioning its ID.
7) kill % job_number
This command kills the job specified by the job_number.
8) kill all
This command uses the name of the process to kill the process instead of PID.
9) pkill
This command kills a process by a small match.
For eg. Pkill -u user_1 user_2 process_name
This command kills the process specified by process_name of user_1 and user_2.
10) skill
This command is used to send a particular signal.
skill _ STOP user_name :- This command stops all user processes until we send continue signal.
11) ctrl c
This command interrupts the execution. Also known as break command.
12) jobs
It lists all the jobs running on the background and foreground in groups.
13) nice
This command is used by the administrator to set the priority of the processes.
14) renice
It changes the priority of the processes.
15) &
This operator will not allow user to log out while the jobs are running. This is shell operator used to run a process in background.
3.File Commands
1) Print Working Directory (pwd) Checking the current working directory
2) Change Directory(cd)Changing the current directory
3) Make Direcotry (mkdir) Is use to create directory & subdirectories under the directory
4) Remove Directory (rmdir) Removing drectory
5) ls Display all files 6) cp Copying a file
7) rm Deleting file
8) mv Moving & renaming files
9) more Display data one screen full at a time
10) less Similar to more but we can move upward also
11) head Shows first ten lines of a file
12) tail Shows last ten lines of a file 13) uptime Display how long the system has been running how many users are
currently logged on, system load average for the percentage cpu utilization, in last one 5, 15 minutes.
14) fileDisplays the file type
15) Word Count (wc) Counting the words , lines, characters.
16) Octal Display(od) Displays the octal representation of the file content
17) Compare (cmp) Comparing the two sorted files.
18) Common(comm.) This command displays the common content of the file.
19) gzip and gunzip Compressing and Decompressing the file
20) tar The archival program with the following options:
a) tar-x : Extract files from archiveb) tar-t : Display files in archivec) tar-c : Create the archive
21) zip and unzipCreates and archive as well as compressing the file
22) Change Mode (chmod)This command change the permission on the file
23) mount Attachment of the file or device 24) umount Deatchments of a file or device
4. Write a shell script that simply displays a Welcome message.
echo "WELCOME TO THE SHELL SCRIPTS"
OUTPUT:
$ ./test
WELCOME TO THE SHELL SCRIPTS
5. Write a shell script to display calendar, date and process status. echo”User Calender” cal mm yyyy echo “DATE” date echo ”Process Ststus” psOUTPUT$ sh linux1.shUser Calender November 2009 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 1415 16 17 18 19 20 21
22 23 24 25 26 27 2829 30 DATE Tue Nov 17 22:08:48 PST 2009Process Status PID TTY TIME CMD 3239 pts/0 00:00:00 bash 3585 pts/0 00:00:00 sh 3622 pts/0 00:00:00 ps
6. Write a shell script to print the multiplication table of any number.
echo “Enter the number: “
read num //cmd to read user input
count=1 //user defined variable
echo “The Table is : “
while[$count-le 10] //checking the value of count continues till 10
do
ans= ’expr $count \* $num’ //multiplying the required numbers