Need some help with this i am not getting the right solutions. Note- I am using
ID: 3849777 • Letter: N
Question
Need some help with this i am not getting the right solutions.
Note- I am using a non-gui red hat unix (Linux version 2.6.18-419.el5 (mockbuild@x86-027.build.eng.bos.redhat.com) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-55)) #1 SMP Wed Feb 22 22:40:57 EST 2017)
1. From your home directory, find all the symbolic links currently in /tmp. My solution: 18 of them.
2. From your home directory, find all the files of the form yyyymmdd.txt in /tmp/notes which represent dates in 2016 from even-numbered months. My solution: 150 of them.
3. Below is a two-column report showing the number (first column) of each different group-id (second column) from the /etc/passwd file. Use a pipe of cut/sort/uniq to re-create this output. Some man page perusing may be required!
[mam-p@voyager ~]$ <your answer here!>
5 0
1 1
1 2
1 4
1 7
1 12
1 13
1 14
1 16
1 23
1 27
1 28
1 29
1 30
1 32
1 37
1 38
1 42
1 43
1 47
1 48
1 50
1 51
1 67
1 68
1 69
1 70
1 74
1 77
1 81
1 86
1 94
1 97
1 99
2 100
74 411
2 412
1860 511
.
.
.
1 65534
[mam-p@voyager ~]$
4. From your home directory, find all the files associated with group 100. Copy/paste both your command and its output, but not its standard error output. My solution: 2 such files.
5. From your home directory, use egrep/cut/sort to produce a list showing the username and real name of all the students in the /etc/passwd file; the list should be lexicographically sorted by username. Copy/paste just your command for hand-in. My output:
023906973:Hobbs Ryan Thomas
10608634:Yang Zhiqiang
11159827:Chang Jonas
.
.
.
zrkerk:"Kerk Zi Rui" .
zsj25502:Zheng Jerod Shaojie
zuyanhuang:Huang Zuyan
6. Use cal to demo (as succinctly as possible) which day of the week November 11, 1884, fell on. Copy/paste your command output for hand-in.
7. The most intriguing student solution I've come across so far in my grading of LAB EXERCISE #9's question #7 was this one:
egrep -i "^(.*:){4} ?v.*:/home.*$" /etc/passwd
It produces one fewer line of output than my solution, but that line is rather irrelevant anyway because the entry is not for an actual person. So, I consider the above a better solution than mine in that it could be way less complex than mine--the approach is very good. However, the way it is implemented above winds up making it look more complex than mine. Rewrite it to make it as UN-complex as possible while still working! Hint: My solution uses just 3 characters with special meaning whereas the above solution uses ~13 (depending on how you count them!). Copy/paste your solution and word count to hand-in.
Explanation / Answer
NOTE: I have tried these commands in my unix system. Commands Output would not be exactly same as what you are expecting in your computer. So please try these and let me know if you face any problems. Also please clarify on the 7th question because there is no mention about what the task is about.
1. From your home directory, find all the symbolic links currently in /tmp. My solution: 18 of them.
Ans)
To identify files with all symbolic links we have to use -type l which indicates files of type symbolic link.
E.g:
Unix Terminal> find /tmp -type l
/tmp
Unix Terminal> ls -tlrhd /tmp
lrwxr-xr-x@ 1 root admin 11B Jan 24 04:08 /tmp -> private/tmp
2. From your home directory, find all the files of the form yyyymmdd.txt in /tmp/notes which represent dates in 2016 from even-numbered months. My solution: 150 of them.
Ans)
find /tmp/notes -name '2016[01][02468]*.txt'
We can give regular expression like 2016[01][02468]*.txt where it will match all the file names with year 2016 and even numbered months.
2016[01] - matches filenames with year 2016 and month starting with either 0 or 1
[01][02468] - matches filenames with month starting with 0 or 1 and ending with 0, 2, 4, 6, 8. That means it covers months like 02, 04, 06, 08, 10, 12
3. Below is a two-column report showing the number (first column) of each different group-id (second column) from the /etc/passwd file. Use a pipe of cut/sort/uniq to re-create this output. Some man page perusing may be required!
Ans)
sh-4.3$ cat /etc/passwd|cut -d':' -f4|sort|uniq -c
5 0
1 1
1 100
1 1000
1 12
1 2
1 4
1 48
1 50
1 7
1 81
1 99
1 995
1 996
1 997
1 998
sh-4.3$
4. From your home directory, find all the files associated with group 100. Copy/paste both your command and its output, but not its standard error output. My solution: 2 such files.
Ans)
cd ~
find . -gid 100
Execute the above commands where the first command will take you to home directory. whereas the next command will search all the files associated with gid 100 from the current directory i.e. home directory.
5. From your home directory, use egrep/cut/sort to produce a list showing the username and real name of all the students in the /etc/passwd file; the list should be lexicographically sorted by username. Copy/paste just your command for hand-in. My output:
Ans)
I am assuming real username as userId which is third field in the /etc/passwd file. The below command picks the username(1st column) and userId(3rd column) from the /etc/passwd file and sorts them by username which is 1st column
sh-4.3$ cat /etc/passwd|cut -d':' -f3,1|sort -t':' -k1
adm:3
apache:48
bin:1
cg:1000
daemon:2
dbus:81
ftp:14
games:12
halt:7
lp:4
mail:8
nobody:99
operator:11
root:0
shutdown:6
sync:5
systemd-bus-proxy:996
systemd-network:998
systemd-resolve:997
systemd-timesync:999
sh-4.3$
6. Use cal to demo (as succinctly as possible) which day of the week November 11, 1884, fell on. Copy/paste your command output for hand-in.
Ans)
The below command will tell you which day of the week Nov 11, 1884 is, considering Sunday as first day of the week as per calendar. The awk command piped to cal just tells you which day 11 is by iterating through each column.
Unix Terminal> cal Nov 1884|awk '{for(i=1;i<=NF;i++)if($i=='11')print i " Day: " $i}'
3 Day: 11
7. The most intriguing student solution I've come across so far in my grading of LAB EXERCISE #9's question #7 was this one:
egrep -i "^(.*:){4} ?v.*:/home.*$" /etc/passwd
It produces one fewer line of output than my solution, but that line is rather irrelevant anyway because the entry is not for an actual person. So, I consider the above a better solution than mine in that it could be way less complex than mine--the approach is very good. However, the way it is implemented above winds up making it look more complex than mine. Rewrite it to make it as UN-complex as possible while still working! Hint: My solution uses just 3 characters with special meaning whereas the above solution uses ~13 (depending on how you count them!). Copy/paste your solution and word count to hand-in.
Ans)
Did not understand what the question was. Please explain and provide the question clearly.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.