1. From your home directory, find all the symbolic links currently in /tmp. 2. F
ID: 3849228 • Letter: 1
Question
1. From your home directory, find all the symbolic links currently in /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.
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!
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.
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
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.
Explanation / Answer
1. From your home directory, find all the symbolic links currently in /tmp.
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.
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)
I really did not understand the meaning of 2 column report. Can you show the sample lines of this 2 column report and what they represent. For now as per my understanding i have picked the 1st(username) and 4th(groupId) column and provided the output. Please check and revert back if this is not what you want with details asked above.
sh-4.3$ cat /etc/passwd|cut -d':' -f1,4|sort|uniq
adm:4
apache:48
bin:1
cg:1000
daemon:2
dbus:81
ftp:50
games:100
halt:0
lp:7
mail:12
nobody:99
operator:0
root:0
shutdown:0
sync:0
systemd-bus-proxy:995
systemd-network:997
systemd-resolve:996
systemd-timesync:998
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.
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
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':' -f1,3|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
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
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.