You are on page 1of 18

Name : Madhav Vakharia

Batch : A3

Roll no : I062

EXPERIMENT 1

Note:- paste the print screen of your output for following commands.

Q.1. Display the long listing of the current directory. 

Ans :

1. ls

Q.2. Create a directory and change to that directory. 

Ans :
1. Mkdir I062_Madhav_Exp1

2. cd I062_Madhav_Exp1

Q.3. Create a file within the created directory using vi editor. 

Ans :

1. vi m1.txt

2. ls
Q.4. Display the contents of the created file. 

Ans :

1. cat m1.txt
Q.5. Remove the created directory. 

Ans :

1. cd ..

2. rm -rf I062_Madhav_Exp1

3. ls
Q.6. Display the current directory path. 

Ans :

1. pwd

Q.7. Write a C program to find factorial of a given number compile and execute

it. 
Ans :

1. pico fil1.c

Code :

#include <stdio.h>

int fact (int n)

if (n < 0)

return -1;

if (n == 0)

return 1;

else

return (n * fact (n - 1));

int main()

printf("\n");
int n;

printf("Enter number: ");

scanf("%d", &n);

printf("Factorial = %d\n\n", fact (n));

return 0;

2. cc fil1.c

3. ./a.out
Q.8. Change the file permission to execute for the created C program file. 

Ans :

1. chmod 777 a.out

2. ls -lrt
Q.9. Store the current date into a file. 

Ans :

1. date >> date.txt

2. cat date.txt
Q.10. Store the count of users into a file. 

Ans :

1. echo "Number of users: $(who | wc -l)" >> users.txt

2. cat users.txt

*Since it’s an online compiler . It will result in 0 user .


Q.11. Append the user listing in sorted order into the same file created in 10. 

Ans :

1. who | sort >> users.txt

2. cat users.txt

3. ls

Q.12. Print the total number of files/directories in current directory on the output
screen. 
Ans :

1. ls | wc -l

Q.13. Print the user list with name starting with some character in sorted order. 

Ans :

1. who | grep -E '\bf' | sort

*Since there are no users In the online compiler hence no output


Q.14. Create two files with 7 lines of data each. Then display the difference from
both files. 

Ans :

1. pico t1.txt

2. pico t2.txt

3. diff t1.txt t2.txt


Q.15. Print the first 2 lines of a file. 

Ans :

1. head -2 t1.txt

2. head -2 t2.txt
Q.16. Print the last 2 lines of a file. 

Ans.

1. tail -2 t1.txt

2. tail -2 t2.txt

Q.17. Print the user names only from who command. 


Ans :

1. who | cut -f 1 -d " "

*Since it’s an online compiler , it will not show any output

Q.18. Count the number of words, characters, lines of a file and store this output
in another file. 
Ans :

1. echo "NUMBER OF WORDS : $(wc -w t1.txt | cut -f 1 -d " ")" >> tw.txt

2. echo "NUMBER OF CHARACTERS : $(wc -m t1.txt | cut -f 1 -d " ")" >> tw.txt

3. echo "NUMBER OF LINES : $(wc -l t1.txt | cut -f 1 -d " ")" >> tw.txt

4. cat tw.txt

Q.19. Print the long listing of all the processes. 

Ans :

1. ps aux

You might also like