Solved Questions of Unix Ch2 and Ch3
Solved Questions of Unix Ch2 and Ch3
Figure 1
$cd /
a. Write a command to display all files under DATA directory, whose name contains three
character long.
$ls DATA/???
b. Write a command to display the data from all the files under directory Test, whose
name is five character long with ali in middle.
$cat Test/?ali?
c. Write a command to remove all files in current directory, whose name is starting with
de.
$rm de*
d. Write a command to copy all files, directory, subdirectories from /Test into /Data,
whose name is ending with deo.
$cp -R /Test/*deo /Data
e. Write a command to display all the files of /Demo directory, whose name is ending
with a character in between a to m.
$ls /Demo/*[a-m]
f. Write a command to display directory DATA contents recursively, whose name is
beginning with a letter from 'm' to 'k' and ends in a letter from 'c' to 'l'.
$ls DATA/[m-k]*[c-l]
g. Write a command to delete all the files in the parent of parent directory, whose name is 6
character long, first character in between h to m and ending with a number 6 or 8.
$rm ../../[h-m]????[6,8]
h. Write a command to display the data from all the files, whose name is beginning in between a
to c and ending with a number 6 or 9.
$cat [a-c]*[6,9]
a. Write a command to copy recursively all files, directory, subdirectories under theory
directory with new name "newtheory" to unix.
$cp -R /Student/theory /Student/theory/unix/newtheory
b. Write a command to list all files, including hidden files under unix directory.
$ls -a /Student/theory/unix
e. Write a command to display the data from dsp.doc page by page with scroll the data
by line by line.
$less /Student/theory/dsp.doc
Q2. a. Write a command to create a symbolic link EEE of the directory ENG.
b. Write a command to delete all the files in the parent directory, whose name contain 5
characters long, first character in between a to d and ending with 4 to 8.
$rm ../[a-d]???[4-8]
c. Write a command to display the data from all the files, whose name is beginning with “a” or
“c”.
$cat [a,c]*
d. Write a command to remove all empty directories, whose name is ending with exam.
$rmdir *exam
$mkdir /home/test
Q 3. Write commands of following directory structure.
CHAPTER – 3 Examples
Chmod Command Examples
1. Write a command to change the permission of a file named is
private.txt.
- User/owner can read and write the file only. (using octal mode)
$chmod 600 private.txt
3. Write a command to set the permission for all the files that is ending
in .txt
• user can read and write, group can execute only, other can
read. (Using octal mode)
$chmod 614 *.txt
4. Write a command to modify the permission for all the files, directory,
subdirectories under demo directory. (Using octal mode)
- User can read and execute it.
- Group and others can read and write it.
$chmod -R 566 demo
5. Write a command to add read and write permission for all the users
for file, directory, and subdirectory inside directory civil. (symbolic
mode)
$chmod -R a+rw civil
6. Assume you have a file named hello, do the following based on
commands as shown below.
• Add the read and write permission for the others.
• Remove executes permission from member of your group.
• Set(assign) all three permissions for the owner.
$chmod u=rwx, g-x, o+rw hello
7. Write a command to set(assign) the permission to a file named is
ali.txt.(symbolic mode)
- User can read and write the file
- Group can execute the file.
- Others can read and execute the file
$chmod u=rw,g=x,o=rx ali.txt $chmod 615 ali.txt
8. Let’s say you are the owner of a file named myfile.
a. For user can add read, write permission,
b. members of your group assign the read and execute
permission,
c. for others remove the execute permission. (symbolic mode)
$chmod u+rw,g=rx,o-x myfile
Q1. Write a command to display the first 3 line of a file named is ali.
$head -3 ali
Q2. Write a command to display the last 4 line of a file named is ali.
$tail -4 ali
Q3. Write a command to display the 3rd and 4th line from the beginning of file ali.
Q4. Write a command to display the 5th and 6th line from the end of file ali.
Examples of wc command
Q10. Write a command print the number of lines in a file named is demo.
$wc -l demo
Q11. Write a command print the number of words in a file named is demo.
$wc -w demo
Q12. Write a command print the number of bytes in a file named is demo.
$wc -c demo
Q13. Write a command print the number of characters in a file named is
demo.
$wc -m demo
Q14. Write a command print the number of characters & lines in a file
named is demo.
$wc -ml demo