top ad

Monday, June 16, 2014

Linux Practical

Linux Lab Questions
Create a user Student and assign the password to P@ssw0rd.
Open terminal
Switch user to root
    # su
    password: <root password>
Synax: useradd <username>
passwd <username>
solution:
 # useradd Student
# passwd Student
new unix password : P@ssw0rd
retype new unix password : P@ssw0rd

Display the name of current working directory.
Syntax : pwd
# pwd
/home/student


List all the files and directories in /etc file system.
Syntax : ls <dir name>
# ls /etc

List all the hidden files and directories in your home directory.
Syntax : ls –a <dir name>
# ls –a  ~

Write a command that displays only directory in your home directory.
Syntax: ls –d */
# cd ~
# ls –d */
Write a command to see the list of recent command used.
Syntax: history
# history
1 cd ~
2 ls –d */
Create a directory 'test' on your home directory.
Syntax : mkdir <directory name>
# cd ~
# mkdir test
Create a file 'myFile' on your home directory using vi editor.
Syntax : vi <file name>
# vi myFile
File will create and open
Press i  for insert mode
Write following text
“this is test file”
Press “ESC” to switch command mode
Then press “shift + : ”
:w + Enter (to save)
:wq + Enter (to save and exit)
:wq! + Enter (to save and exit force fully)
:x + Enter (to save and exit)



Create a Symbolic Link of ‘myFile’ in the currenct directory.
Syntax : ln –s <source file path>  <destination file path>
# ln –s /home/student/myFile   softfile
Rename the ‘test’ directory to ‘NewTest’ directory.
Syntax : mv <old dir> <new dir>
# mv test NewTest

Delete the ‘myFile’ file from the home directory.
Syntax : rm <fille name>
# cd ~
# rm myFile
Write the symbolic representation (eg: rwx-wx—x) of each of the following numeric permissions.
644 ………………….. : rw-r--r--
755 …………………..
600 …………………..
000 …………………..
137 …………………..
124 …………………..
You have given a file with permissions 755, write a command that would change the permissions to r-xr—rwx ?
Syntas : chmod <permission> <file/dir>
# chmod 547 myFile
Change the permission of a file ‘myFile’ such that owner gets full permission, group member get read , write permission & other gets read only permission.
Syntas : chmod <permission> <file/dir>
# chmod 761 myFile

Change the permission of the file so that all category of the user gets full permission.
Syntax : chmod <permission> <file/dir>
# chmod 777 myFile

Write a command that search ‘passwd’ file in /etc directory.
Syntax :find <file name>
# cd /etc
# find passwd

Redirect the above search result to the ‘result.out’ file.
Syntax : find <search result> > <output file name>
# find passwd > result.out
# cat result.out


Redirect the error message to the ‘error.out’ file.

Write a command that counts words, lines, bytes and characters of the ‘result.out’ file.
syntax: wc <option>  <filename>
e.g.
# wc –w result.out  //words
# wc –l result.out  //lines
# wc –c result.out  //bytes
# wc –m result.out  //characters

Sort the ‘error.out’ file.

Sort the content of /etc/passwd in dictionary word and save the sorted result in another file named sorted_passwd.
Syntax: sort <filename> > <result filename>
# sort /etc/passwd   > sorted_password


Display the /etc/passwd line for any account that starts with the letter ‘a’.
Syntax: grep “search text/letter” <filename>
# grep “^a” /etc/passwd

Find all the configuration files inside  /etc directory that have .conf  as the file extension.
Syntax:find <folder path> *.extension
# find /etc/*.conf

Find all the empty files inside the current directory.
Syntax: find <directory name>  -type  <type> -empty
#find –type f -empty

Find all the files and directories that belongs to a user and that have 777 permission.


Display the number of lines in /etc/passwd file.
Write a shell script that displays “Hello World” .
Write a shell script that prompts for age and displays it to screen.
Write a shell script that guess root password. If password match displays the message “you are right”, other wise displays “try again”.
Write a shell script that calculate simple interest for 3 sets of P,N,R values.
Write a shell script that takes a command –line argument and reports on whether it is directry, a file, or something else.
Write a shell script that computes the gross salary of a employee according to the following.
a) if basic salary is <5000 then Allowance 10% of the basic salary.
b) if basic salary is >5000 then Allowance 25% of the basic salary.
The basic salary is entered interactively through the key board
Write a shell script that displays a list of all files in the current directory to which the user has read write and execute permissions .
Develop an interactive script that asks for a word and file name and then tells how many times that word occurred in the file.
Write a shell script which receives two files names as arguments. It should check whether the two file contents are same or not. If they are same then second file should be deleted.

0 comments to “Linux Practical”

Post a Comment

ShareThis

Total Pageviews