0% found this document useful (0 votes)
82 views8 pages

Foss Commands

The document contains questions and answers related to Linux commands. It demonstrates how to use commands like pwd, ls, la, mkdir, cd, cat, sort, head, tail, date, find, grep, tr, cut, cp and mv to navigate directories, view, edit, search and manage files and folders in Linux. Key commands covered include navigating and viewing directory contents, creating and modifying files, permissions management, string search and manipulation, file sorting and filtering.

Uploaded by

Chandramathi M
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)
82 views8 pages

Foss Commands

The document contains questions and answers related to Linux commands. It demonstrates how to use commands like pwd, ls, la, mkdir, cd, cat, sort, head, tail, date, find, grep, tr, cut, cp and mv to navigate directories, view, edit, search and manage files and folders in Linux. Key commands covered include navigating and viewing directory contents, creating and modifying files, permissions management, string search and manipulation, file sorting and filtering.

Uploaded by

Chandramathi M
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/ 8

Qn 1.

To display the present working Directory


liji@liji-VirtualBox:~$ pwd
Ans: /home/liji
Qn2.To display files and folders in the current working directory
liji@liji-VirtualBox:~$ ls
Ans:Desktop Documents Downloads Music Pictures Public Templates Videos
Qn3.To display files and folders in the current working directory with hidden files
liji@liji-VirtualBox:~$ la -a
Ans:. .bashrc Desktop .gnupg Pictures .ssh
.. .cache Documents .local .profile Templates
.bash_logout .config Downloads Music Public Videos
Qn4.To display files and folders in the current working directory with access permissions
liji@liji-VirtualBox:~$ ls -al
Ans: total 72
-xr-x 15 liji liji 4096 Aug 28 00:04 .
drwxr-xr-x 3 root root 4096 Aug 27 23:47 ..
-rw-r--r-- 1 liji liji 220 Aug 27 23:47 .bash_logout
-rw-r--r-- 1 liji liji 3771 Aug 27 23:47 .bashrc
drwxr-xr-x 10 liji liji 4096 Aug 28 00:04 .cache
drwx------ 12 liji liji 4096 Aug 28 00:05 .config
drwxr-xr-x 2 liji liji 4096 Aug 28 00:03 Desktop
drwxr-xr-x 2 liji liji 4096 Aug 28 00:03 Documents
drwxr-xr-x 2 liji liji 4096 Aug 28 00:03 Downloads
drwx------ 3 liji liji 4096 Aug 28 08:59 .gnupg
drwxr-xr-x 3 liji liji 4096 Aug 28 00:02 .local
drwxr-xr-x 2 liji liji 4096 Aug 28 00:03 Music
drwxr-xr-x 2 liji liji 4096 Aug 28 00:03 Pictures
- rw-r--r-- 1 liji liji 807 Aug 27 23:47 .profile
drwxr-xr-x 2 liji liji 4096 Aug 28 00:03 Public
drwx------ 2 liji liji 4096 Aug 28 00:04 .ssh
drwxr-xr-x 2 liji liji 4096 Aug 28 00:03 Templates
drwxr-xr-x 2 liji liji 4096 Aug 28 00:03 Videos
Qn5.To create a new directory SDE
liji@liji-VirtualBox:~$ mkdir SDE
Qn6.To change to newly created directory SDE
liji@liji-VirtualBox:~$ cd SDE
Qn7.To display current working directory
liji@liji-VirtualBox:~/SDE$ pwd
Ans: /home/liji/SDE
Qn 8.To create a file BCA in directory SDE
liji@liji-VirtualBox:~/SDE$ cat> BCA
Basil
Aswathy
Ancy
Gayathri
Joel
Shine
Qn 9.To display file BCA
liji@liji-VirtualBox:~/SDE$ cat BCA
Ans: Basil
Aswathy
Ancy
Gayathri
Joel
Shine
Qn 10.To create a file BCA in directory SDE
liji@liji-VirtualBox:~/SDE$ cat >BSC
Vishnu
jaes
anju
ananthu
rafeek
Qn 11.Display the contents of file BSC

liji@liji-VirtualBox:~/SDE$ cat BSC


Ans: Vishnu
jaes
anju
ananthu
rafeek

Qn.12.To append content of file BSC to the file BCA


liji@liji-VirtualBox:~/SDE$ cat >>BCA BSC
Qn 13. To display the content of file BCA
liji@liji-VirtualBox:~/SDE$ cat BCA
Ans: Basil
Aswathy
Ancy
Gayathri
Joel
Shine
Vishnu
jaes
anju
ananthu
rafeek
Qn 14. To display the content of file BSC
liji@liji-VirtualBox:~/SDE$ cat BSC
Ans: Vishnu
jaes
anju
ananthu
rafeek
Qn 15..To display the content of the directory SDE
liji@liji-VirtualBox:~/SDE$ ls
Ans: BCA BSC
Qn 16:To display access permissions of files in the directory SDE
liji@liji-VirtualBox:~/SDE$ ls -al
Ans: total 16
drwxrwxr-x 2 liji liji 4096 Aug 28 09:15 .
drwxr-xr-x 16 liji liji 4096 Aug 28 09:11 ..
-rw-rw-r-- 1 liji liji 71 Aug 28 09:19 BCA
-rw-rw-r-- 1 liji liji 32 Aug 28 09:18 BSC
Qn 17.To give execute permission to the file
liji@liji-VirtualBox:~/SDE$ chmod +x filename
Qn 18.To give all access permission to a file
liji@liji-VirtualBox:~/SDE$ chmod 777 filename
Qn 19.To sort contents of file BCA in ascending order
liji@liji-VirtualBox:~/SDE$ sort BCA
Ans: ananthu
Ancy
anju
Aswathy
Basil
Gayathri
jaes
Joel
rafeek
Shine
Vishnu
Qn 20.To sort contents of file BSC in ascending order
liji@liji-VirtualBox:~/SDE$ sort BSC
Ans: ananthu
anju
jaes
rafeek
Vishnu
Qn 21.To sort contents of file BCA in descending order
liji@liji-VirtualBox:~/SDE$ sort -r BCA
Ans: Vishnu
Shine
rafeek
Joel
jaes
Gayathri
Basil
Aswathy
anju
Ancy
ananthu
Qn 23.To display the first ten lines of the file BCA

liji@liji-VirtualBox:~/SDE$ head BCA


Ans: Basil
Aswathy
Ancy
Gayathri
Joel
Shine
Vishnu
jaes
anju
ananthu
Qn 24.To display the first 5 lines of the file BCA
liji@liji-VirtualBox:~/SDE$ head -5 BCA
Ans: Basil
Aswathy
Ancy
Gayathri
Joel
Qn 25.To display the last 10 lines of the file BCA
liji@liji-VirtualBox:~/SDE$ tail BCA
Ans: Aswathy
Ancy
Gayathri
Joel
Shine
Vishnu
jaes
anju
ananthu
rafeek
Qn 26.To display the last 3 lines of the file BCA
liji@liji-VirtualBox:~/SDE$ tail -3 BCA
Ans:anju
ananthu
rafeek

Qn 27.To sort and display the last 5 lines of the file BCA(to join two commands we use pipe
symbol ‘|’)
liji@liji-VirtualBox:~/SDE$ sort BCA| tail -5
Ans: jaes
Joel
rafeek
Shine
Vishnu
Qn 28.To display Calendar

liji@liji-VirtualBox:~/SDE$ cal
Ans:
August 2020
Su Mo Tu We Th Fr Sa
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31
Qn 29To display Calendar of the year 2020
liji@liji-VirtualBox:~/SDE$ cal 2020
Ans:

2020
January February March
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 1 1 2 3 4 5 6 7
5 6 7 8 9 10 11 2 3 4 5 6 7 8 8 9 10 11 12 13 14
12 13 14 15 16 17 18 9 10 11 12 13 14 15 15 16 17 18 19 20 21
19 20 21 22 23 24 25 16 17 18 19 20 21 22 22 23 24 25 26 27 28
26 27 28 29 30 31 23 24 25 26 27 28 29 29 30 31

April May June


Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 1 2 1 2 3 4 5 6
5 6 7 8 9 10 11 3 4 5 6 7 8 9 7 8 9 10 11 12 13
12 13 14 15 16 17 18 10 11 12 13 14 15 16 14 15 16 17 18 19 20
19 20 21 22 23 24 25 17 18 19 20 21 22 23 21 22 23 24 25 26 27
26 27 28 29 30 24 25 26 27 28 29 30 28 29 30
31

July August September


Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 1 1 2 3 4 5
5 6 7 8 9 10 11 2 3 4 5 6 7 8 6 7 8 9 10 11 12
12 13 14 15 16 17 18 9 10 11 12 13 14 15 13 14 15 16 17 18 19
19 20 21 22 23 24 25 16 17 18 19 20 21 22 20 21 22 23 24 25 26
26 27 28 29 30 31 23 24 25 26 27 28 29 27 28 29 30
30 31

October November December


Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 1 2 3 4 5 6 7 1 2 3 4 5
4 5 6 7 8 9 10 8 9 10 11 12 13 14 6 7 8 9 10 11 12
11 12 13 14 15 16 17 15 16 17 18 19 20 21 13 14 15 16 17 18 19
18 19 20 21 22 23 24 22 23 24 25 26 27 28 20 21 22 23 24 25 26
25 26 27 28 29 30 31 29 30 27 28 29 30 31
Qn 31.To display date
liji@liji-VirtualBox:~/SDE$ date
Friday 28 August 2020 09:33:13 AM IST
Qn 32.To locate a file BCA in a directory SDE
liji@liji-VirtualBox:~/SDE$ find BCA
Ans: BCA
Qn 33. To locate a directory SDE
liji@liji-VirtualBox:~/SDE$ cd
liji@liji-VirtualBox:~$ find SDE
Ans: SDE
SDE/BSC
SDE/BCA
Qn 34. To search a word Aswathy in the file BCA
liji@liji-VirtualBox:~/SDE$ grep Aswathy BCA
Ans: Aswathy
Qn 35. To count number of lines,words,characters in a file BCA
liji@liji-VirtualBox:~/SDE$ wc -l -w -c BCA
Ans: 11 11 71 BCA
Qn.36.To replace all ‘A’ in a file with letter ‘e’ in file BCA

liji@liji-VirtualBox:~/SDE$ tr 'A' 'e' <BCA


Ans: Basil
eswathy
ency
Gayathri
Joel
Shine
Vishnu
jaes
anju
ananthu
rafeek
Qn 37.To count the number of lines,words ,characters in a file and redirect its ouput to a file
students
liji@liji-VirtualBox:~/SDE$ wc -l -w -c BCA >students

Qn 38.To display the content of file students


liji@liji-VirtualBox:~/SDE$ cat students
Ans: 11 11 71 BCA
Qn 39.To replace all ‘A’ in a file with letter ‘e’ in file BCA and redirect the content in file
students
liji@liji-VirtualBox:~/SDE$ tr 'A' 'e' <BCA >students
Qn 40.To display the content of file students
liji@liji-VirtualBox:~/SDE$ cat students
Ans: Basil
eswathy
ency
Gayathri
Joel
Shine
Vishnu
jaes
anju
ananthu
rafeek
Qn 41.To display first letter of all lines of the file BCA
liji@liji-VirtualBox:~/SDE$ cut -c -1 BCA
Ans: B
A
A
G
J
S
V
j
a
a
r
Qn 42.To display first 2 letters of all lines of the file BCA
liji@liji-VirtualBox:~/SDE$ cut -c -2 BCA
Ans: Ba
As
An
Ga
Jo
Sh
Vi
ja
an
an
ra
Qn 43. To display the file that donot have ‘A’ in the file BCA

liji@liji-VirtualBox:~/SDE$ grep -v 'A' BCA


Basil
Gayathri
Joel
Shine
Vishnu
jaes
anju
ananthu
rafeek
Qn 44.To copy the content of file BCA to BCAA
liji@liji-VirtualBox:~/SDE$ cp -i BCA BCAA
Qn 45.Display content of file BCAA
liji@liji-VirtualBox:~/SDE$ cat BCAA
Ans: Basil
Aswathy
Ancy
Gayathri
Joel
Shine
Vishnu
jaes
anju
ananthu
rafeek
Qn 46. To move a file or rename a file
iji@liji-VirtualBox:~/SDE$ mv BSC ABC
Qn 47.Display the content of file ABC
liji@liji-VirtualBox:~/SDE$ cat ABC
Ans: Vishnu
jaes
anju
ananthu
rafeek
Qn 48. To display the content of file BSC
liji@liji-VirtualBox:~/SDE$ cat BSC
cat: BSC: No such file or directory
Qn 49.Remove file BCAA after prompting confirmation
liji@liji-VirtualBox:~/SDE$ rm -i BCAA
rm: remove regular file 'BCAA'? y
Qn 50.Remove directory SDE
liji@liji-VirtualBox:~$ rmdir SDE

You might also like