Part A Procedure
Part A Procedure
for file in *
do
if [ -f $file ]
then
if [ -r$file -a -w$file -a -xfile ]
then
ls -l $file
fi
fi
done
procedure:
step 1- open a nano editor
nano progname.sh
step 2- type the program
step 3- save the program
ctrl+x
press Enter
step 4- Execute the program
sh progname.sh
procedure:
step 1-create a file with content
cat>filename (creating a file with content)
hello world (content)
ctrl+d (to save the file)
step 2- open a nano editor
nano progname.sh
step 3- type the program
step 4- save the program
ctrl+x
press Enter
step 5- Execute the program
sh progname.sh
1. Write grep commands to the following:
a. To select the lines from a file that has exactly 2
characters.
b. To select the lines from a file that has more than one
blank spaces.
procedure:
step 1-create a file with content
cat>filename (creating a file with content)
hello
hi
world
my
ctrl+d (to save the file)
step 2- open a nano editor
nano progname.sh
step 3- type the program
step 4- save the program
ctrl+x
press Enter
step 5- Execute the program
sh progname.sh
procedure:
step 1-create a file with content
cat>filename (creating a file with content)
hi my name is rama
welcome to my world
ctrl+d (to save the file)
step 2- open a nano editor
nano progname.sh
step 3- type the program
step 4- save the program
ctrl+x
press Enter
step 5- Execute the program
sh progname.sh
procedure:
step 1-create a file with content
cat>file1
hello wolrd
ctrl+d
step 2- create a second file
cat>file2
hello wolrd
step 3- open a nano editor
nano progname.sh
step 4- type the program
step 5- save the program
ctrl+x
press Enter
step 6- Execute the program
sh progname.sh
Output:$sh 6.sh
Enter first file name
file1
Enter second file name
file2
contents of the files are same
successfully removed duplicate file
3. Write a shell script
a. to count number of lines in a file that do not contain
vowels.
b. to count number of characters, words, lines in a given
file.
procedure:
step 1-create a file with content
cat>filename (creating a file with content)
try
hello
my
ctrl+d (to save the file)
step 2- open a nano editor
nano progname.sh
step 3- type the program
step 4- save the program
ctrl+x
press Enter
step 5- Execute the program
sh progname.sh
procedure:
step 1-create a file with content
cat>filename (creating a file with content)
hello welcome to my world
ctrl+d (to save the file)
step 2- open a nano editor
nano progname.sh
step 3- type the program
step 4- save the program
ctrl+x
press Enter
step 5- Execute the program
sh progname.sh
Output:-$sh 7b.sh
Enter file name
f1
Number of characters in f1 is 33
Number of words in f1 is 6
Number of lines in f1 is 4
4. Write a shell script to list all the files in a given
directory.
procedure:
step 1-create a directory
mkdir dir
cd dir
touch file1 (creating 3 empty files)
touch file2
touch file3
mkdir subdir (creating a subdirectory)
step 2- open a nano editor
nano progname.sh
step 3- type the program
step 4- save the program
ctrl+x
press Enter
step 5- Execute the program
sh progname.sh
Output:$sh p8.sh
Enter the directory name
dir
List of files in the directory are
file1 file2 fil3
5. Write a shell script to display list of users currentlylogged
in.
Output:$sh p9.sh
List of users currently logged in is: Student
procedure:
step 1-create a file with content
cat>file1
hi
ctrl+d (to save the file)
cat>file3
hello
ctrl+d
cat>file2
from me
ctrl+d
create three files with content
step 2- open a nano editor
nano progname.sh
step 3- type the program
step 4- save the program
ctrl+x
press Enter
step 5- Execute the program
sh progname.sh
Output:$sh 10.sh
Enter first file name
f1
Enter second file name
f2
Enter third file name
f3
all three files exists
$cat new.txt
Hi hello from me