100% found this document useful (1 vote)
808 views2 pages

Unix Qs

The document contains instructions for various Linux commands organized into multiple levels. Level I includes commands to list files and directories, count files, and delete files. Level II demonstrates linking files, running multiple commands, and displaying messages. Level III finds directories, users who logged in, and creates a variable. Level IV accepts user input for a file name and line number, then displays or checks the file.

Uploaded by

taurus8055
Copyright
© Attribution Non-Commercial (BY-NC)
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
100% found this document useful (1 vote)
808 views2 pages

Unix Qs

The document contains instructions for various Linux commands organized into multiple levels. Level I includes commands to list files and directories, count files, and delete files. Level II demonstrates linking files, running multiple commands, and displaying messages. Level III finds directories, users who logged in, and creates a variable. Level IV accepts user input for a file name and line number, then displays or checks the file.

Uploaded by

taurus8055
Copyright
© Attribution Non-Commercial (BY-NC)
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/ 2

LEVEL - I

1. 2. 3. 4.

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 ??? 5. List all the files with extension .doc in your current directory = ls *.doc 6. List all the files having the first letter of their name within the range 'l' to , 's' from your current directory = ls [l-s]* 7. Create a file text1 and read its input from keyboard = cat > text1 8. Copy contents of file text1 to another file text2 = cp text1 text2 9. Append the contents of file text2 to file text1 = cat >> text1 text2 10. Count the number of files in the current directory = ls|wc -w 11. Display the output of command ls -l to a file and on the output screen = ls -l|cat > text3 or ls -l|cat>>text2 12. From file text1 print all lines starting from 10th line = tail +10 text1 13. Find the number of users currently logged on to the system = who|wc -l 14. Delete all the files with their names starting with "tmp" = rm tmp*

LEVEL - II

1. 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 2. Using one single command, display the output of "who" and "pwd" commands =who;pwd 3. Display today's date = echo "Today is $(date+%a) $(date+%d) $(date+%h) $ (date+%y) " 4. Display the text message on monitor screen "We are done!!!" = echo "We are done!!!" 5. 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

1. List only the directories in your current directory = find -type d|nl 2. Display the name and count of the directories in the current directory = find -type d print; find -type d|wc -l 3. Find out whether the users with a pattern "itp9" in their names have logged in =who|cut d " " -f1|fgrep itp9 4. Find out whether a particular user "itp9" has logged in o n=`who|cut -d " " -f1|fgrep ncs|wc-l` if test $n -ne 0 then echo -e "no" else echo -e "yes" fi 5. Assign a value "Black" to var1 and then display the following message on the terminal using this variable "Sirius Black is a true marauder." o Set var1 Black

echo "Sirius $var1 is a true marauder." 6. Create the file employee.txt having ":" separated fields. The fields of record are : enumber, ename, eposition, esal, edoj, edept. Now answer the following.

1. List all the employees along with a row number = cat employee.txt|cut -d ":" f2|nl 2. Sort the files as per names = cat employee.txt|sort -t ":" +1 -2 3. List top three salaried employees = cat employee.txt|sort -r -t ":" +3 -4|head -3 4. Rmove duplicate record from the file = cat employee.txt|unique 5. List dept. no along with no. of emplooyees working in each dept =cat employee.txt|cut -d ":" -f6, 1|unique 6. Sort the file in descending order of salary = cat employee.txt|sort -r -t ":" +3 -4

LEVEL - IV

1. 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. echo 'Enter the file name' read file if test -e file then echo 'File exists.' if test -r file '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

echo

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy