Linux Basic Commands Lab Exercise Solution



    1. Obtain the following results
      (i) To print the name of operating system
         cat /etc/*-release
      (ii) To print the login name
         whoami
     (iii) To print the host name
          hostname


2.    Find out the users who are currently logged in and find the particular user too.

Ans: who
       

3.    Display the calendar for
(i) Your Birthday month/year
(ii) Feb 2020
(iii) For the current month
(iv) Current Date Day Abbreviation , Month Abbreviation along with year


(i) cal 07 1999
           
             (ii) cal 02 2020

             (iii) cal

             (iv) date "+ %d %a %B %Y"


4.     Display the time in 12-Hour and 24 Hour Notations.
date “+%r” (12 hour) date “+ %R” (24 hour)
             
5.    Display the Current Date and Current Time.
date "+%d %r"
         
6.    Display the message “GOOD MORNING”+ YOUR NAME AND STUDENT ID as a string in enlarged
characters.

echo "GOOD MORNING  Shawon 01051750"
     
7.    Display the name of your home directory.
echo “$HOME”
      
8.    Create a directory SAMPLE_(YOUR STUDENT ID) under your home directory.

mkdir SAMPLE_01051750
         
9.    Create a sub-directory by name TRIAL_(YOUR STUDENT ID) under SAMPLE_(YOUR STUDENT ID).

mkdir SAMPLE_01051750/TRIAL_01051750
         
                      10.   Change to SAMPLE_(YOUR STUDENT ID).
         cd ..
         
11.     Change to your home directory.
        cd ..
         
   12.     Change from home directory to TRIAL_(YOUR STUDENT ID)  by using absolute and relative pathname.

       cd SAMPLE_01051750/TRIAL_01051750
        
   13.      Remove directory TRIAL_(YOUR STUDENT ID).

            rm -r TRIAL_01051750
          
  14.        Create a directory TEST_(YOUR STUDENT ID) using absolute pathname.

        mkdir TEST_01051750
           
  15.     Using a single command change from current directory to home directory.

        cd ~
          
16.     Remove a directory using absolute pathname.

       rm -r TEST_01051750/app
         
      17.   Create files myfile_(YOUR STUDENT ID) and yourfile_(YOUR STUDENT ID) under Present Working
Directory.

        touch myfile_01051750 yourfile_0101750
           
    18.     Display the files myfile_(YOUR STUDENT ID) and   yourfile_(YOUR STUDENT ID).
     
     vi myfile_01051750
     vi yourfile_0101750

   19.           Append more lines in the myfile_(YOUR STUDENT ID) and yourfile_(YOUR STUDENT ID) files.

           echo "Appended Line " >>myfile_01051750
           echo "Appended Line " >>yourfile_01051750



     20.       How will you create a hidden file?

             touch .myfile_hidden
          
   21.      Copy myfile_(YOUR STUDENT ID) file to emp_(YOUR STUDENT ID).
      cp myfile_01051750 emp_01051750
         
  22.        Write the command to create alias name for a file.
      alias mf="myfile_01051750"
         
  23.      Move yourfile_(YOUR STUDENT ID) file to dept_(YOUR STUDENT ID).
        mv yourfile_01051750 dept_01051750
         
  24.       Copy emp_(YOUR STUDENT ID) file and dept_(YOUR STUDENT ID) file to TRIAL_(YOUR STUDENT ID)
Directory

       cp emp_01051750 dept_01051750 TRIAL_01051750
         
25.        compare a file with itself.
       cmp file1 file2

26.        Compare myfile_(YOUR STUDENT ID) file and emp_(YOUR STUDENT ID) file.

       cmp myfile_01051750 emp_01051750

27.        Append two more lines in emp_(YOUR STUDENT ID) file existing in TRIAL_(YOUR STUDENT ID) directory
      echo –e “line 1\n line2” >> emp_01051750
28.        Create and Compare employee_(YOUR STUDENT ID) file with emp_(YOUR STUDENT ID) file in TRIAL_(YOUR STUDENT ID) directory.

       touch employee_01051750  cmp emp_01051750 
         employee_01051750      

29.        Find the difference between the above files.
      diff emp_01051750 employee_01051750

30.         Remove the files in the TRIAL_(YOUR STUDENT ID) directory.
        rm –r emp_01051750  rm –r employee_01051750
31.        Can you remove a directory with files by using a single command?  How, show it.
       rm –r *
          

Download Coding Interview Book and Get More Tutorials for Coding and Interview Solution: Click Here

Download System Design Interview Book and Get More Tutorials and Interview Solution: Click Here

Do you need more Guidance or Help? Then Book 1:1 Quick Call with Me: Click Here

Share on Google Plus

About Ashadullah Shawon

I am Ashadullah Shawon. I am a Software Engineer. I studied Computer Science and Engineering (CSE) at RUET. I Like To Share Knowledge. Learn More: Click Here
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment