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

CP Assignment Aditya Rohila

The document is a computational physics assignment that includes beginner, intermediate, and advanced level questions related to command line operations in a Unix-like environment. It provides commands for file and directory management, process handling, and user management. Each question is followed by a detailed answer explaining the command and its components.

Uploaded by

vanshsaini312
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)
6 views4 pages

CP Assignment Aditya Rohila

The document is a computational physics assignment that includes beginner, intermediate, and advanced level questions related to command line operations in a Unix-like environment. It provides commands for file and directory management, process handling, and user management. Each question is followed by a detailed answer explaining the command and its components.

Uploaded by

vanshsaini312
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
You are on page 1/ 4

Computational Physics Assignment no.

1
Beginner Level
1. Which command would you use to list all files and directories in the current directory?

Ans- ls

2. How would you create a new directory called projects?

Ans:- mkdir projects

3. What command creates an empty file named notes.txt?

Ans:- touch notes.txt

4. Which command would display the contents of a file called readme.txt?

Ans:- cat readme.txt

5. How do you delete a file named temp.txt?

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?

Ans:- cp data.csv backup/

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

the current directory?

Ans:- find . -name "document.txt"

2. How would you move a file named report.doc from the current directory

to a directory called docs?

Ans:- mv report.doc docs/

3. What command would you use to search for the word ”error” in a file

named log.txt?

Ans:- grep "error" 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?

Ans:- diff file1.txt file2.txt

i) diff: The command used to compare files line by line.

ii) file1.txt and file2.txt: The files you want to compare.

8. Which command gives a summary of the disk usage for the current directory and its subdirectories?

Ans:- du -sh *

i) du: The command to estimate file space usage.

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

i) ls: Lists all files in the current directory.

ii) xargs: Takes the output of ls and passes it as arguments to the wc -l command.

iii) wc -l: Counts the number of lines in each file.

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?

Ans:- tar -czf backup.tar.gz data/

i) tar: The command used for creating and managing archives.

ii) -c: Create a new archive.

iii) -z: Compress the archive using gzip (resulting in a .gz file).

iv) -f: Specifies the name of the archive file.

v) backup.tar.gz: The name of the compressed archive to be created.

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

it executable by the owner only?

Ans:- chmod u+x script.sh

i) chmod: The command used to change file permissions.

ii) u+x: The u stands for "user" (the file owner), and the +x adds the execute permission for the owner.

iii) script.sh: The file whose permissions you want to modify.

4. Which command would you use to schedule a task to run every day at 6 AM?

Ans:- First, open the crontab file for editing:

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?

Ans:- ping 192.168.1.1

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.

6. How would you temporarily set an environment variable MY VAR to HelloWorld?

Ans:- export MY_VAR="HelloWorld"

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?

Ans:- kill 1234

i) kill: The command used to terminate processes by their process ID (PID).

ii) 1234: The PID of the process you want to kill.


8. How can you find all files larger than 100MB in the current directory and

its subdirectories?

Ans:- find . -type f -size +100M

i) find: The command used to search for files and directories.

ii) .: Represents the current directory (you can change it to another directory if needed).

iii) -type f: Restricts the search to files only (excluding directories).

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:

sudo useradd -m newuser

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:

sudo passwd newuser

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:

sudo usermod -aG sudo newuser

i) -aG: The -a option appends the user to the group without removing them from other groups, and
G specifies the group (sudo).

You might also like