wc (will count things such as lines of text and number of characters)
Now if you add a pipe you can do things like this:
% ls -al | wc
16 137 884
The directory listing that would have been displayed was a total of 16 lines and those lines had total of 137 'words' (anything broken by a tab or a space) and the total number of bytes that made up the listing was 884.
The pipe | can (and is) used ALOT and allows for some really cool things.
Another cool symbol is >
% ls -al > mydirectory
Will take the directory listing that would have normally been output to the screen and instead redirect it to a file called mydirectory.
You can then open that file in any text editor you like.
One more cool symbol is <
%wc < mydirectory
The above command will PUSH the text found in that text file I just created in the last example INTO the unix app called wc (see above). The output from wc was displayed to the screen as usual.
%wc < mydirectory > newfile
In that last example the output from wc was NOT displayed to the screen but instead written to a file called newfile.
While these examples are kinda lame they do show some of the really wild things you can do with unix.
Just to clarify to newbs, the pipe takes the output from the first program and sends it to the second program as input. Neither of these programs know what is going on. In his example, ls still thinks that it is writing to the screen and ws thinks that the input is coming from the user. The OS takes care of routing the output and input around.
An alternative way of piping would be:
ls -al > mydirectory
ws < mydirectory
These two commands together perform the same things as the pipe, only the pipe doesn't create a file as a middleman.
A couple of things, and these took me a while to figure out and learn:
Control-C kills an app. So let's say you are surfing the web in w3m, and it stalls while loading a page. Control-C, and you are back in the terminal, ready to give another shell command.
Control-Z : Makes a process dormant. So let's say, even though you are on OSX, you are a confused newbie, and are compiling the linux kernel... CPU is maxxed out. But you just downloaded a bunch of mpegs of, let's say, groverat's mother. You can't play them back at a decent FPS while compiling a kernel. So to 'postpone' the compile, you hit:
Control-Z . You can either continue using the same term, or just leave it. When you want to resume the compile, just type either:
fg to 'foreground' the app compiling
bg to 'background' the app compiling
%2 (I think, I forget) starts a second dormant app (assuming the is a second dormant app).
Keen, eh?
But the real magic of bash is 'bash scripting', just like serrano's NPR aliases (a bash script and an alias are essentially the same). I've got bash scripts coming out the yin-yang. They're not for OSX, however, so you can't have them.
Basically, you write a string of commands to a text file using nano/pico/whatever, then chmod + x them. I then move them to /usr/local/sbin or similar, and they can be executed like any other command.
telnet, ftp, and ipfw are some of the ones i use as well...the best thing is to be able to compile *nix source code (./configure, make; make install) and run free software! (web analyzer or what not)
As of late, I've found lsof to be useful in finding open files. Ever have a disk image that just refuses to eject because it claims a file is open? Use lsof to find that open file.
At work, we've got an Apple demo running on some of the machines, and the demo software doesn't show up when I bring up the Force Quit menu. We had to quit the demo when updating the machines to Jaguar, so it was a bit of a dilemma.
So, I opened Terminal and ran top to find out which Process ID (PID) it was using, then kill to get rid of it. Voila! No more demo.
At home, I use sudo occasionally to get rid of stubborn files, by logging in as root to perform an rm (remove) command.
Oh, and ls is the one you'll use the most, for listing the directory contents, and cd for changing directories.
Comments
<strong>Don't forget our friend the pipe!
ls -al (will do a 'directory listing')
wc (will count things such as lines of text and number of characters)
Now if you add a pipe you can do things like this:
% ls -al | wc
16 137 884
The directory listing that would have been displayed was a total of 16 lines and those lines had total of 137 'words' (anything broken by a tab or a space) and the total number of bytes that made up the listing was 884.
The pipe | can (and is) used ALOT and allows for some really cool things.
Another cool symbol is >
% ls -al > mydirectory
Will take the directory listing that would have normally been output to the screen and instead redirect it to a file called mydirectory.
You can then open that file in any text editor you like.
One more cool symbol is <
%wc < mydirectory
The above command will PUSH the text found in that text file I just created in the last example INTO the unix app called wc (see above). The output from wc was displayed to the screen as usual.
%wc < mydirectory > newfile
In that last example the output from wc was NOT displayed to the screen but instead written to a file called newfile.
While these examples are kinda lame they do show some of the really wild things you can do with unix.
Dave
[ 07-29-2002: Message edited by: DaveGee ]</strong><hr></blockquote>
Just to clarify to newbs, the pipe takes the output from the first program and sends it to the second program as input. Neither of these programs know what is going on. In his example, ls still thinks that it is writing to the screen and ws thinks that the input is coming from the user. The OS takes care of routing the output and input around.
An alternative way of piping would be:
ls -al > mydirectory
ws < mydirectory
These two commands together perform the same things as the pipe, only the pipe doesn't create a file as a middleman.
[ 07-30-2002: Message edited by: pyr3 ]</p>
nmap - THE port scanner
nc - port connection swiss army knife
> - basicaly your print to file command
| - pipe is God! pipes results from one app into another
grep - search through files for text patterns
curl - download swiss army knife
ftp - duh
ssh - your non gaping security hole telnet
pico - for my rudimentary shell scripting and alias binding
personal aliases
l - a more complete directory listing (thanks stimuli)
atc - downloads NPR's All Things Considered .smil
me - same as above, except Morning Edition
[ 07-31-2002: Message edited by: serrano ]</p>
sudo
mv
rm
nslookup
whois
Sing along, you know the lyrics...
Control-C kills an app. So let's say you are surfing the web in w3m, and it stalls while loading a page. Control-C, and you are back in the terminal, ready to give another shell command.
Control-Z : Makes a process dormant. So let's say, even though you are on OSX, you are a confused newbie, and are compiling the linux kernel... CPU is maxxed out. But you just downloaded a bunch of mpegs of, let's say, groverat's mother. You can't play them back at a decent FPS while compiling a kernel. So to 'postpone' the compile, you hit:
Control-Z . You can either continue using the same term, or just leave it. When you want to resume the compile, just type either:
fg to 'foreground' the app compiling
bg to 'background' the app compiling
%2 (I think, I forget) starts a second dormant app (assuming the is a second dormant app).
Keen, eh?
But the real magic of bash is 'bash scripting', just like serrano's NPR aliases (a bash script and an alias are essentially the same). I've got bash scripts coming out the yin-yang. They're not for OSX, however, so you can't have them.
Basically, you write a string of commands to a text file using nano/pico/whatever, then chmod + x them. I then move them to /usr/local/sbin or similar, and they can be executed like any other command.
It is pretty sweet.
dunno if this was already in here or not, but here's another good one.
sudo update_prebinding -root /
speeds stuff up nice...
<strong>
sudo update_prebinding -root /
</strong><hr></blockquote>
When you put that in will it ask you for your password? Thanks.
So, I opened Terminal and ran top to find out which Process ID (PID) it was using, then kill to get rid of it. Voila! No more demo.
At home, I use sudo occasionally to get rid of stubborn files, by logging in as root to perform an rm (remove) command.
Oh, and ls is the one you'll use the most, for listing the directory contents, and cd for changing directories.
[ 10-01-2002: Message edited by: Kesh ]
[ 10-01-2002: Message edited by: Kesh ]</p>
make love
[ 10-03-2002: Message edited by: ThinkingDifferent ]</p>
both a set of commands that are used for uploading and downloading files via FTP and HTTP, as well as other data retrieval tasks over the ether.
Jaguar has not /usr/local/bin in his default PATH.
So maybe you can't use (or have some problem with) some of the commands cited above if running jaguar (ex.: gcc and other compilers......).
To add that path to the default ones, simply write:
setenv PATH /usr/local/bin:$PATH
in the file /etc/csh.login
(you have to be root......)
<img src="graemlins/smokin.gif" border="0" alt="[Chilling]" />