0% found this document useful (0 votes)
32 views4 pages

Linux Assignment 1

The document discusses various Linux commands and their usage. It provides the syntax for commands like pwd, ls, mkdir, cd, cat, touch, echo, diff, rmdir, rm, head, cp, mv, and man. It also explains the differences between commands like mv vs cp, rm vs rmdir, and mkdir vs mkdir -p.

Uploaded by

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

Linux Assignment 1

The document discusses various Linux commands and their usage. It provides the syntax for commands like pwd, ls, mkdir, cd, cat, touch, echo, diff, rmdir, rm, head, cp, mv, and man. It also explains the differences between commands like mv vs cp, rm vs rmdir, and mkdir vs mkdir -p.

Uploaded by

thanuja siva
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Assignment 1- Commands Utilities

Name: Aketi Thanuja Batch : Sep 8

1.Which command is used to know the current working directory?


Ans: pwd command is used to know the current working directory. It gives
us the absolute path, which means the path that starts from the root. 
Syntax: $ pwd

2.How would you find out its contents?


Ans: ls command is used to find the contents of a file or directory.
Syntax: $ ls filename

3.Identify the commands with inputs to do the following


a.create a directory d1
Syntax: $ mkdir dir name(d1)
b.create a subdirectory d2 in d1
Syntax: $ mkdir -p ./d1/d2
c.change to directory d2
Syntax: $ cd d2
d.create an empty file “f1.txt”
Syntax: 1. $ cat >>f1.txt
2. $ touch f1.txt
3. $ echo >f1.txt
e.display the contents of “f1.txt”
Syntax: $ cat f1.txt
f.view the contents of d1 from current directory d2
Syntax: $diff -r d1 d2
4.Use the ls command with its options. How will you identify directories
from the listing?
Ans: 1. $ ls *: This command will list the content of all subdirectories.
2. $ ls -l : Tells the size of the file along with its permissions,
modification etc.
3. $ ls -a: To view hidden files
4. $ ls -f: To identify directories and executable files.
5. $ ls -r: List files in reverse order
To identify the directories from the listing we can use
a.$ ls -l
b.$ ls -lh
c. $ ls -l|grep ‘^d’

5.Use ls to do the following


a.List files with single character names.
Ans: Syntax: $ echo ?
b.List hidden files also. [ Note : Hidden files are files having name
started with a “.” ]
Ans: Syntax: $ ls -a
c.Suppose there are files tb1.1, tb2.1, tb3.1, ….tb10.1. Write command
to list all the files [Hint: use wild card characters]
Ans: Syntax: $ ls *

6.Write the command to list all files in descending order of their size.
Ans: Syntax: $ ls -S
7.Suppose there are files temp1, temp2, temp3. Write command to
remove the files without listing them explicitly
Ans: Syntax: 1. $ rmdir temp1 temp2 temp3 (To delete empty directories)
2. $ rm temp1 temp2 temp3

8.Which command is used to list top few lines in the file?


Ans: Head command is used to list the top few lines of a file
Syntax: $ head filename

9.Create a directory “testdir”


Ans: Syntax: $ mkdir testdir

10.Use cp command to do the following


a.Copy the file tb1.1 (created above) in the same directory.
Ans: Syntax: $ cp tb1.1 testdir
b.Write a command to copy all the files i.e tb1.1,tb2.1,tb3.1,…..tb10.1 in
a new directory –“new”
Ans: Syntax: $ cp tb1.1 tb1.1 tb2.1 tb3.1 tb4.1 tb5.1 tb6.1 tb7.1 tb8.1 tb9.1
tb10.1 new
c.Create a subdirectory in new in named“new1”.
Ans: Syntax: $ mkdir -p ./new/new1
d.Write a command to copy selectively only tb2.1, tb6.1, tb7.1 and
tb10.1 in the directory new1.
Ans: Syntax: $ cp tb2.1 tb6.1 tb10.1 new1
e.Write a command to copy the entire directory “new” to a directory
“newprogs”. [Note : use the –R option of “cp” command ]
Ans: Syntax: $ cp -R new newprogs

11.Find out the difference between


a.“mv” & “cp”
Ans: mv- Moving files or directories from one location to the other
cp- Copying files into a directory or copying directories from one
location to the another.
b.“rm”, “rmdir”
Ans: rm- It is used to delete files or directory
rmdir- It is used to delete a directory. But it can only be used to delete
an empty directory
c.“mkdir” and “mkdir -p”
Ans: mkdir- It is used to create a directory
mkdir -p : Making multiple directories inside a directory

12.Use a single command rmdir once to remove “testdir” and all its sub
directories and files created above.
Ans: Syntax: $ rm -R testdir

13.Which command is used to get the manual information of a


command?
Ans: man command
Syntax: $ man commandname

14.If you are not able to change to a directory what could be the likely
cause?
Ans: Because the user did not the give the permission to write and execute.
The directory is given the permission to read only.

15.Explain the differences among the following commands:


a.cd / - It is used to go to the absolute path of the directory

b.cd .. - To move one level from the current directory

c.cd - Used to change the path of the directory

d.cd ../.. - To move two levels up from the current directory

You might also like