EXPERIMENT NO. 01 Name of Experiment Implement following commands with their options: ps and kill. df and du mount and umount. (4 Hours) Prerequisite of. / execution of Basic knowledge about linux command. Linux Operating System. Open shell terminal Set ps command and get information of process. Set $ ps ag command for real time process monitoring. Use kill command to kill process by ID $kill 1020 Use killall command to kill all processes. Kill with process name $killall processname Stop all process $kill 0 Df command is used to check disk available space. $df $df h The du command shows the disk usage for a specific directory (by default, the current directory). $du c $du h Mount Command mount -t vfat /dev/sdb1 /media/disk Unmount Command $umount Check command result and notice that results. Do not kill system processes. Note down all results after command execution. Describe Linux file structure in details.
EXPERIMENT NO. 02 Name of Experiment Implement grep and tar commands. (4 Hours) Prerequisite of. / execution of Open Linux shell Before performing grep command need files for searching data Type in shell Create sample files in linux in home directory $cat file1 One two three four $man grep Check grep manual and performing operating $grep two file Use different attributes Use tar command for archiving file $man tar $tar cvf test.tar /test1/test2 Use different parameters and attributes in grep and tar command examples. Note down result of different attributes used in examples Explain grep and tar commands with 4 examples.
EXPERIMENT NO. 03 Name of Experiment Prerequisite of. / execution of Implement setting of global and local environment variable, shell environment variables. (4 Hours) Open Linux shell $ echo $SHELL would give you the name of the current shell you are using. To see a list of the environment variables that are already set on your machine, type the following- $ env Display current environment variables- $set Printing shell, environment variables $printenv $env VAR1="blahblah" command_to_run command_options Creating Environment variables $test_var=testing $echo test_var $export test_var $echo $test_var e.g $export PATH=${PATH}:/home/cse/bin Removing Environment Variables $unset test_var Seting PATH variable $ PATH=$PATH:/home/rich/test Setting Shell variables $test_var='cse' To define a temporary value to a shell variable use the command: $set variable_name=value Use different parameters and attributes in shell commands Note down result of different attributes used in examples
EXPERIMENT NO. 04 Name of Experiment Create users, groups.set permissions and ownership. View the /etc/passwd file and describe its syntax. View the /etc/shadow file and describe its syntax. View the /etc/group file and describe its syntax. (4 Hours) Prerequisite of. Equipment/ Instrumentation Adding a new user Open Linux shell # /usr/sbin/useradd D You can test this by creating a new user account using the default system parameters # /usr/sbin/useradd test Changing the default values is a snap: # useradd -D -s /bin/tsch Removing a user # /usr/sbin/userdel -r test Modifying a user Usermod passwd and chpasswd # passwd test The chpasswd command reads a list of login name and password pairs (separated by a colon) from the standard input, and automatically encrypts the password and sets it for the user account. chsh, chfn, and chage # chfn test # finger rich # chfn test # finger test The /etc/group file Creating new groups # /usr/sbin/groupadd shared # /usr/sbin/usermod -G shared test Modifying groups # /usr/sbin/groupmod -n sharing shared Default file permissions $ touch newfile $ ls -al newfile $ umask Changing permissions Format: chmod options mode file
$ chmod 760 newfile $ ls -l newfile $ chmod o+r newfile Changing ownership The format of the chown command is: chown options owner[.group] file # chown dan newfile # ls -l newfile The /etc/passwd file $man passwd $ cat /etc/passwd The /etc/shadow file The /etc/shadow file contains one record for each user account on the system. A record looks like this: rich:$1$.ffck0ns$f1ugiyhq25wrb/hykcn020:11627:0:99999:7::: In between check Points Use ls command to check system result of operation. during / execution of Note down result of different attributes used in examples.
EXPERIMENT NO. 05 Name of Experiment Prerequisite of. / execution of Implement setting up and releasing of special permissions (SGID, SUID and sticky bit) and state their effects. (4 Hours) Open Linux shell The set user id (SUID): When a file is executed by a user, the program runs under the permissions of the file owner. The set group id (SGID): For a file, the program runs under the permissions of the file group. For a directory, new files created in the directory use the directory group as the default group. The sticky bit: The file remains (sticks) in memory after the process ends. to create a shared directory that always sets the directory group for all new files, all you need to do is set the SGID bit for the directory: $ mkdir testdir $ ls l $ chgrp shared testdir $ chmod g+s testdir $ ls l $ umask 002 $ cd testdir $ touch testfile $ ls -l Use different parameters and attributes in shell commands Note down result of different attributes used in examples
EXPERIMENT NO. 06 Name of Experiment Implement I/O Redirection and Pipes. (4 Hours) Prerequisite of. Output redirection The most basic type of redirection is sending output from a command to a file. The bash shell uses the greater-than symbol for this: command > outputfile $ date > test6 $ ls -l test6 $ cat test6 Now the contents of the test6 file contain the output from the who command. $ who > test6 $ cat test6 $ date >> test6 $ cat test6 The test6 file still contains the original data from the who command processed earlier, plus now it contains the new output from the date command. Input redirection The input redirection symbol is the less-than symbol (<): command < inputfile $ wc < test6 The wc command provides a count of text in the data. The inline input redirection symbol is the double less-than symbol (<<). Besides this symbol, you must specify a text marker that delineates the beginning and end of the data used for input. command << marker $ wc << EOF > test string 1 > test string 2 > test string 3 > EOF Pipes There are times when you need to send the output of one command to the input of another command. This process is called piping. The pipe symbol is the bar operator ( ): command1 command2 Now, using piping you can easily pipe the output of the rpm command directly to the sort
command to produce your results: $ rpm -qa sort / execution of Use different parameters and attributes in shell commands Note down result of different attributes used in examples Subject Teacher (Mr. Pise S. P ) HOD (Mr. Patil P.R.)
EXPERIMENT NO. 07 Name of Experiment Write shell script to demonstrate use of conditional and loop control statements. Write a shell script that shows effects of quotes on the Output of a variable. Write a shell script that looks through all the files in the current directory for the string POSIX and then prints the name of these files to the standard output. (6 Hours) Prerequisite of. Here The syntax expressed the how to use loops: if [ expression ] then Statement(s) to be executed if expression is true fi If else if [ expression ] then Statement(s) to be executed if expression is true else Statement(s) to be executed if expression is not true fi While Loop while command do Statement(s) to be executed if command is true Done For Loop for var in word1 word2... wordn do Statement(s) to be executed for every word. done try this Code for standard output #finding name of files echo current working directory files
find. print find. -name POSIX ls > search.txt ls > find. name POSIX #find name \*.txt.posix.txt ls > search.txt / execution of Use different parameters and attributes in shell commands Note down result of different attributes used in examples Subject Teacher (Mr. Pise S. P ) HOD (Mr. Patil P.R.)
EXPERIMENT NO. 08 Name of Experiment Write shell script to implement following test commands : For string comparisons. For numeric comparisons. For file comparisons (6 Hours) Prerequisite of. String Comparison Example 1: $ cat > test9b # testing string sort order val1=testing val2=testing if [ $val1 \> $val2 ] then echo "$val1 is greater than $val2" else echo "$val1 is less than $val2" fi $ sh test9b Testing is less than testing $ sort testfile Numeric Comparison Example 1: $ cat > test5 # using numeric test comparisons val1=10 val2=11 if [ $val1 -gt 5 ] then echo "The test value $val1 is greater than 5" fi if [ $val1 -eq $val2 ] then echo "The values are equal" else echo "The values are different" fi
echo The first test condition: if [ $val1 -gt 5 ] echo tests if the value of the variable val1 is greater than 5. The second test condition: if [ $val1 -eq $val2 ] echo There is a limitation to the test numeric conditions though. Try this script: #sh test5 File Comparison Example 1: $ cat > test11 # look before you leap if [ -d $HOME ] then echo "Your HOME directory exists" cd $HOME ls -a else echo "There s a problem with your HOME directory" fi $ sh test11 / execution of Use different parameters and attributes in shell commands Note down result of different attributes used in examples Subject Teacher (Mr. Pise S. P ) HOD (Mr. Patil P.R.)
EXPERIMENT NO. 09 Name of Experiment Write shell script that : Uses command line parameters. Counts number of parameters. Implements shift command. Implements processing option with parameter values. (6 Hours) Prerequisite of. Command Line Parameter Example 1 $ cat > test4 # handling lots of parameters total=$[ ${10} * ${11} ] echo The tenth parameter is ${10} echo The eleventh parameter is ${11} echo The total is $total $ sh test4 1 2 3 4 5 6 7 8 9 10 11 12 Counting Parameters Example 1 $ cat > test8 # getting the number of parameters echo There were $# parameters supplied. $ sh test8 There were 0 parameters supplied. $ sh test8 1 2 3 4 5 There were 5 parameters supplied. $ sh test8 1 2 3 4 5 6 7 8 9 10 There were 10 parameters supplied. $ sh test8 "Rich Blum" There were 1 parameters supplied. $ Shift Command
/ execution of Example 2 $ cat > test14 # demonstrating a multi-position shift echo "The original parameters: $*" shift 2 echo "Here s the new first parameter: $1" $ sh test14 1 2 3 4 5 Use different parameters and attributes in shell commands Note down result of different attributes used in examples Subject Teacher (Mr. Pise S. P ) HOD (Mr. Patil P.R.)
EXPERIMENT NO. 10 Name of Experiment Write shell script : To implement redirection of Input script. For redirecting file descriptors. Creating input file descriptor. (6 Hours) Prerequisite of. Redirecting Input in Scripts Example 1 $ cat test12 # redirecting file input exec 0< testfile count=1 while read line do echo "Line #$count: $line" count=$[ $count + 1 ] done $./test12 Redirecting file descriptors Example 1 $ cat test14 # storing STDOUT, then coming back to it exec 3>&1 exec 1>test14out echo "This should store in the output file" echo "along with this line." exec 1>&3 echo "Now things should be back to normal" $./test14 Now things should be back to normal $ cat test14out This should store in the output file along with this line. $
/ execution of Creating input file descriptors Example 1 $ cat test15 # redirecting input file descriptors exec 6<&0 exec 0< testfile count=1 while read line do echo "Line #$count: $line" count=$[ $count + 1 ] done exec 0<&6 read -p "Are you done now? " answer case $answer in Y y) echo "Goodbye";; N n) echo "Sorry, this is the end.";; esac $./test15 Use different parameters and attributes in shell commands Note down result of different attributes used in examples Subject Teacher (Mr. Pise S. P ) HOD (Mr. Patil P.R.)
EXPERIMENT NO. 11 Name of Experiment Practice sed editor and gawk utility. (6 Hours) Prerequisite of. Sed The format for using the sed command is: sed options script file $ echo "This is a test" sed s/test/big test/ This is a big test $ Using multiple editor commands in the command line To execute more than one command from the sed command line, just use the -e option: $ sed -e s/brown/green/; s/dog/cat/ data1 Reading editor commands from a file $ cat script1 s/brown/green/ s/fox/elephant/ s/dog/cat/ $ sed -f script1 data1 Gawk The gawk command format The basic format of the gawk program is: gawk options program file Reading the program script from the command line $ gawk {print "Hello John!"} Using data field variables $ cat data3 One line of test text. Two lines of test text. Three lines of test text. $ gawk {print $1} data3 Using multiple commands in the program script $ echo "My name is Rich" gawk {$4="Dave"; print $0} My name is Dave $ Reading the program from a file $ cat script2
/ execution of { print $5 " s userid is " $1 } $ gawk -F: -f script2 /etc/passwd Running scripts before processing data $ gawk BEGIN {print "Hello World!"} Hello World! $ $ gawk BEGIN {print "Hello World!"} {print $0} Running scripts after processing data $ gawk BEGIN {print "Hello World!"} {print $0} END {print "byebye"} $ cat script4 BEGIN { print "The latest list of users and shells" print " Userid Shell" print "-------- -------" FS=":" } { print $1 " " $7 } END { print "This concludes the listing" } $ Use different parameters and attributes in shell commands Note down result of different attributes used in examples Subject Teacher (Mr. Pise S. P ) HOD (Mr. Patil P.R.)
EXPERIMENT NO. 12 Name of Experiment Write a shell script using functions. Modify it to handle function with parameters, function returning values. Write shell script for handling array variables. Write shell script that uses function returning true or false result. (6 Hours) Prerequisite of. Returning a Value Example 1 $ cat test4 # testing the exit status of a function func1() { echo "trying to display a non-existent file" ls -l badfile } echo "testing the function:" func1 echo "The exit status is: $?" $./test4 Example 2 $ cat test5 # using the return command in a function function dbl { read -p "Enter a value: " value echo "doubling the value" return $[ $value * 2 ] } dbl echo "The new value is $?" $ Passing parameters to a function $ cat badtest1 # trying to access script parameters inside a function function badfunc1 { echo $[ $1 * $2 ] } if [ $# -eq 2 ] then
/ execution of value=`badfunc1` echo "The result is $value" else echo "Usage: badtest1 a b" fi $./badtest1 Usage: badtest1 a b $./badtest1 10 15./badtest1: * : syntax error: operand expected (error token is "* ") The result is $ Passing arrays to functions $ cat test10 # array variable to function test function testit { local newarray newarray=(`echo "$@"`) echo "The new array value is: ${newarray[*]}" } myarray=(1 2 3 4 5) echo "The original array is ${myarray[*]}" testit ${myarray[*]} $./test10 Use different parameters and attributes in shell commands Note down result of different attributes used in examples Subject Teacher (Mr. Pise S. P ) HOD (Mr. Patil P.R.)
EXPERIMENT NO. 13 Name of Experiment Write a shell script which checks disk space and store the value to the variable and display it. Write a shell script that tests connectivity with the PCs whose IPs are provided as command line parameters. (6 Hours) Prerequisite of. / execution of Use different parameters and attributes in shell commands Note down result of different attributes used in examples Subject Teacher (Mr. Pise S. P ) HOD (Mr. Patil P.R.)