PDA

View Full Version : Terminal Tricks


Gargoyle
2004-05-30, 04:26
I have been using Linux and the likes for a few years now and never came across this little gem before. Hope you find it useful

cd -

This takes you to the previous directory you were in. not the parent like ".." does. So if you were in "/Users/fred/Desktop" then you cd to "/Users/bob/Desktop". Doing a "cd -" will take you back to freds desktop directory.

Enjoy.

chucker
2004-05-30, 05:49
You can even combine those. cd -- will take you *two* steps back.

SilentEchoes
2004-05-30, 09:27
Well would you look at that. I dunno though its not very often I go skipping around to random directories that are not parents of each other and need to go back. If this had happened to me in the past odds are I cd'ed the entire path in which case I would just hit the up arrow the desired number of times and cd to that dir again.


Either way thanks for the tip

curiousuburb
2004-05-30, 12:41
terminal typing is ok.
being able to drag and drop directory listings into terminal directly from finder is better.

and of course there's always the coolest terminal trick for sci-fi fans.

telnet towel.blinkenlights.nl

set your terminal window translucency and sit back and watch

thuh Freak
2004-05-30, 18:48
similar to that 'cd -' trick is the pushd & popd pair, and dirs. if you are using the bash shell (and presumably others), pushd will act just like cd. but, popd acts like 'cd -'. using these names, i find, helps amplify the stack nature of the directories. and a call to 'dirs' lists the stack, incase you want to go far back in the annals of history, and have lost your way. oh, perhaps worthy of mention, pushd and popd aren't exactly like 'cd'. they are like 'cd $@;dirs', b/c after going to a dir, they list out the contents of the directory stack.

Wickers
2004-05-30, 18:52
Neat,

Kinda useful, I like it.

But this thread should be renamed to "Terminal Tricks" because nothing pointed out so far is limited to just OS X.

:)

Gargoyle
2004-05-31, 04:31
Bah, editing the title in the first post still does not change the title of the thread... Which is probably a good thing... :D

Do us a favour mod, change this to just "Terminal Tricks" and other people can keep posting new tricks.

Ta

Mac+
2004-06-01, 08:16
I have been using Linux and the likes for a few years now and never came across this little gem before. Hope you find it useful

cd -

This takes you to the previous directory you were in. not the parent like ".." does. So if you were in "/Users/fred/Desktop" then you cd to "/Users/bob/Desktop". Doing a "cd -" will take you back to freds desktop directory.

Enjoy.
Ahhh Gargoyle - thank you... I was wishing for something like this, this week - I was getting tired of going into a directory and then coming back up via the same path before traversing a different directory.

Dragging form the finder is cool, but so is this. Thanks for enlightening me. :)

ZO
2004-06-02, 04:10
how do I force quit an app that does NOT want to quit?

Also, when im in terminal, and run TOP is there a way to see more of the application names? There are multiple instances of "Apple" and Microsoft", etc...

thuh Freak
2004-06-02, 07:47
how do I force quit an app that does NOT want to quit?

Also, when im in terminal, and run TOP is there a way to see more of the application names? There are multiple instances of "Apple" and Microsoft", etc...
to the first item, here's what you do. first you have to discover the "process id" (often called the 'pid'). you can find this in `top`, or in `ps ax`. if the program is not a cocoa app (or more specifically, if it is a command line program), you won't need the pid. you could simply do `sudo killall programName`. that doesn't always work for cocoa apps though. so, once you find the pid, you do `sudo kill pid`. sometimes neither of those will work. if they spit an error message, like "no process was found" then you got the wrong prog name or pid. at this point, if the program didn't die, you should know that there are 31 ways to 'kill' a program. not all of them are fatal, but different programs react to each differently, and a lot of the time, trying to kill a program with all of these will eventually get it. copying and pasting the following into terminal (and replacing the 'pid' at the end) will attempt to kill a program in all kinds of heinous ways. if this doesn't work, you're pretty much sol. (note: you can also replace 'kill', with 'killall' and 'pid' with 'programName').
for f in 0 1 2 3; for d in 0 1 2 3 4 5 6 7 8 9; sudo kill -$f$d pid

to the second item, if you stretch your terminal window wider you can see more. moving beyond that, i don't think top gives you many options. actually, there should be a configuration bit somewhere in there to cut or alter some of the columns. i dont remember how to do that though. `ps ax` has less wide output (iirc), and you can avoid the width problem by 'piping' it to less, ie `ps ax | less`. then you should be able to get the full file names.

chucker
2004-06-02, 08:17
how do I force quit an app that does NOT want to quit?

1. Get a tool that can assign an AppleScript to a keyboard short cut. I use alt-control-slash for kill, and alt-control-shift-slash for force-kill.
2. Create two AppleScripts:

tell application "System Events" to set theApp to name of the first process whose frontmost is true
do shell script "killall " & quoted form of theApp

and

tell application "System Events" to set theApp to name of the first process whose frontmost is true
do shell script "killall -9 " & quoted form of theApp

3. Save the first as "Kill Frontmost Application.scpt" and the second as "Force-Kill Frontmost Application.scpt".
4. Assign keyboard shortcuts.

Now, whenever you have an application that seems to hang, try Kill first, and if that doesn't seem to do the job, Force-Kill definitely should.

(If that still doesn't do it, then your entire GUI is hanging.)