- LEVEL - I
- List all the files and subdirectories of the directory /bin = cd bin ls bin
- List all the files including hidden files in your current directory = ls -a
- List all the files starting with letter 'r' in your current directory = ls r*
- List all the files having three characters in their names from your current directory. = ls ???
- List all the files with extension .doc in your current directory = ls *.doc
- List all the files having the first letter of their name within the range 'l' to , 's' from your current directory = ls [l-s]*
- Create a file text1 and read its input from keyboard = cat > text1
- Copy contents of file text1 to another file text2 = cp text1 text2
- Append the contents of file text2 to file text1 = cat >> text1 text2
- Count the number of files in the current directory = ls|wc -w
- Display the output of command ls -l to a file and on the output screen = ls -l|cat > text3 or ls -l|cat>>text2
- From file text1 print all lines starting from 10th line = tail +10 text1
- Find the number of users currently logged on to the system = who|wc -l
- Delete all the files with their names starting with "tmp" = rm tmp*
- LEVEL - II
- Create a file FILE2 with some text in it. Increase the no. of hard links to the file FILE2 to 3 and check the inode number and link count for those names = ls -l FILE2 Fl1 Fl2|cut -d " " -f3,10
- Using one single command, display the output of "who" and "pwd" commands = who;pwd
- Display today's date = echo "Today is $(date+%a) $(date+%d) $(date+%h) $ (date+%y) "
- Display the text message on monitor screen "We are done!!!" = echo "We are done!!!"
- Display the message on monitor screen "The long listing of my home dir ----- is -----" = 'the long listing of my home dir '; pwd; echo ' is ';ls -l
- LEVEL - III
- List only the directories in your current directory = find -type d|nl
- Display the name and count of the directories in the current directory = find -type d -print; find -type d|wc -l
- Find out whether the users with a pattern "itp9" in their names have logged in = who|cut -d " " -f1|fgrep itp9
- Find out whether a particular user "itp9" has logged in
- n=`who|cut -d " " -f1|fgrep ncs|wc-l` if test $n -ne 0
then
echo -e "no"
else
echo -e "yes"
fi - Assign a value "Black" to var1 and then display the following message on the terminal using this variable "Sirius Black is a true marauder."
- Set var1 Black
- echo "Sirius $var1 is a true marauder."
- Create the file employee.txt having ":" separated fields. The fields of record are : enumber, ename, eposition, esal, edoj, edept. Now answer the following.
- List all the employees along with a row number = cat employee.txt|cut -d ":" -f2|nl
- Sort the files as per names = cat employee.txt|sort -t ":" +1 -2
- List top three salaried employees = cat employee.txt|sort -r -t ":" +3 -4|head -3
- Rmove duplicate record from the file = cat employee.txt|unique
- List dept. no along with no. of emplooyees working in each dept = cat employee.txt|cut -d ":" -f6, 1|unique
- Sort the file in descending order of salary = cat employee.txt|sort -r -t ":" +3 -4
- LEVEL - IV
- Accept a file name and a number (x). Display x lines from the top of the file. Check if the file exists and is readable. The value of x should not exceed the total no. of lines in the files. Display suitable messages in case an error is encountered.
read file
if test -e file
then
echo 'File exists.'
if test -r file
echo 'File is readable'
echo 'Enter the line no.'
read n
x=`wc.. -l $file|cut -d " " -f1`
if test $n -lc $x
then
head -$n $file
else
echo 'The value exceeds total no of lines.'
fi
else
echo 'File is not readable'
fi
else
echo 'File doesn't exist'
fi