KEMBAR78
02 134172 159 7036657417 25062020 100054pm | PDF | Filename | Operating System Technology
0% found this document useful (0 votes)
34 views5 pages

02 134172 159 7036657417 25062020 100054pm

Uploaded by

Mehdi Nisar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views5 pages

02 134172 159 7036657417 25062020 100054pm

Uploaded by

Mehdi Nisar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

BAHRIA UNIVERSITY (KARACHI CAMPUS)

Assignment –SPRING SEMESTER – 2020


(operating system: CSL-320)

Class BS (CS) 6A/B/ BS(IT)-5A (Evening)/Morning


Lab Engineer: Muslim Ahmed Date: 26 june 2020;
Max Marks: 15

Student Name: Syed Muhammad Mehdi Enrolment : 02-134172-159

Note: All questions carry equal marks.


In addition to upload the solution on LMS, please also email it to course instructor.
In order to avoid any run time electricity and internet unavailability situation, it is suggested that keep your
laptop charged. Also activate 3G/4G connection as an alternative of Wifi/internet option to upload your
solution.

Q1: Give LINUX/UNIX commands

To make a backup of current directory

LINUX:
$ cp -r directory_1 /home/DIRECTORY NAME
UNIX:
cd dirname

__________________________________________________________

To copy all environmental variables in a file which is in /etc directory

LINUX:
$ printenv //displays all the global ENVs
or
$ set //display all the ENVs (global as well as local)
or
$ env //display all the global ENVs

UNIX:

$ env | sort | head -10

DBUS_SESSION_BUS_ADDRESS=UNIX: path=/run/user/1000/bus

Page 1 of 5
HISTCONTROL=ignorespace

HISTFILE=/home/shs/. history

HISTIGNORE=history:pwd: man *:ls:ls *

HISTSIZE=100

HISTTIMEFORMAT=%h %d %H:%M:%S>

HOME=/home/shs

LANG=en_US.UTF-8

LESSCLOSE=/usr/bin/lesspipe %s %s

LESSOPEN=| /usr/bin/lesspipe %s

_____________________________________________________________

To show the current user, system and working directory name

1. Wcommand or $USERNAME to show the current user

2. $pwd use for current working directory

3. $cat /etc/os-release for check the system using

______________________________________________________________

To print a list of running processes

LINUX:

1. top command: Display and update sorted information about LINUX processes.
2. atop command: Advanced System & Process Monitor for LINUX.
3. htop command: Interactive process viewer in LINUX.
4. pgrep command: Look up or signal processes based on name and other attributes.
5. pstree command: Display a tree of processes

UNIX:

Ps-aux
Sudo ps-a
_______________________________________________________

To give a list of all files containing word “bin”

To give a list of all files containing word “bin”


LINUX:
$ grep "bin" /home/tom/*.txt

Page 2 of 5
UNIX:
grep "bin" filename
grep root /etc/*

_____________________________________________________________.

Q2.: Write a script to search a specific file in current directory and then count all
characters/Words/Lines in the files

Answer
file=$1
v=0

if [ $# -ne 1]
then
echo "$0 filename"
exit 1
fi
if [ ! -f $file ]
then
echo "$file not a file"
exit 2
fi

# read vowels
exec 3<&0
while read -n 1 c
do
l="$(echo $c | tr '[A-Z]' '[a-z]')"
[ "$l" == "a" -o "$l" == "e" -o "$l" == "i" -o "$l" == "o" -o "$l" == "u”] && ((v++ )) || :
done < $file

echo "Vowels: $v"


echo "Characters: $(cat $file | wc -c)"
echo "Blank lines: $(grep -c '^$' $file)"
echo "Lines: $(cat $file|wc -l)"

Q:3 Write a program or script to

Display all Text files.


Answer:
!/bin/bash

Page 3 of 5
files=$(ls);
for file in $files
do
# extension=$($file | awk -F. ‘{print $NF}');
if [ $file | awk -F. “{print $NF}" = txt ]
then
echo $file;
else
echo "Not a .txt file";
fi;
done;

Count all executable files.


Answer:
LINUX:

#! /bin/bash
To="home/magie/d2"
cd "$To"
find. -type f -perm 755

find. -type f -perm 755 | wc -l

UNIX:
USER=`whoami`
for GROUP in `groups`
do
GROUPLIST=${GROUPLIST}\\\|${GROUP}
done
READ=0
WRITE=0
EXEC=0
for FILE in `ls`
do
if ls -l $FILE | grep $USER
then
if ls -l $FILE | cut -c2 | grep r
then
READ=`expr $READ + 1`
fi
elif ls -l $FILE | egrep $GROUPLIST
then

else
fi
done

Page 4 of 5
check the type of a file.
Answer:
for file in *; do
case $(file --mime-type -b "$file") in
image/*g) ... ;;
text/plain) ... ;;
application/xml) ...;
application/zip) ...;
*) ... ;;
esac
done

#! /bin/bash

for file in "$PATH_TO_SOMEWHERE"; do


if [ -d $file]
then
# do something directory-ish
else
if [ "$file" == "*.txt”] # this is the snag
then
# do something txt-ish
fi
fi
done;

count all directories in the current directory.


Answer:
$ find. vim/ -maxdepth 1 -type d
. vim/
. vim/indent
. vim/colors
. vim/doc
. vim/after
. vim/autoload
. vim/compiler
. vim/plugin
. vim/syntax
. vim/ftplugin
. vim/bundle
. vim/ftdetect

Page 5 of 5

You might also like