Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Instructions: For each question, you must give the complete/full command that wh

ID: 3883657 • Letter: I

Question

Instructions: For each question, you must give the complete/full command that when executed in a

Linux Bash shell it gives the correct output (as stated in the question). Full credit is given only when

command executed successfully and gave the correct output.

Example

Question: What is the command to list the contents of the current directory in long format?

Answer: ls –l

Note: Quotes surrounding certain terms such as “ls”, “/etc/passwd”, “work”, etc. are NOT part of that

term. The quotes are only for highlighting the terms. When using that term remove the quotes. Your

answer must be the exact string that is typed into the Bash shell.

11. Your home directory currently has permissions “rwxr-xr-x”. Give 3 different ways to change the

permissions to “rwxrwx---“.

12. What is the command to create a file named “#secret”?

13. What is the command to save the contents of both files “/proc/cpuinfo” and “/proc/meminfo” to a

file named “hwinfo.txt” in your own home directory and have nothing printed on the screen?

14. What is the command to find all files in directory “/etc” (and its subdirectories) whose filenames

ended in “config”?

15. What is the command to display the names of all files in the system that are bigger than 10 MB and

do not display any error message regarding files/directories you cannot access?

16. What is the command to display a sorted list in ascending order (A to Z) of all files in “/etc” (and its

subdirectories) that contain the string “address” somewhere in the contents of the file?

CPSC-254 Fall 2017 Prof. Thomas Nguyen Assignment #2 pg. 2

17. What is the command to unpack a tarballed and compressed file named “grep.tgz” in

“~/Downloads” and have the outputs placed in “~/source”?

18. What is the command to list just the PID of all “bash” processes currently running in the system?

19. What is the single command to both display the calendar for the year 2017 on the console and save

it a file named “cal2015.txt”?

20.What are the outputs of the commands “yes please” and “who is best?”? Explain why you got the

outputs that you got.

Explanation / Answer

1. Your home directory currently has permissions “rwxr-xr-x”. Give 3 different ways to change the

permissions to “rwxrwx---“.

a) Using chmod

  

chmod g=rwx,u=rxw,o-rwx <path to home directory>

  

Example:

  

chmod g=rwx,u=rwx,o-rwx /home/user/

  

If you get operation is not permit, try with sudo.

sudo chmod chmod g=rwx,u=rxw,o-rwx <path to home directory>

  

b) Using setfacl

setfacl -m g=rwx,u=rwx,o=--- <path to home directory>

c) chmod with numbers

chmod 770 <path to home directory>

2) What is the command to create a file named “#secret”?

touch ./#secret

3) What is the command to save the contents of both files “/proc/cpuinfo” and “/proc/meminfo” to a

file named “hwinfo.txt” in your own home directory and have nothing printed on the screen?

cat /proc/cpuinfo > hwinfo.txt && cat /proc/meminfo >> hwinfo.txt

4) What is the command to find all files in directory “/etc” (and its subdirectories) whose filenames

ended in “config”?

sudo find /etc -type f -name *config

5) What is the command to display the names of all files in the system that are bigger than 10 MB and

do not display any error message regarding files/directories you cannot access?

sudo find . -type f -size +10M

6) What is the command to display a sorted list in ascending order (A to Z) of all files in “/etc” (and its

subdirectories) that contain the string “address” somewhere in the contents of the file?

sudo grep -nre "address" /etc -l | sort

7) What is the command to unpack a tarballed and compressed file named “grep.tgz” in

“~/Downloads” and have the outputs placed in “~/source”?

tar -xvzf ~/Downloads/grep.tgz -C ~/source/

8) What is the command to list just the PID of all “bash” processes currently running in the system?

ps -ef | grep "bash" | awk {'print $2'}

9) What is the single command to both display the calendar for the year 2017 on the console and save

it a file named “cal2015.txt”?

cal 2017 | tee cal2015.txt