PDA

View Full Version : How many Unix users out there?




Powerbook G5
Aug 8, 2003, 09:56 PM
After the interesting little aside in one of the other threads, I figured it'd be better to discuss somewhere in a more appropriate thread than hijacking another :)

So I picked up Unix for Dummies and decided to take the plunge into the world of Unix so I can become terminal savy. Right now I am purely a newbie, so all I know are the basic "uptime" and "who am i" commands for now. I know, it's pretty basic, but at least I am taking the first step. I've found that reading all this info about Unix can be quite overwhelming, but I just can't help but want to know all I can. I figured it'd be good to know how to use the terminal to get the most out of OS X when I upgrade with a new PowerBook soon, and incase I run across a need to use Unix in the future. So who else out there is learning/a die hard Unix fan/a poweruser/or just plain enjoy using the terminal? What kinds of commands have you found invalible for the OS X user? What kind of experiences, pluses with using Unix, etc have you come up with? If you have an opinion on Unix, then by all means, post! :D



Carbon
Aug 8, 2003, 11:18 PM
< ;) >

Personally, I'm still learning, but I've found an invaluable command that I use almost weekly. This command "optimizes" your hard drive by removing all extraneous temp, garbage, and system-independent files:
** ** *.

Heh, heh...

</ ;) >

Carbon
Aug 8, 2003, 11:21 PM
Just so you know, I WAS JOKING — Never, ever, ever enter that command! But I'm sure you knew that already. ;)

Because I have a slight problem with personal vendettas aimed at me...

:D

Powerbook G5
Aug 8, 2003, 11:25 PM
Reminds me of this useful DOS command...

deltree windows :D

grapes911
Aug 8, 2003, 11:36 PM
My college runs sun os (almost unix) on their servers. As a comp sci major, i spend a lot of time logged on to the servers. I picked up most of the usefull commands. It inspired me to install and learn linux (which is on my primary box). I just got my ibook about a week ago so I haven't fully explored it.

In linux, I use command line ftp, ssh, and a lot of other stuff. I really only use a gui for internet. Terminals are much faster for most apps.

I must say learn the terminal, unix, bsd, linux, or something similar. Most of the basic commands are the same. You never know when it might be usefull.

Powerbook G5
Aug 8, 2003, 11:54 PM
I've already found some useful commands in terminal that you can't do with OS X on its own without a third party program:

sudo ssh /etc/daily

sudo ssh /etc/weekly

sudo ssh /etc/monthly

(I think these are right...)

But if you are on a laptop and put your computer to sleep at night, OS X cannot do those routine maintainence steps, so you need to do them through the terminal.

Anyone find other commands that are useful for OS X?

Vortex
Aug 9, 2003, 12:04 AM
What exactly do those maintenance programs do?

Powerbook G5
Aug 9, 2003, 12:08 AM
I can't say offhand, but they do stuff like empty cache, clean out junk, check your disk for errors, do simple system checks, optimizations, etc. When you run the commands it displays step by step what it does. It's basically the commands that MacJanitor runs for the maintainence, except, you are inputing them yourself via the terminal.

Powerbook G5
Aug 9, 2003, 05:04 PM
I just spent a few hours at Barnes and Noble and learned quite a bit about the origin of Unix and bought "Unix for Mac OS X". So far it looks easy to follow and is helping to take my step by step in the process of using some Unix in Mac OS X. I also bought "Mac OS X Hints" which seems to have quite a bit of useful Unix info, as well.

janey
Aug 9, 2003, 09:15 PM
wait...basically isn't everyone using Mac OS X using Unix at the same time? X has a Unix foundation after all....

Powerbook G5
Aug 9, 2003, 09:17 PM
Yeah, but I meant as in how many people actively use the Unix side of it. If I tell my girlfriend about Unix in OS X she just looks at me as if I am on something or having another dorky moment. Lots of people don't even know there is a deeper side to OS X beyond the eye candy.

Doctor Q
Aug 9, 2003, 09:20 PM
There was a similar discussion in this thread (http://forums.macrumors.com/showthread.php?s=&threadid=24481). Check it out!

Powerbook G5
Aug 9, 2003, 09:26 PM
Cool, I'll have to check that thread out. I'm reading Learning Unix for Mac OS X, Unix for Dummies, and Mac OS X Hints to give me a good grounding in the terminal and the various things I can do with it. I still haven't really had much experience with OS X yet, but I want to jump in being able to be as skilled as I am with OS 9.

janey
Aug 10, 2003, 03:15 PM
my fav o'reilly book sorta on unix is Mac OS X for Unix Geeks :p

and does linux count?

Powerbook G5
Aug 10, 2003, 03:21 PM
Sure! The O'Reilly book seem to be pretty good. I am also reading Mac OS X in a Nutshell and it lays out all the details of the system along with quite a few Unix commands in a very logical and plain sort of way. Linux looks interesting, too. I remember before I switched I looked seriously into running a Linux/X Windows enviroment on my PC after wanting desperately to rid myself of Microsoft Windows.

janey
Aug 10, 2003, 03:26 PM
in Powerbook G5's sig
kill -9 windows :D
ummm i think that you're using it incorrectly, it's supposed to by PID not by name :p
nevertheless, it's very funny :)

Powerbook G5
Aug 10, 2003, 03:32 PM
Well I don't know the process ID number, so the name will have to do :)

Doctor Q
Aug 10, 2003, 03:41 PM
Maybe this will do:

# kill -9 `cat /var/run/windows.pid`

Powerbook G5
Aug 10, 2003, 03:45 PM
This is why I am still a newbie with Unix. :)

Doctor Q
Aug 10, 2003, 07:27 PM
Even though it's a joke, I'd rather be helpful than cryptic, so i'll explain what # kill -9 `cat /var/run/windows.pid` means, in case anybody is interested. It combines a few basics from the world of Unix.

1. Unix processes can send signals to each other, many of them for telling another process when and how to stop, i.e., signal #1 (HUP, for hangup), signal #2 (INT, for interrupt), signal #3 (QUIT), signal #6 (ABRT, for abort), signal #9 (KILL), signal #15 (TERM, for terminate), and signal #17 (STOP). You can see a list of the most common signals by typing kill -l (that's a letter "el" after the dash). You can also peek at file /usr/include/sys/signal.h for the complete list.

2. There are conventions for what a program does when it receives each of these signals. One convention is enforced by the operating system: Signal #9 (KILL) is the only one of these signals that a progarm cannot choose to ignore, so sending signal 9 (i.e., sending a KILL signal) is a practically foolproof way to stop a process (program) that is running.

3. To send a signal to a process that is not your own, you must be "superuser", whose shell prompt is usually a # instead of a % or $. That's why there is a # shown before the command. You don't type the # but you will see it.

4. The shell command kill is used to send signals. It is named after the KILL signal, but it can send any signal. You tell it the signal name or signal number along with the process ID number (PID) of the process to be signaled. For example, the command kill -HUP 1234 sends a HUP (hangup) signal to the process with process ID number 1234. The command kill -9 1234 is the same as kill -KILL 1234. Why use a number when you can use the name? Because you save a few keystrokes!

5. But how do you know what process ID number to use? Suppose you want to kill a processing running a program named windows. You could use commands like top or ps -aux to find out the PID. But some programs have a nice habit of writing their own PID into a file in the /var/run directory, which is intended for that purpose. For example, the web server (named httpd) writes its own PID to file /var/run/httpd.pid. Try it! Peek at that file and look for that number in the ps -aux display.

6. The cat command displays the contents of a file, so if there was really a program named windows that wrote its own PID to /var/run/windows.pid, you could use the command

cat /var/run/windows.pid

to display that process ID number.

7. In a shell command, you can nest one command within another command by enclosing the inner command in backquote marks. A command of the form

command1 fee fi `command2 poo bah` fo fum

will execute the command

command2 poo bah

and then insert whatever command2 outputs into the command1 line. If command2 poo bah outputs the word hello then the shell would execute the command

command1 fee fi hello fo fum

So...

Put it all together and you have a shell command that finds the process ID number of the windows process and sends it a KILL signal to terminate it:

# kill -9 `cat /var/run/windows.pid`

Nothing to it!

Powerbook G5
Aug 10, 2003, 07:33 PM
And this, my friends, is when the Unix user goes "Duh". :D I know that someday I'll be able to do this like second nature, but until then, I must hit the books.

And before I forget, thanks for the detailed explaination, that does help to explain the reasoning behind what makes the command do what it does.