Homework Questions and Answers #1

Q1.
a) List all the files and sub directories of the directory /bin.

Ans: The command for listing all the files and sub directories of the directory /bin is “cd bin | ls –l”

b) List all the files including hidden files in your current directory.

Ans: The command for including all the hidden files in our current directory is “ls -a”.

c) List all the files starting with letter ‘r’ in your current directory.

Ans: The command for listing all the files starting with letter ‘r’ in your current directory is “ls –al r*”

d) List all the files having three characters in their names, from your current directory.

Ans: The file having three characters in their names from tha current directory is “ls *abc*”.

e) List all the files with extension .doc in your current directory.

Ans: The command for listing all the files with extension .doc in your current directory is “ls *.doc”.

Q2.
a) Using one single command, display the output of “who” and “pwd” commands.

Ans: The command that display the output of ‘who’ and ‘pwd’ commands together is “who ; pwd”.

b) Display the system date in following format: Today is Friday, 17 May 12

Ans: echo “Today is” date

c) Display the following text message on the monitor screen.  Deposited $100 to you account.

Ans:  echo “Deposited \$100 to you account”.

d) Display the following message on the monitor. 
The long listing of my home dir …………   is ………… 
(Hint: Use ls – l and pwd commands)

Ans: echo “The long listing of my home dir ‘pwd’ is ‘ls –l’ ”.

Q3. 
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 number of lines in the files. Display suitable messages in case an error is encountered.

Ans: echo “enter the file name that we have to display”
        read a
        if [ -e $a ]
        then
        echo “enter the nos. of lines”
        read b
        x = ‘wc –l $a’
        if [ $b –le $x ]
        then
        head -$b $a
        else
        echo “entered line is not found”
        fi 
        else
        echo “the file does not exist”
        fi

Linux Tips

See Also
Useful Linux Command Line Q&A

Have a Linux Problem
Linux Forum - Do you have a Linux Question?

Linux Books
Linux Certification, System Administration, Programming, Networking Books

Linux Home: Linux System Administration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.
The site www.gotothings.com is in no way affiliated with or endorsed by any company listed at this site.
Any unauthorised copying or mirroring is prohibited.