CP Assignment Aditya Rohila
CP Assignment Aditya Rohila
1
Beginner Level
1. Which command would you use to list all files and directories in the current directory?
Ans- ls
Ans:- rm temp.txt
6. If you want to copy a file named data.csv to a directory called backup, what command would you use?
7. What command would you use to move up one directory level from your current location?
Ans:- cd ..
8. How do you clear all the text from the terminal screen?
Ans:- clear
Intermediate Level
1. Which command helps you find a file named document.txt starting from
2. How would you move a file named report.doc from the current directory
3. What command would you use to search for the word ”error” in a file
named log.txt?
4. Which command would tell you how many lines are in a file called script.sh?
Ans:- wc -l script.sh
5. How can you check the permissions of all files in the current directory?
Ans:- ls -l
6. What command would you use to see a list of currently running processes?
Ans:- ps
7. How do you compare two files, file1.txt and file2.txt, to see their
differences?
8. Which command gives a summary of the disk usage for the current directory and its subdirectories?
Ans:- du -sh *
ii) -s: Summarizes the total disk usage of each argument (directory or file) rather than listing usage for each
file within the directory.
iii) -h: Displays the sizes in a human-readable format (e.g., KB, MB, GB).
iv) *: Specifies that you want to check the disk usage of all files and subdirectories in the current directory.
Advanced Level
1. What command would you use to list all files in the current directory and then display the number of
lines in each file?
Ans:- ls | xargs wc -l
ii) xargs: Takes the output of ls and passes it as arguments to the wc -l command.
For each file, it will display the number of lines followed by the filename, like this:
123 file1.txt
45 file2.txt
2. How would you create a compressed archive called backup.tar.gz from a directory named data?
iii) -z: Compress the archive using gzip (resulting in a .gz file).
vi) data/: The directory that you want to compress into the archive.
3. How would you change the permissions of a file named script.sh to make
ii) u+x: The u stands for "user" (the file owner), and the +x adds the execute permission for the owner.
4. Which command would you use to schedule a task to run every day at 6 AM?
crontab -e
Add the following line to the crontab file to schedule the task:
0 6 * * * /path/to/your/command
i) 0 6: This specifies the time (6:00 AM). 0 represents the minute (on the hour), and 6 represents the hour
(6 AM).
ii) * * *: These represent the day of the month, the month, and the day of the week, respectively. * means
"every" (i.e., every day of the month, every month, and every day of the week).
iii) /path/to/your/command: Replace this with the actual command or script you want to run at 6 AM.
5. What command would you use to check if a server with IP 192.168.1.1 is reachable?
i) ping: A command used to test network connectivity by sending ICMP echo request packets to a target
host and waiting for a response.
ii) 192.168.1.1: The IP address of the server you want to check.
i) export: This command is used to set environment variables that will be available to child processes in
the current shell session.
ii) MY_VAR="HelloWorld": This assigns the value HelloWorld to the environment variable MY_VAR.
7. What command would you use to kill a process with PID 1234?
its subdirectories?
ii) .: Represents the current directory (you can change it to another directory if needed).
iv) -size +100M: Finds files larger than 100MB. The + symbol means "greater than," and M represents
megabytes.
Bonus Question
1. How do you create a new user named newuser with a home directory and add them to the group
sudo?
Ans:- Create the user with a home directory: Use the useradd command with the -m option to create the
home directory:
i) -m: This option ensures that a home directory is created for the new user (/home/newuser by
default).
Set a password for the new user: You need to set a password for the new user with the passwd command:
This will prompt you to enter and confirm a password for newuser.
Add the new user to the sudo group: To give the new user sudo privileges, add them to the sudo group
using the usermod command:
i) -aG: The -a option appends the user to the group without removing them from other groups, and
G specifies the group (sudo).