9. From ~/asgt2, execute following commands, then explain what happened. Then te
ID: 3871214 • Letter: 9
Question
9. From ~/asgt2, execute following commands, then explain what happened. Then tell me how you fixed it so you could actually delete that file and directory.
rm subdir/data
10. Compare two ways of quick file creation. While in the “~/asgt2” directory:
Create file named data1 with: touch data1
Create file named data2 with: >data2
Examine data1 and data2 using the ls and stat commands with appropriate options.
What’s the difference, if any, between the two files?
11. From ~/asgt2, execute the following command sequence (there are spaces after the commas) and if it asks, go ahead and remove file2.
rm *
touch f1, f2
> f3, f4
What messages did you get, and why?
12. From the previous question, why was f2 treated as a filename?
13. Why was f4 not treated as a filename?
14. How many files, excluding directories, exist in the working directory? And, what are their names?
15. Does the shell use commas to separate arguments?
16. While still in ~/asgt2, execute the following command sequence (there are no spaces after the commas, and you’ll again get a message about the subdirectory):
rm *
touch f1,f2
> f3,f4
How many files, excluding directories, exist in the working directory? And, what are their names?
17. Let’s explore shell brace expansions and command substitution From ~/asgt2, execute the following command sequence:
rm *
echo f{1,2,3}
touch $(echo f{1,2,3})
How many files, excluding directories, exist in the working directory? And, what are their names?
18. From ~/asgt2, execute the following command sequence:
rm *
touch f{1,2,3} f{3..5} f{9,10}.txt
How many files, excluding directories, exist in the working directory? Why?
19. Come up with a command sequence to print only the number of files (excluding directories) in ~/asgt2.
20. The cat command can be used with ctl-D (^D) to quickly create short text files. From ~/asgt2, use the following command sequence to make a two line file, with three characters in each line.
rm *
cat >f1
123
abc
<ctl-D> -- the ^D character for EOF
Display the size of f1. If the byte size is not 8, then remake f1.
Use the following commands to view f1.
cat f1
cat -A f1
hd f1
ls -l f1
Explain why f1 contains 8 bytes rather than 6, 7, or 9.
21. From ~/asgt2, execute following commands:
rm *
mkdir d1 d2 .d10 f11
touch f1 f2 .f20 d11
ls -al | wc -l
The result of the last command should be 11 (“ell-ess dash-a-ell pipe to wc dash-ell”).
But why does the command pipeline ls -a1 | wc -l write 10 to the console? (This is “ell-ess dash-a-one pipe to wc dash-ell”).
22. From ~/asgt2, execute following command:
rm -r *
Some files and directories remain. How many files and/or directories remain in ~/asgt2 (Not including the current and parent directory)?
23. From ~/asgt2, execute following commands:
pwd >result1
echo $pwd >>result1
echo $PWD >>result1
Ensure that wc -l result1 returns 3 result1. (Or, repeat the preceding commands.)
View the result of cat -n result1 and then, explain why the command line
uniq result1 | wc -l
returns 3, but the command line
sort result1 | uniq | wc -l
returns 2.
24. How could you obtain the same result as in the second part of the previous question, but by using just the sort and wc commands?
25. Explore some more commands in combination. From ~/asgt2, execute the following command sequence:
cp /etc/passwd ./password
Use the echo command with the appropriate options, arguments, and command substitution with commands like cut and sort (along with their appropriate options and arguments) to construct a single command pipeline to report the usernames in the password file in this format:
List of all users:
avahi avahi-atutopic backup <snip> uucp www-data
Where:
<snip> means content omitted from the illustration, not a literal phrase.
You may not use a command sequence (no semicolons).
The list of users needs to start on a new line after the phrase "List of all users:" and it needs to be sorted alphabetically, a-z.
What command did you come up with?
You may want to remember to remove “asgt2” directory from your home directory.
Explanation / Answer
9. From ~/asgt2, execute following commands, then explain what happened.
Then tell me how you fixed it so you could actually delete that file and directory.
rm subdir/data
If there exists the directory or a file named data in your directory, it will be removed.
Please note that if data is a directory, and cannot be deleted unless it is empty.
So, its a hypothetical question based on the machine you're testing on.
Just do execute both these instructions:
>cd ~/asgt2
>rm subdir/data
And just write the warning message you received.
The two possible warnings are:
File or directory doesn't exist.
Directory is not empty.
10. Compare two ways of quick file creation. While in the “~/asgt2” directory:
Create file named data1 with: touch data1
Create file named data2 with: >data2
Examine data1 and data2 using the ls and stat commands with appropriate options.
What’s the difference, if any, between the two files?
If the files data1, and data2 doesn't exist, there will be really no difference between
the both instructions. Where as, if the files readily exist and if they contain some
valid data, now touch will just change the flags of the data like accesstime etc
but will leave the file unchanged. Whereas, if we try the other method, it will erase
the contents of the file, and will make it empty. Remember > is a redirection operator
and if nothing is given as input, an emptiness will be written(overwritten) to the file.
11. From ~/asgt2, execute the following command sequence (there are spaces after the commas) and if it asks, go ahead and remove file2.
rm *
touch f1, f2
> f3, f4
What messages did you get, and why?
rm will simply remove all the files in the current directory.
And once the directory is empty, touch will simply create a(or a list of) file(s).
touch f1, f2 will create two files. The first one is named "f1,", and the other one is named "f2"
Please note you used a comma, and it will be considered as file name.
Actually, you're supposed to give a space, and not a comma, if you don't want it as part of the file name.
And the output operator cannot be used to redirect the output to multiple files like this.
So, it will again create a file named "f3," but will also generate a warning "f4: command not found"
This is because, you're not allowed to redirect the output to multiple files.
12. From the previous question, why was f2 treated as a filename?
touch can be used to touch any number of files. And therefore, any number of parameters
separated by spaces will be considered as filenames.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.