Provide the UNIX command(s) to perform the following actions: 1. In no more than
ID: 3747030 • Letter: P
Question
Provide the UNIX command(s) to perform the following actions:
1. In no more than two UNIX commands (and without using shell scripts or piping commands into a shell), perform all the following tasks. Create a directory called “projects” (without the double-quotes) in the current working directory. Within the “projects” directory, create directories called “project 1”, “project 2”, and “project 3” (without the double-quotes, but including the embedded space). Within each of the project # directories, create an empty file called “task 1”, “task 2”, “task 3”, and “task 4” (without the double-quotes, but including the embedded space). Explain why you chose the commands you chose and how they work.
2. Provide two different commands that recursively remove the contents of a directory called tmp but not the directory itself. BE CAREFUL WHEN TESTING THIS FUNCTIONALITY! YOU DON’T WANT TO ACCIDENTALLY DELETE THINGS YOU WANT TO KEEP. Explain why you chose the commands you chose and how they work.
3. Provide and demonstrate three different commands that create an empty file in the current directory. Name the file “tasks” (without the double-quotes). Explain how each command works / what it does.
4. Assume the current directory has a file called “tasks” with arbitrary content. Provide and demonstrate a single “find” command that creates a “tasks” file (without the double-quotes) in each of the subfolder of the current directory. Create those “tasks” files in such a way that changing the contents of any of the “tasks” files changes the contents of all other “tasks” files. Also, create those “tasks” files in such a way that you can delete any of the “tasks” files without impacting the other “tasks” files. Explain how your command works.
5. With three different permissions (read, write, and execute) and three different categories of user (owner, group, and world), how many different combinations of permissions exist that may be applied to a file or directory? Why?
6. Is there a permission on a directory that allows me to create a file in that directory but not see the existence of that file? If so, provide the necessary commands to create and set the permissions on the directory. If not, explain why not.
7. Can I delete a file even though I can’t see its contents or modify the contents of the file? If so, provide a sequence of commands to exhibit this behavior. Be sure to show the commands that demonstrate you get an error if you try to see the contents of the file or change the contents of the file. If not, explain why not.
8. Provide and demonstrate a single UNIX command, using wildcards, pipelining, and redirection, that uses “cat” to obtain the contents of all files in the /etc directory that begin with a lower-case letter, sorts the contents ACROSS ALL THE FILES (don’t just sort each individual file), discards duplicates lines, and provides a count of the resulting number of lines. If the command results in any errors, have those errors written to a file called “errors.txt”.
Explanation / Answer
According to the chegg policy I answered the First four questions .
1. In no more than two UNIX commands (and without using shell scripts or piping commands into a shell), perform all the following tasks. Create a directory called “projects” (without the double-quotes) in the current working directory. Within the “projects” directory, create directories called “project 1”, “project 2”, and “project 3” (without the double-quotes, but including the embedded space). Within each of the project # directories, create an empty file called “task 1”, “task 2”, “task 3”, and “task 4” (without the double-quotes, but including the embedded space). Explain why you chose the commands you chose and how they work.
Answer)
mkdir -p projects/{'project 1','project 2','project 3'}
touch projects/{'project 1'/'task 1','project 2'/'task 2','project 3'/'task 3'}
If we create subdirectories or files in single command then we have to mention in {} and if we want to include spaces then we have write the file or directory name in ''(single quotes)
2. Provide two different commands that recursively remove the contents of a directory called tmp but not the directory itself. BE CAREFUL WHEN TESTING THIS FUNCTIONALITY! YOU DON’T WANT TO ACCIDENTALLY DELETE THINGS YOU WANT TO KEEP. Explain why you chose the commands you chose and how they work.
Answers)
Recursive means from down to top
1st command
rm -rf tmp/*
By the above command we are removing all the contents by not the directory itself, if we dirname/*, -r for recusively and -f for force.
2nd command
find projects1 -mindepth 1 -delete
-mindepth 1 and -delete is used for delete all the contents.
3. Provide and demonstrate three different commands that create an empty file in the current directory. Name the file “tasks” (without the double-quotes). Explain how each command works / what it does.
Answer)
touch e1
The touch command is used for creating empty file.
>e2
By output redirecting we can create a empty file.
cat /dev/null > e3
/dev/null means blank is redirecting to a file means a empty file creation.
4. Assume the current directory has a file called “tasks” with arbitrary content. Provide and demonstrate a single “find” command that creates a “tasks” file (without the double-quotes) in each of the subfolder of the current directory. Create those “tasks” files in such a way that changing the contents of any of the “tasks” files changes the contents of all other “tasks” files. Also, create those “tasks” files in such a way that you can delete any of the “tasks” files without impacting the other “tasks” files. Explain how your command works.
find . -type d -exec ln -s tasks {} ;
By the find command we fetch the file and then by -exec we create a symbolic link to links all the files created in the subdirectpries.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.