You are on page 1of 10

Course: Unix Shell Scripting for Beginners

User Assignment 2 - Working with Files and Directories

1. Create a directory called iiht and inside it creates three sub directories namely, trainers,
trainees and employees.
Ans : Use commands as follows,
mkdir iiht
cd iiht
pwd
mkdir namely
mkdir employers
mkdir trainees and employees
2. Move to employee’s directory and list all the process, then get back to the home directory.

Ans : Use following commands,


cd iiht - To move to iiht directory
cd employees - To move to employee’s directory
ps - To list all processes
cd - To get back to home directory
3. Find the current working directory.

And : Use ‘pwd’ command to find current working directory.


4. Display all files which has .txt extension and display all the files whose name starts with ‘n’

Ans : Use ‘find -name “.txt” -print’ command to display .txt file and
Use ‘ls -d /etc/ [n]* command to files whose name start with ‘n’
5. List all files which are having first letter as A and last character as a in between any 4
characters.

Ans : Use ‘find -name “*[A!!!!a]” -print’ command to display all files which are having
first letter as A and last character as a in between any 4 characters.
6. List all files which does not have any numeric values in their file names.

Ans : Use ‘find -name “*[!(0-9)]” -print’ command to list all files which does not have
any numeric values in their file names.
7. Display the contents of a specified file in the directory.

Ans : Use ‘ ls / iiht’ command to display the contents of a specified file in the directory.
8. Create a file called first.txt and insert some content into and copy the contents to second.txt
file.

Ans : Use ‘cat > first.txt’ command to create a new file.


Use ‘cp first.txt second.txt’ command to copy contents to second .txt.
9. Move the contents from second.txt to final.txt

Ans : Use ‘mv second.txt final.txt’ command to move the contents from second.txt to
final.txt.

You might also like