0% found this document useful (0 votes)
7 views3 pages

Linux Command Line Basics Guide

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

Linux Command Line Basics Guide

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Assignment 1

1. Find out the username/userid on your machine.


Ans: whoami

2. How to print the present working directory path?


Ans: pwd

3. How to go to a given directory (change the directory)?


Ans: cd directory_name

4. What is the command to view the information about a Linux/Unix command? Try
to know about the commands “ls”.
Ans: man ls

5. View the man page for command ‘id’ and find the options for printing all the
groups associated to a user with name.
Ans: man id

6. Create a file called “ctest”. Modify the access permissions as: “user - rwx”, “group -
rx”, and “others - nothing”.
Ans: touch ctest
chmod 750 ctest

7. Create a 3 level directory in your home directory as shown in the structure below
with single command.
mydir
|
Subdir1
|
Subdir2
Ans: mkdir -p /mydir/subdir1/subdir2

Now move the whole directory i.e. mydir to mydir1 and change the permissions as
owner-rwx, group-rx, others-x.
Ans: mv /mydir/mydir1
chmod 751 /mydir1
8 Create a text file using an editor with content as:
Welcome to ACTS courses.
First day is about Linux.
It’s a very commonly used OS.
Simple to understand and work.
Many os are based on LINUX.
All linux OS are open source and freely available.
a) From the file get the count of word “Linux” it must also include LINUX while
counting.
Ans: grep -io “linux” filename | wc -1

b) Display lines that exactly have the word ‘OS’.


Ans: grep -w “OS” filename

c) Display the line number where appears word ‘Linux’ irrespective of case
Ans: grep -in “linux” filename

9. Create sample files ending with “.txt” in your directory. Now run a command to
list all the files ending with “txt”.
Ans: touch [Link] [Link] [Link]
ls -a *.txt

10. Create a file “test” in the directory /home/cdac/mydir1/subdir1/test. Go to the


home directory and now find the file “test” executing the appropriate command.

Ans: touch /home/cdac/mydir1/subdir1/test/test


find . -name "test"

11. From home directory list all the files including the hidden files.

Ans: ls -al
12. Create a file with the following content:

You absolutely must run these exercises in the bash shell, or results will not be as
expected.

1. Display first 2 lines from the file.

Ans: head -n 2 filename

2. Display last 2 lines from the file.


Ans: tail -n 2 filename

3. Display exactly the tenth line in the file.


Ans: sed -n ‘10p’ filename

13. Create a set of 3 files and tar them to [Link]. Untar the tar file [Link] and
check the extracted files.
Ans: touch file1 file2 file3
tar -cvf [Link] file1 file2 file3
tar -xvf [Link]
ls

You might also like