The sixth case study in the greatest class I will ever take.
Understand the use of device files within the Unix environment.
Shown below, I have navigated to /dev and listed the files. I then continued to discover what types of files were in the directory.
lab46:~$ cd /dev lab46:/dev$ ls MAKEDEV hvc2 mem root tty10 tty20 tty30 tty40 tty50 tty60 urandom zero block hvc3 net shm tty11 tty21 tty31 tty41 tty51 tty61 vcs char hvc4 network_latency snapshot tty12 tty22 tty32 tty42 tty52 tty62 vcs1 console hvc5 network_throughput snd tty13 tty23 tty33 tty43 tty53 tty63 vcsa core hvc6 null sndstat tty14 tty24 tty34 tty44 tty54 tty7 vcsa1 cpu_dma_latency hvc7 port stderr tty15 tty25 tty35 tty45 tty55 tty8 vga_arbiter disk initctl ppp stdin tty16 tty26 tty36 tty46 tty56 tty9 xconsole fd input psaux stdout tty17 tty27 tty37 tty47 tty57 ttyS0 xen full kmsg ptmx tty tty18 tty28 tty38 tty48 tty58 ttyS1 xvda1 hvc0 log pts tty0 tty19 tty29 tty39 tty49 tty59 ttyS2 xvda2 hvc1 loop0 random tty1 tty2 tty3 tty4 tty5 tty6 ttyS3 xvda3 lab46:/dev$ file full full: character special lab46:/dev$ file net net: directory lab46:/dev$ file loop0 loop0: block special lab46:/dev$ file shm shm: sticky directory lab46:/dev$ file root root: symbolic link to `xvda1'
Here are three block devices:
lab46:/dev$ ls block 202:1 202:2 202:3 lab46:/dev$ file block/202\:1 block/202:1: symbolic link to `../xvda1' lab46:/dev$ file block/202\:2 block/202:2: symbolic link to `../xvda2' lab46:/dev$ file block/202\:3 block/202:3: symbolic link to `../xvda3'
And three character devices:
lab46:/dev$ ls char/ 10:1 10:63 1:1 1:8 229:4 4:10 4:16 4:21 4:27 4:32 4:38 4:43 4:49 4:54 4:6 4:65 5:0 7:129 10:231 116:2 1:11 1:9 229:5 4:11 4:17 4:22 4:28 4:33 4:39 4:44 4:5 4:55 4:60 4:66 5:1 10:59 13:32 1:3 229:0 229:6 4:12 4:18 4:23 4:29 4:34 4:4 4:45 4:50 4:56 4:61 4:67 5:2 10:60 13:63 1:4 229:1 229:7 4:13 4:19 4:24 4:3 4:35 4:40 4:46 4:51 4:57 4:62 4:7 7:0 10:61 13:64 1:5 229:2 4:0 4:14 4:2 4:25 4:30 4:36 4:41 4:47 4:52 4:58 4:63 4:8 7:1 10:62 13:65 1:7 229:3 4:1 4:15 4:20 4:26 4:31 4:37 4:42 4:48 4:53 4:59 4:64 4:9 7:128 lab46:/dev$ file char/10:1 char/10:1: symbolic link to `../psaux' lab46:/dev$ file char/10:62 char/10:62: symbolic link to `../xen/gntdev' lab46:/dev$ file char/4:51 char/4:51: symbolic link to `../tty51'
After using the df command, I can see:
lab46:~$ df Filesystem Size Used Avail Use% Mounted on /dev/xvda1 4.0G 2.8G 993M 75% / tmpfs 766M 0 766M 0% /lib/init/rw udev 738M 36K 738M 1% /dev tmpfs 766M 4.0K 766M 1% /dev/shm /dev/xvda2 248M 11M 225M 5% /tmp nfs:/home 2.8T 1.4T 1.5T 49% /home nfs:/lib/mail 2.8T 1.4T 1.5T 49% /var/mail
I have no stinking clue where the system swap is located. But thanks to the df command, I can see that Lab46 uses Xen Virtual Disks (since the server is virtual while running on top of Xen Server) and NFS for the storage of our home directories and mail! NFS… Pretty sure that's located on a different system and it's been mounted as a drive on this system. Meow.
The permissions on my two TTY files are shown below:
lab46:/dev/pts$ tty /dev/pts/0 lab46:/dev/pts$ file 0 0: character special lab46:/dev/pts$ ls -la | grep adahmane crw--w---- 1 adahmane tty 136, 0 Dec 12 00:09 0 crw--w---- 1 adahmane tty 136, 59 Dec 12 00:09 59
I personally have read/write access and the tty group has write access. Here's what I get with the who command…
lab46:/dev/pts$ who | grep adahmane adahmane + pts/0 2013-12-11 22:33 . 10880 (cpe-67-252-123-191.stny.res.rr.com) lab46:/dev/pts$ mesg is y
My current messaging status is y (which means my terminal is available). Changing that to n ought to remove the write access from the tty group. That's my assumption… Let's see!
lab46:/dev/pts$ mesg n lab46:/dev/pts$ mesg is n lab46:/dev/pts$ who | grep adahmane adahmane - pts/0 2013-12-11 22:33 . 10880 (cpe-67-252-123-191.stny.res.rr.com) lab46:/dev/pts$ ls -la | grep adahmane crw------- 1 adahmane tty 136, 0 Dec 12 00:15 0 crw--w---- 1 adahmane tty 136, 59 Dec 12 00:14 59
WOO! Correct. Since we are all part of the tty group, we are given the ability to print to another person's terminal. Taking away the write access from the tty group (with the use of “mesg n”) will prevent anyone from printing to my terminal!
Mini-mind-blow #7428307940 - Since everything is a file and /dev/pts/0 is my current terminal session, I could theoretically redirect output to that file and it would be the same as using the echo command! Again, let's see…
lab46:/dev/pts$ echo meow meow lab46:/dev/pts$ echo meow > /dev/pts/0 meow lab46:/dev/pts$ echo meow > /dev/pts/ -bash: /dev/pts/: Is a directory lab46:/dev/pts$ who NAME LINE TIME IDLE PID COMMENT adahmane + pts/0 2013-12-11 22:33 . 10880 (cpe-67-252-123-191.stny.res.rr.com) smeas + pts/2 2013-05-10 16:24 01:05 1516 (li583-226:S.0) alius + pts/13 2013-05-13 16:26 08:05 14720 (cpe-74-65-109-183:S.0) bh011695 + pts/22 2013-05-15 10:42 old 32271 (cpe-74-67-87-78:S.0) smeas + pts/24 2013-12-08 15:12 05:12 16386 (li583-226.members.linode.com) jmendoza + pts/30 2013-12-11 22:55 . 11292 (pool-96-238-196-119.bing.east.verizon.net) jvanzil4 + pts/38 2013-12-11 08:35 00:05 20621 (cpe-69-205-156-203.stny.res.rr.com) cclay + pts/54 2013-12-11 23:54 . 12088 (pool-96-238-196-119.bing.east.verizon.net) vcordes1 + pts/53 2013-12-11 22:09 . 10512 (cpe-67-252-122-189.stny.res.rr.com) jkosty6 + pts/55 2013-12-11 23:25 00:03 11470 (cpe-69-204-219-21.stny.res.rr.com) jlapham1 + pts/57 2013-12-11 22:56 00:47 11315 (cpe-69-204-215-105.stny.res.rr.com) jkosty6 + pts/58 2013-12-11 23:38 . 11575 (cpe-69-204-219-21.stny.res.rr.com) jvanzil4 - pts/46 2013-12-11 22:18 . 10620 (cpe-69-205-156-203.stny.res.rr.com) jmendoza + pts/8 2013-12-11 23:17 00:23 11439 (pool-96-238-196-119.bing.east.verizon.net) lab46:/dev/pts$ echo wow.very_shell.much_command. wow.very_shell.much_command. lab46:/dev/pts$ echo wow.very_shell.much_command. > /dev/pts/58 -bash: /dev/pts/58: Permission denied
Well, I think that shows my understanding of the pts stuff. Just another way to make text appear on my screen! Really, any command could be redirected to /dev/pts/0 (or whatever port I'm on) to display text on my terminal! As you can see above, I attempted to harass John Kosty but it didn't work out as well as I had hoped…
lab46:~$ cat /etc/motd __ _ _ _ __ . . . . . . . . . . . . . . . . . . . . . . . . . | | __ _| |__ / | |_/ / . Basic System Usage: Type 'usage' at prompt . | |__/ _` | '_ \\_ _/ _ \ . Events and News: Type 'news' at prompt . |_____\__,_|_.__/ |_|\___/ . Broken E-mail? Type 'fixmail' at prompt . --------------------------- . Check Lab46 Mail: Type 'alpine' at prompt . c o r n i n g - c c . e d u . . . . . . . . . . . . . . . . . . . . . . . . . Lab46 is the Computer & Information Science Department's Student Development Server for Computer-related coursework, projects, and exploration. For more information, please check out: .. . . . . . . . . . .. . Lab46 Web Page: http://lab46.corning-cc.edu/ . . Lab46 Help Form: http://lab46.corning-cc.edu/help_request . . Help E-mail: haas@corning-cc.edu or wedge@lab46.corning-cc.edu . .. . . . . . . . . . .. _ .-./*) _/___/ `. U U 'You can filter data with the 'grep' command.' lab46:~$ cat /etc/motd > /dev/tty __ _ _ _ __ . . . . . . . . . . . . . . . . . . . . . . . . . | | __ _| |__ / | |_/ / . Basic System Usage: Type 'usage' at prompt . | |__/ _` | '_ \\_ _/ _ \ . Events and News: Type 'news' at prompt . |_____\__,_|_.__/ |_|\___/ . Broken E-mail? Type 'fixmail' at prompt . --------------------------- . Check Lab46 Mail: Type 'alpine' at prompt . c o r n i n g - c c . e d u . . . . . . . . . . . . . . . . . . . . . . . . . Lab46 is the Computer & Information Science Department's Student Development Server for Computer-related coursework, projects, and exploration. For more information, please check out: .. . . . . . . . . . .. . Lab46 Web Page: http://lab46.corning-cc.edu/ . . Lab46 Help Form: http://lab46.corning-cc.edu/help_request . . Help E-mail: haas@corning-cc.edu or wedge@lab46.corning-cc.edu . .. . . . . . . . . . .. _ .-./*) _/___/ `. U U 'You can filter data with the 'grep' command.'
Apparently I just did something very similar above. Kinda. This method allowed me to redirect the output of the cat to my terminal session. Nifty!
I'm not even going to type this one into the terminal… I know that redirecting to null won't show me anything. We learned this in class one day. It could be useful for cronjobs so as not to receive any output from the completion of the task! That's just one of a million or more examples.