The macosxhints Forums

The macosxhints Forums (http://hintsforums.macworld.com/index.php)
-   UNIX - Newcomers (http://hintsforums.macworld.com/forumdisplay.php?f=15)
-   -   What "intresting" commands/programs can i do in terminal? (http://hintsforums.macworld.com/showthread.php?t=5332)

icenw 09-06-2002 04:25 PM

What "intresting" commands/programs can i do in terminal?
 
well... i've play'd with linux on my X86 and now am starting to play with terminal on OSX,

sofar i'ce come accross

ping
emacs
pico (looks like the old word star :))

and thats about it, apart from the cd, ls and the like


i'm looking for things to play with without paying money for a book or program :) and if i happen to lean some cool commands that'll help my unix side all the better :)

Craig R. Arko 09-06-2002 09:59 PM

Magic 8 Ball says: Do a search here for fink and you may find the gateway to many hours of UNIXy fun. :)

wolfie85032 09-07-2002 01:38 AM

Learn about find. May uses! In my job, I frequently need to find files that have not been used for a certain time frame. This is an example.

find -mtime +183 -daystart -name '*' -printf '%p\t%s\n'

Or how about finding large files. This one finds files larger than 15meg

find -size +15360k -name '*' -printf '%p\t%s\n'

osxpez 09-07-2002 05:14 AM

Take a good look at grep, cut, head and tail.

Titanium Man 09-07-2002 05:32 PM

Check out 'man open'. I've been trying to figure out a comparable command on my Linux box, and haven't been able to do so so far. But the OS 10.2 version of open lets you do all the old stuff from OS 10.1 (launch apps, open docs, etc with specified apps) and now you can connect to websites too. For example, if I want to search for something on google.com and I'm in the Terminal I type

gsearch <mysearch string>

and my default browser opens with the results.


#! /bin/sh
#gsearch, a script to do a google search in your default browser

open="/usr/bin/open"
echo="/bin/echo"
sed="usr/bin/sed"

open http://www.google.com/search\?hl=en\&q=$(echo "$*" | sed 's/ /+/')


Welcome to OS X.

rusto 09-07-2002 05:40 PM

When was the last time you played Adventure?

In terminal, type:

Code:

emacs -batch -l dunnet
:)

Glanz 09-07-2002 06:40 PM

"top" & "ps ax"....
 
Two I find very useful are the

"top" command

and the "ps ax" command...

You can kill a run-away process easily by listing the # of the process in the left-hand column with the "kill" command.

Ps displays a header line followed by lines containing information about your processes that have controlling terminals. This information is
sorted by controlling terminal, then by process ID.
top displays an ongoing sample of system usage statistics. It operates in various modes, but by default shows cpu utilization and memory usage for each process in the system.

Just type "man ps"

and "man top" to find out more....

mervTormel 09-07-2002 09:20 PM

Quote:

Originally posted by Titanium Man
gsearch <mysearch string>

#! /bin/sh
#gsearch, a script to do a google search in your default browser

open="/usr/bin/open"
echo="/bin/echo"
sed="usr/bin/sed"

open http://www.google.com/search\?hl=en\&q=$(echo "$*" | sed 's/ /+/')
had a few problems with that script there, TiMan...
Code:

$ cat goog

#!/bin/sh

# file: goog - google.com search

open="/usr/bin/open"
echo="builtin echo"
sed="/usr/bin/sed"

ss=$($echo "$*" | $sed 's/ /+/g')

#echo $ss

googThis=http://www.google.com/search\?hl=en\&q=$ss

#echo $googThis; sleep 2

$open $googThis


Titanium Man 09-07-2002 10:14 PM

Weird. I just tried the version I posted (the url shouldn't be underlined, though) and it works. I just tried the version you posted, merv, and nothing happened. /bin/sh is /bin/sh, no? Unless something has changed in your version of 10.2.1? Shrug. At any rate, I forgot to mention earlier that I also use open to look up words (eng omphaloskepsis):

% cat eng

#!/bin/sh

/usr/bin/open http://www.dictionary.com/search\?q="$*"

and translate words:

%cat spen

#!/bin/sh

/usr/bin/open http://www.diccionario.com/cgi-bin/esp-engl.php\?query="$*"

from English to Spanish:

% cat ensp

#!/bin/sh

/usr/bin/open http://www.diccionario.com/cgi-bin/engl-esp.php\?query="$*"

These might actually work on other people's systems (assuming they'd rather not launch Sherlock 3) :D

mervTormel 09-07-2002 10:24 PM

¡no me gusta!
 
hmm. what does it look like if you uncomment the echos and comment out the open?

Titanium Man 09-08-2002 10:47 AM

Well, goog works this morning. Either it was too late when I was testing it last night, or some script gremlins have changed something in my system as I slept. I think it was the latter. But I wonder why the version I originally posted didn't work? /bin/echo vs builtin echo? Both 'gsearch fish hats' and 'goog fish hats' now work on my rig.

Glanz 09-08-2002 12:25 PM

Re: What "intresting" commands/programs can i do in terminal?
 
Quote:

Originally posted by icenw
well... i've play'd with linux on my X86 and now am starting to play with terminal on OSX,
Well my friend, I decided to do you a great service by communicating the following link http://www.macdevcenter.com/pub/ct/51 which is the R E A L deal!

sao 09-08-2002 01:46 PM

Timan, MervTormel,

Thanks for the scripts.

Have you tried an 'open' replacement called 'launch' ?

You can install it with Fink, launch doesn't have any dependencies (works with 10.1 + dev tools) and I find it very useful by itself, but is even better when used in scripts.

It is essentially an OS X-savvy version of 'file', 'which', and 'open'. It will open applications, open/print documents, launch URLs, show file info (shows info about any item on disk, including its file type, creator, data and resource fork sizes, dates and bundle ID), etc.

Code:

152 [Sao @/Users/pm] % launch
usage: launch [-npswbmhCX] [-c creator] [-i bundleID] [-u URL] [-a name] [document ...]
  or: launch [-npflswbmhCX] item ...
  -n            print matching paths/URLs instead of opening them
  -p            ask application(s) to print document(s)
  -f            display information about item(s)
  -l            launch URLs (e.g. treat http:// URLs as Web sites, not WebDAV)
  -w            wait for application to finish opening before exiting
  -b            launch application in the background
  -h            hide application once it's finished opening
  -C            force CFM/PEF Carbon application to launch in Classic
  -X            don't start Classic for this app if Classic isn't running
  -c creator    match application by four-character creator code ('ToyS')
  -i bundle ID  match application by bundle identifier (com.apple.scripteditor)
  -u URL        open application at file:// URL (NOT RECOMMENDED for scripts)
  -a name      match application by name (NOT RECOMMENDED, very fragile)
'document' may be a file, folder, or disk - whatever the application can open.
'item' may be a file, folder, disk, or URL.

launch 1.0a9 (c) 2001-02 Nicholas Riley <http://web.sabi.net/nriley/software/>.
Please send bugs, suggestions, etc. to <launchsw@sabi.net>.

I adapted 'goog' to use 'launch' and works very well.


Cheers...

osxpez 09-08-2002 02:27 PM

Hey, launch sounds like a dream come true. Though fink fails compiling it for me. I think I have the April 2002 dev tools (on 10.1.5).

Those google scripts reminds me of "surfraw". Have you tried that one? It brings the cli interface to google, webster, jeeves and lots of more web enabled services. I should be quite easy to add a "use launch" option to the surfraw scripts. Which would enable results to show up in a new tab in Chimera. "surfraw" is in stable so installing it is a breeze:

$ sudo apt-get install surfraw

osxpez 09-08-2002 02:35 PM

Quote:

Originally posted by Titanium Man
But I wonder why the version I originally posted didn't work?
That's probably because you had a space after the shebang:
Code:

#! /bin/sh

sao 09-08-2002 03:09 PM

osxpez,

I installed surfraw. Wow! Thanks for the tip.

To install 'launch' if you are still in 10.1.5, you could always move /Developer to /Dev_2002-04, then reinstall the old December devtools (and the small update) if you have them around. But maybe too much of a hassle.

Code:

152 [Sao @/Users/pm] % surfraw --help
W              -- Activate Surfraw defined web-browser
altavista      -- Search the web using Altavista (www.altavista.com)
amazon          -- Search the amazon.com bookstore
appwatch        -- Search entries on Appwatch (www.appwatch.com)
ask            -- Question the web using Ask Jeeves (www.ask.com)
austlii        -- Search Australian Law docs (www.austlii.edu.au)
britannica      -- Look up word in Encyclopedia Britannica (www.britannica.com)
cite            -- Search computer science papers (www.researchindex.com)
cnn            -- Search on CNN (cnn.com)
currency        -- Abuse the Universal Currency Converter (www.xe.net/ucc)
debbugs        -- Search the debian BTS (bugs.debian.org)
debcontents    -- Search contents of debian packages(packages.debian.org)
debpackages    -- Search debian packages (packages.debian.org)
deja            -- Search usenet using Deja News (www.dejanews.com)
excite          -- Search on Excite (www.excite.com)
fast            -- Search the web using FAST Search (www.alltheweb.com)
filesearching  -- Search files on filesearching (www.filesearching.com)
freebsd        -- Search FreeBSD related information (www.freebsd.org)
freshmeat      -- Search Freshmeat (www.freshmeat.net)
ftpfind        -- Search files on ftpfind (www.ftpfind.com)
ftpsearch      -- Search files on ftpsearch (ftpsearch.lycos.com)
google          -- Search the web using Google (www.google.com)
jake            -- Search journal/databases in jake (jake.med.yale.edu)
netbsd          -- Search NetBSD related information (www.netbsd.org)
openbsd        -- Search OpenBSD related information (www.openbsd.org)
pubmed          -- Search medical/molbio databases (www.ncbi.nlm.nih.gov)
raging          -- Search the web using Raging (www.raging.com)
rhyme          -- Search for rhymes et al using Lycos Rhyme (rhyme.lycos.com)
scaleplus      -- Search Australian Law using ScalePlus (scaleplus.law.gov.au)
slashdot        -- Search stories on Slashdot (www.slashdot.org)
slinuxdoc      -- Search entries in LDP (www.linuxdoc.org)
sourceforge    -- Search SourceForge (www.sourceforge.net)
stockquote      -- Get a single stock quote (multiple providers)
sundocs        -- Search docs on Sun.com (docs.sun.com)
sunsolve        -- Search public docs on Sunsolve (sunsolve.sun.com)
swhois          -- Search Whois (www.geektools.com)
thesaurus      -- Look up word in Merriam-Webster's Thesaurus (www.m-w.com)
translate      -- Translate human languages (various providers)
webster        -- Look up word in Merriam-Webster's Dictionary (www.m-w.com)
wetandwild      -- Real time weather information (many sources)
woffle          -- Search the web using Woffle (localhost:8080)
xxx            -- Superior XXX, hot and ready to press (arXiv.org)
yahoo          -- Search Yahoo categories (www.yahoo.com)

Now I will go to play with surfraw and launch.


Cheers...

mervTormel 09-08-2002 03:17 PM

osxpez, no, a space after she-bang is fine

TiMan, i forgot to point out the "troubles" i had with your script

a) you define variables, like open=/usr/bin/open , but then never reference the variable in the script.

open != $open

b) your sed lacked the 'g' global replacement switch and only replaced the first space with plus

oddly, whenever i test a google thingy, i search for meat+hats

Titanium Man 09-08-2002 03:57 PM

sao, that little google thingy was something I originally put together after installing 'launch' a few months back. I figured that since open now has some more bells and whistles, the script would be accessible for the folks who hadn't installed fink (yet) ;) I had also heard of surfraw, but it seemed like too much for what I was wanting to do...maybe I'll have to look into it again, though, 'cause it does look pretty cool. merv, thanks for the tip. There I was trying avoid problems by defining the full path of the commands I was using. A simple one liner:

open http://www.google.com/search\?hl=en\&q=$(echo "$*" | sed 's/ /+/g')

probably would have worked. Also thanks for pointing out my missing 'g' in sed. I had originally done sed 'y/ /+/', but when I inserted the s instead of y I never added the g. How's that for alphabet soup. Oh, and I figured out why your script (ie my brain) didn't work. I cut and pasted it into something I had stupidly called 'test' and when I did 'test fish hats' (instead of ./test fish hats) test the shell builtin didn't have anything to say about fish hats.

But on to the original question, of cool things to do in the Terminal:

softwareupdate
sw_vers
AppleSystemProfiler

Last, but not least, here're some cool things that I've found scouring the web (sorry I can't rememer where; I'd love to give the authors credit). Also sorry about the long post.

% cat colors
#!/bin/bash
#
# This file echoes a bunch of color codes to the
# terminal to demonstrate what's available. Each
# line is the color code of one forground color,
# out of 17 (default + 16 escapes), followed by a
# test use of that color on all nine background
# colors (default + 8 escapes).
#

T='gYw' # The test text

echo -e "\n 40m 41m 42m 43m\
44m 45m 46m 47m";

for FGs in ' m' ' 1m' ' 30m' '1;30m' ' 31m' '1;31m' ' 32m' \
'1;32m' ' 33m' '1;33m' ' 34m' '1;34m' ' 35m' '1;35m' \
' 36m' '1;36m' ' 37m' '1;37m';
do FG=${FGs// /}
echo -en " $FGs \033[$FG $T "
for BG in 40m 41m 42m 43m 44m 45m 46m 47m;
do echo -en "$EINS \033[$FG\033[$BG $T \033[0m";
done
echo;
done
echo

cat mandelbrot2
#!/bin/zsh
#
#mandelbrot fractal
#
((columns=COLUMNS-1, lines=LINES))
((colour=0))

for ((b=-1.5;b<=1.5;b+=3.0/lines));do
for ((a=-2.0;a<=1;a+=3.0/columns));do

for (( p=0.0, q=0.0, i=0 ; p*p+q*q < 4 && i < 32 ; i++));do
((pnew=p*p-q*q+a, q=2*p*q+b, p=pnew))
done

((colour=(i/4)%8))

echo -n "\\e[4${colour}m "
done
done

sao 09-08-2002 04:11 PM

Surfraw working with links is fast_______________!!!! :)

Cheers...

sao 09-08-2002 11:08 PM

If you don't have Fink installed, you can download 'launch' source and binary in gzipped tar format (there is no installer) from this link and follow the install instructions in the README file :

http://web.sabi.net/nriley/software/


Cheers...

pyrohotdog 09-09-2002 01:29 AM

another fun one
 
"banner" is always fun.:)

osxpez 09-09-2002 04:32 PM

launch is way cool. Thanks for the hint!

I said that I thought it would be quite easy to pactch surfraw to use launch and that way reach Chimera. In fact is isn't even needed to patch it:

$ google -browser='launch Chimera' java os x
$ britannica -browser='launch Chimera' platypus

Make a few aliases for this if you think it's to much typing. (Please share those aliases).

sao 09-09-2002 05:32 PM

osxpez,

Thanks for the use. I was using in X11:

google -browser=mozilla osx
and
google -browser=mozilla -search=mac osx

And in OSX :
google -browser='launch -l' osx (will open your default browser)

Tomorrow will try some more and share.


Cheers...

ynolo 10-22-2002 12:59 AM

Surfraw
 
is there any way not to use Lynx with Surfraw. I would like to open either IE or Netscape/Mozilla.

Any ideas?

sao 10-22-2002 06:45 AM

I installed 'launch' with Fink and use it together with surfraw to open my default browser, then use different aliases:

Code:

alias wet      'wetandwild singapore -browser='launch''
 alias wet1    'wetandwild -browser='launch''
 alias wetn    'wetandwild New York -browser='launch''
 alias go      'google -browser='launch''
 alias bri      'britannica -browser='launch''


Cheers...


All times are GMT -5. The time now is 10:35 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.