Shell Assign
Shell Assign
1.
Write a shell script to check the number of files and directories in current directory.
echo Enter a Dir Name:
read nm
If [-d $nm]; then
echo The no of files in the directory $nm : $(find $nm type f | wc l)
echo The no of Directoy in $nm : $(find $nm type d | wc l)
else
echo Enter dir name!
exit1
fi
Output :
exit
3. Write a shell script to check whether the given name is palindrome.
Echo Enter a String :
Read nm
If [ $nm == $rev nm]; then
Echo Given name is a Palindrome !
Else
Echo Not A Palindrome!!
Exit 1
Fi
4. write a shell script that accepts name from user and creates a directory by the path name, then creates a text
file in that directory and stores in it.
echo Enter a Dir.Name to create
read nm
mkdir -p $nm
echo Dir $nm created!
echo Enter a file name to create
read fnm
cd $nm
touch $fnm
echo File $fnm created in $nm !!
exit
Output:
12. Write a small shell script that adds an extension ".new" to all the files in a directory.?
echo Path
read p
cd $p
for i in *
do
mv $i ${i}.nnn
if [ $? eq 0 ] then
echo Renamed successfully!!
ls -l {$i}
fi
done
Output:
13.In shell scripting How to indentify that the previous command was run successfully?
By using $?