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

3. [10 marks] This question asks you to use wildcards. Use ls command to perform

ID: 3878422 • Letter: 3

Question

3. [10 marks] This question asks you to use wildcards. Use ls command to perform the tasks below (no other commands are allowed), and use script to record your most successful execution. For each subquestion, you are required to use only one UNIX command. Your command lines must work no matter what the current working directory is.

The names of the files to be generated by script, for the four questions below, are a1q3_a.txt, a1q3_b.txt, a1q3_c.txt and a1q3_d.txt.

(a) Print a list of files in directory /usr/bin whose names end with “.sh”. For example, gvmap.sh is such a file, but ssh is not.

(b) Print a list of files in the directory /usr/include whose names start with a or b, and ends with “.h”. For example, the file aio.h in this directory is one of them.

(c) Print a list of files in the directory /usr/bin whose names start with a and are 6 letters long. For example, file alpine in this directory is such a file.

(d) Print a list of files in the directory /usr/bin whose names do not start with either a lowercase or an uppercase English letter.

Explanation / Answer

1). ls /usr/bin | grep '.sh' > a1q3_a.txt

Output:

[cloudera@quickstart Desktop]$ cat a1q3_a.txt
alsa-info.sh
amuFormat.sh
gettext.sh
gnome-power-bugreport.sh
lesspipe.sh
lprsetup.sh
pm-utils-bugreport-info.sh
pv.sh
setup-nsssysinit.sh
start_logs.sh
stop_logs.sh
tail_logs.sh
unix-lpr.sh
[cloudera@quickstart Desktop]$

2). ls /usr/bin | grep -e '^a.*.sh' > a1q3_b.txt

output:

[cloudera@quickstart Desktop]$ cat a1q3_b.txt
alsa-info.sh
amuFormat.sh
[cloudera@quickstart Desktop]$

3). ls /usr/bin | grep -e '^a[a-z][a-z][a-z][a-z][a-z]$' > a1q3_c.txt

output:

[cloudera@quickstart Desktop]$ cat a1q3_c.txt
amixer
aulast
auvirt
[cloudera@quickstart Desktop]$

4). ls /usr/bin | grep -e '^[^a-zA-Z]' > a1q3_d.txt

ouput:

[cloudera@quickstart Desktop]$ cat a1q3_d.txt
[
[cloudera@quickstart Desktop]$

Please comment if you face any difficulty or if you want any modification.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote