# Terminal Commands --



## Trip (Apr 6, 2002)

I've recently received quite a few e-mails and private messages asking me to make this thread and keep it up for a while, so here it is, it will be made sticky for exactly 1 week!

In this thread post important or VERY useful terminal commands you use or have used! Any commands are welcome, this thread is for those programmers out there who are planning on implementing terminal or UNIX commands into their projects.

Enjoy.


----------



## nkuvu (Apr 6, 2002)

Well, the most useful unix command that I use is ls.    Sorry, I couldn't resist taking the easy ones.  Also in my personal unix toolbox are the commands chmod and cd.

Aren't you glad that not everyone on this site is as literal as I am? 

Maybe I should have written down useful _obscure_ unix commands, but that wouldn't have been as fun.


----------



## jesnil (Apr 7, 2002)

This is my top 5, used commands.
(not including filesystem-commands like ls, rm, cd etc.).

#1 *top* (better than ProcessViewer)
#2 *kill* (same as above)
#3 *ps* (process status)
#4 *locate* (faster than Sherlock on my G3)
#5 *grep* (same as above for searching inside files)

And the commond that I never EVER use is:

*banner* (just test it)

If you dont know what all of this commands does use the #6 best command *man*.


----------



## vm.mayer (Apr 8, 2002)

I have a bunch of perl scripts that I routinely use at both work and home.

fpid - Essentially a ps -aux piped to a grep.
   Syntax:: fpid search_string
   Usage:: allows you to quickly scan the full list of processes for a specific
                string (which may appear anywhere in the ps output)

kpid - Same as fpid, but issues a kill -9 to every match.

clean - Removes all core, *~, *.bak, etc files from the current directory.


I also have rolled a couple of ksh functions which allow me to "bop" around
  my "cd history" easily.  (These are more powerful than pushd/popd in that
  I can popd without ever having pushd'd... and to any directory that I've
  visited in the current shell.)

Overwrote cd to create a tracking of visited directories.
Wrote popd to parse the cd history and "jump" back to the users request
  (specified either on the command line or as a response to a prompt
    listing the history)


I would be more than glad to post my source for these if anyone cares. 

mike


----------



## Trip (Apr 9, 2002)

I've got a quick question of my own if ya can help me out here: what is the return string called whenever you type a command into the terminal? Is it 'output'? err...get what I'm asking?


----------



## xoot (Apr 9, 2002)

> _Originally posted by Trip _
> *I've got a quick question of my own if ya can help me out here: what is the return string called whenever you type a command into the terminal? Is it 'output'? err...get what I'm asking? *



Ummm... I don't really know about that... 

But the commands that I like are:

*cvs
cat
pico
grep
man
uptime
w*

Especially when one user is on ttyp2 and i'm on ttyp1:
*cat > /dev/ttyp2*

The result: Hey! Who's typing on my screen?!?!


----------



## nkuvu (Apr 9, 2002)

> I've got a quick question of my own if ya can help me out here: what is the return string called whenever you type a command into the terminal? Is it 'output'? err...get what I'm asking?


You mean STDOUT?  That's the handle which most processes use to write the default messages.  There's also STDERR, which gets most errors.  Is this what you are asking?


----------



## lethe (Apr 10, 2002)

maybe you mean '$?'  it is the exit status of the last command...


----------



## Trip (Apr 10, 2002)

Thanks turtle-man! You've saved my day!


----------



## Koelling (Apr 14, 2002)

is that the command for outputting a file to the screen? My CS teacher was doing something in DOS and he wanted to read the contints of a file that was created by fprintf() in C so he used the DOS command TYPE. What would it be for us?


----------



## nkuvu (Apr 14, 2002)

(type == cat) && (type == less)

cat my_file spews to screen.  Pipe it through more or less to stop at the end of the screen:
cat my_long_file_that_scrolls_off_the_screen | less

Alternatively, you can use less to do the same thing:
less my_long_file_that_scrolls_off_the_screen


----------



## nkuvu (Apr 14, 2002)

STDOUT and STDERR are file handles, not commands.

In C, you'd use them like
fprintf(STDOUT, "My output text");

Which of course would be silly, since printf defaults to STDOUT.  But you could do something like Perl's warn which prints to STDERR:
fprintf(STDERR, "Kernel Panic!");

Note that those may need to be printf statements instead of fprintf's -- it's been a while since I have done ANSI C coding...


----------



## Koelling (Apr 14, 2002)

Thanks for the help with cat... I wondered what that did too but I didn't connect the two in my head.

yeah fprintf usually refers to a file in C, where as printf("hello world"); is the default to print to console out.


----------



## nkuvu (Apr 14, 2002)

Here's the relevant section from the manpages:


> The printf() family of functions produces output according to a format as described below.  Printf() and vprintf() write output to stdout, the standard output stream; fprintf() and vfprintf() write output to the given output stream


So technically fprintf is designed to write to file _streams_, which include STDOUT and STDERR.  And printf doesn't do what I thought it did, give you the option to send its output to another stream other than STDOUT.


On the hunt for more nits to pick...


----------



## nkuvu (Apr 14, 2002)

I just read over this thread again, and remembered something I wanted to point out to Unix newbies.  There is a find command, but it doesn't do what you might expect, which is find files.  Instead, it goes through each file in a directory structure and does something to it.  You specify what it does.  Enter man find for more information.

To easily find files, use locate (which was actually pointed out by jesnil first).

And one other annoying command (similar to cat > /dev/tty2) is wall.


----------

