Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Dynamic terminal window titles UNIX
I learned about this in college to make the title of xterms dynamic and found that the same method works with Terminal.app. I've created some aliases that allow me to have the title of the window reflect the machine that I'm on and current working directory of the shell, or of what file I'm editing. If you'd like a title on your terminal window that changes based on what you're doing, read the rest of this article...
read more (347 words)   Post a comment  •  Comments (7)  
  • Currently 0.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (0 votes cast)
 
[14,388 views] Email Article To a Friend View Printable Version
Another way to get to your home directory UNIX
I don't know why but the tilde shortcut "~" to access my User Folder doesn't work for me (I get a "Permission Denied" alert). I've just discovered that "cd home" does exactly the same: it moves you to the user directory...I don't know if it's a common Unix feature or another alias made by Apple but it's neat!

descoff.
  Post a comment  •  Comments (3)  
  • Currently 0.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (0 votes cast)
 
[2,809 views] Email Article To a Friend View Printable Version
Use 'ShellShell' to learn UNIX UNIX
Robert Woodhead has written a very useful little utility called ShellShell, which basically wraps an Aqua GUI around the terminal. You launch ShellShell, and then pick any one of a number of 'macros', which will execute terminal commands in a GUI.

If that wasn't enough, one of the really neat features is that ShellShell will show you the command-line version of what you've asked it to do before it runs. So you can see how you would do the same thing in the terminal. For example, ps (Process Status) is a command-line version of Apple's ProcessViewer, and it has a large number of runtime options. When you first pick ps in ShellShell, you get a dialog box with about 15 choices in it, with two defaults (show all, and include processes without terminals (ie Aqua programs)) enabled. It shows you that the command line version of this command is ps -a -x. If you then add a check to "Display information about processes associated with user..." and enter your username, the shell command box changes to read ps -a -x -Uusername. This is a great way to learn the obscure command-line options that exist for many UNIX programs.

Once you've set the options you want, you click RUN, and ShellShell returns the results in another Aqua window.

If you're new to UNIX and the command line, ShellShell is a neat way to teach yourself about various options without trying to decode UNIX "man" pages or using the sometimes dangerous "try it and see what happens" method. Best of all, ShellShell is 'legoware'; if you like it, Robert asks you to send his children some Lego pieces (you'll have to see the details on the Read Me file).

ShellShell doesn't include every UNIX command, but it includes quite a few and is easily extensible. Hopefully authors will chip in with new "macros" for the program in the future.
  Post a comment  •  Comments (2)  
  • Currently 2.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[3,082 views] Email Article To a Friend View Printable Version
A guide for compiling UNIX programs UNIX
If you're interested in learning more about how to compile UNIX programs for OS X, I found a great reference on the X4U mailing list. This tutorial will walk you through the basics of downloading, expanding, configuring, and compiling UNIX programs. It's not specific to OS X, but it's a great overview of the process.

I've also added the URL to the links section of the site.
  Post a comment  •  Comments (2)  
  • Currently 0.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (0 votes cast)
 
[2,641 views] Email Article To a Friend View Printable Version
Safer file manipulation in the Terminal UNIX
By default in OSX, terminal commands like move (mv), copy (cp) or remove (rm) can overwrite or delete existing files without prompting you whether it's really want you want to do. These commands can be dangerous to use especially when using * for designing multiple files. To be automatically prompted for confirmation before each file is processed, create yourself a .cshrc file in your home directory and put the following lines
alias mv 'mv -i'
alias rm 'rm -i'
alias cp 'cp -i'
Another thing I find very useful is to have the target directory listed automatically when issuing a cd command. This can be done as well by adding the following line in your .cshrc file:
alias cd  'cd \!*;echo $cwd; ls -FC'
For these changes to be effective, type source .cshrc or open a new terminal window.

[Editor's note: Please see this related conversation on aliases in another macosxhints' posting. Aliases can live in a number of locations; .tcsh is one of them, but the referenced article gives an alternate, (possibly better?) location for these types of files.]
  Post a comment  •  Comments (5)  
  • Currently 0.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (0 votes cast)
 
[2,804 views] Email Article To a Friend View Printable Version
View nicely formatted 'man' pages UNIX
If you'd like to read the "man" pages (UNIX manual pages) in PDF mode, here's how to do it.

The following shell script displays high quality man pages using Preview.app (or whichever PDF viewer the finder thinks to use):
#!/bin/tcsh
set m=`man -w $1`
set c=`grog $m`
$c | ps2pdf - /tmp/$1.pdf
open /tmp/$1.pdf
Save the script in your personal bin directory, e.g. ~/bin/superman. Set execute permissions: chmod +x ~/bin/superman. And then superman ls will present nicely typeset man pages.

NOTE: In order for this to work, You'll need ghostscript installed for ps2pdf.
  Post a comment  •  Comments (7)  
  • Currently 0.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (0 votes cast)
 
[5,584 views] Email Article To a Friend View Printable Version
Type Faster in Terminal UNIX
Terminal is a great app to get around your filesystem but it gets to be a pain in the hands to type those long pathnames. Here's some quick tips on typing paths or filenames in terminal.

1. If you want to get to your home directory quickly, just type ~ and hit return. You will be at the root level of you're home directory. Note if you are su'd as root you'll go to root home dir.

2. When type paths or file names, start typing the path and hit tab. Your Terminal (shell) will complete the word for you. If nothing appears to happen, hit tab again and shell will give you all the words in that path that have the partial of what you typed.Start typing again till you are past the uniqueness of the word and hit tab to finish typing the word for you. A little practice and you can navigate the CLI faster than point and clicking.

See the rest of this article for some additional examples and comments.
read more (159 words)   Post a comment  •  Comments (5)  
  • Currently 0.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (0 votes cast)
 
[4,748 views] Email Article To a Friend View Printable Version
Start file sharing from the terminal UNIX
This may be useful for some people. To start file sharing from the terminal do the following:
cd /usr/sbin
./AppleFileServer
  Post a comment  •  Comments (2)  
  • Currently 4.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[7,266 views] Email Article To a Friend View Printable Version
FTP access and non-standard shells UNIX
OS X uses the tcsh shell for the terminal. There are a number of others you can install, including bash, which is probably the most popular. If you've installed one of these alternate shells, however, you may find that your FTP access has been disabled.

There's a file called shells that lives in /etc, and it contains a list of paths to known shells. The FTP server uses this file to limit the types of shells remote users will be allowed to connect with. The problem is that if you install a shell, it may or may not go where the shells file says it will go. For example, shells lists 'bash' as installed at /bin/bash, but it would more than likely be installed in /usr/local/bin/bash). If you try to connect and have a non-authorized shell, you'll see a message that says User username access denied.

The fix is simple - edit the /etc/shells file and make sure that the proper path to your alternate shell saved in the file. This tip was seen today on the X4U mailing list...
  Post a comment  •  Comments (3)  
  • Currently 0.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (0 votes cast)
 
[4,723 views] Email Article To a Friend View Printable Version
One-line batch file renamer UNIX
This one was posted to the X4U mailing list by Dierdre M., and I think it's an incredibly useful tip, so I'm posting it here!

If you want to batch rename a bunch of files (say "foo*.jpg" to "bar*.jpg"), you might think you could just do "mv foo*.jpg bar*.jpg" in the Terminal. However, this doesn't work right since the shell expands each argument before the execution occurs. However, there's a cool way to accomplish the same result with a (more complex) command line argument.

Open a terminal, and "cd" your way to the directory of interest (or just drag the folder you want to work with onto the terminal icon in the dock; it will open in that directory). Once there, we'll run a 'test' before actually change any names. This first version of the command is "proof of concept"; it will output what will happen, without actually doing it. So to rename all those "foo*.jpg" files into "bar*.jpg" files, type:
ls foo*.jpg | awk '{print("mv "$1" "$1)}' | sed 's/foo/bar/2'
This should output a series of "mv" (the unix "move" command, which is used to rename files) lines, each one showing the old and new name for each file affected. If it all looks right, then just pipe the output to the shell to execute:
ls foo*.jpg | awk '{print("mv "$1" "$1)}' | sed 's/foo/bar/2' | /bin/sh
That should do the trick. Dierdre points out that this is an especially nice way to do it, since you get to see what will happen before you commit to it! I happen to agree with that logic completely!

To use this on your own files, you'll need to replace the references to filenames and items to be replaced in both the "ls" and "sed" portions of the script.
  Post a comment  •  Comments (21)  
  • Currently 4.33 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (12 votes cast)
 
[86,052 views] Email Article To a Friend View Printable Version