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

Using Quick Look from the Command Line UNIX
Sometimes you need to Quick Look a file, but you're in Terminal or iTerm or something. If you're dealing with images, you want to see them before you do anything. But you don't want to use the open command. That's where qlmanage comes in.
read more (149 words)   Post a comment  •  Comments (14)  
  • Currently 2.67 / 5
  You rated: 4 / 5 (27 votes cast)
[16,461 views]  View Printable Version
How to Obscure Command Line Passwords UNIX
Many command line programs, such as mySQL and Apple's Xgrid, are not OS X Keychain savvy, and require passwords in plaintext on the command line. This can also be true when entering things like SMB and AFP disk mounts from the command line. Command line text will not only appear in plain view on your screen and terminal scroll-back but it persists indefinitely in your bash history file on disk. It can even sometimes be viewed in process monitors that show your executing commands to other users. Here is a way to avoid that pitfall.
read more (437 words)   Post a comment  •  Comments (16)  
  • Currently 2.50 / 5
  You rated: 1 / 5 (28 votes cast)
[9,004 views]  View Printable Version
Rescue photos off memory cards with PhotoRec UNIX
There are a lot of good tools out there to restore data from corrupted memory cards but most of them are for Windows. I remembered using an open source command line tool for this purpose. It is called PhotoRec and is cross platform as well. Although their web site has detailed instructions on how to use the software I still wanted to share my straightforward procedure for doing so on a Mac (you are still doing it at your own risk).
read more (195 words)   Post a comment  •  Comments (4)  
  • Currently 3.27 / 5
  You rated: 4 / 5 (26 votes cast)
[12,751 views]  View Printable Version
Install the Google command line tool UNIX
Google has released a command line tool to access many of their services. This is obviously handy for batch processing with scripts. The tool is largely written in Python and is open source, so it's highly portable and runs on the Mac.

The following services are currently supported:
  • Blogger
  • Calendar
  • Contacts
  • Docs
  • Picasa
  • Youtube
read more (190 words)   Post a comment  •  Comments (8)  
  • Currently 2.33 / 5
  You rated: 4 / 5 (27 votes cast)
[12,209 views]  View Printable Version
Search-replace recursively in files and folders UNIX
I wrote a bash script that lets you search and replace text strings in files of a specified folder and its subfolders recursively. Key features:
  • recursive operation with immediate visible results in simulation mode (no waiting time)
  • perl/POSIX compliant regex for search strings
  • retains ownership and permissions of replaced files
  • cross-platform (BSD/Mac/POSIX Linux compatible)
  • easy to compare ANSI-colorized diff output (switchable)
  • safe: creates and removes temporary files in the system temporary folder
  • simulation mode
  • free :)
read more (258 words)   Post a comment  •  Comments (8)  
  • Currently 1.79 / 5
  You rated: 3 / 5 (24 votes cast)
[10,611 views]  View Printable Version
Get the command line version of Maple UNIX
If you own a copy of the Mac version of Maple, and have used Maple in Linux, you may know about the command line version of Maple, and have noticed that it is missing in the Mac OS X version. But it is still there, it's just hidden.

To get it, add /Library/Frameworks/Maple.framework/Versions/Current/bin to your PATH (see this page if you don't know how to do this). Then, you can type maple at a command prompt to get the command line version of Maple with all it's ASCII beauty. There are advantages, too. It is much faster to load if you just need to do a quick computation and don't care too much about the appearance of the output.

If the GUI version doesn't work for some reason, such as a Java problem, the command line version will still work fine. There is also a diagnostic version of maple called mint, and an alternative GUI version called xmaple. But most importantly of all, you should at least give it a try to experience the wonders of ASCII 3D plots.

Note: This hint applies to Maple 12. I don't know if things are still this way for Maple 13 or Maple 14.

[crarko adds: I haven't tested this one. I omitted a very nice, but very large, ASCII 3D plot image.]
  Post a comment  •  Comments (5)  
  • Currently 2.39 / 5
  You rated: 5 / 5 (18 votes cast)
[7,893 views]  View Printable Version
How to add a user to a UNIX group UNIX
In Unix, you can easily add a user to a group by editing the /etc/group file. In the NetInfo days, there were equivalent methods in Mac OS X. Now that NetInfo has been replaced, how do you add a user as a member of a group? Here's how you can do it in Snow Leopard.

First, to find which groups you are currently in, you can use: % groups which promptly listed all the groups, except the one I needed. How do you add the user?

That's where the dseditgroup command comes in. It's a command-line tool which can perform certain editing operations on groups. It has an explanatory man page, and I used this command to add a username to a group. The parameter -u yourusername is your admin account, and the -p will prompt for the password.

% dseditgroup -o edit -u yourusername -p -a username -t user group.

[crarko adds: I tested this, and it works as described. You can consult the man page for dseditgroup for more information.]
  Post a comment  •  Comments (6)  
  • Currently 2.83 / 5
  You rated: 4 / 5 (12 votes cast)
[32,305 views]  View Printable Version
An alternative method of installing certain Unix apps UNIX
Many people know about Fink and MacPorts, but few seem to know about Rudix.

MacPorts and Fink can compile complex *nix software for Macs, including all dependencies, but they also add a lot of bulk to your hard drive. So if you're just trying to download one simple tool like wget, sox, or imagemagick, they may be overkill for what you need.

The number of packages isn't nearly as large in Rudix as it is in the others, but if they have what you're looking for, you'll just be downloading one small .pkg file for each *nix program you want.

[crarko adds: I haven't tried Rudix; their home page notes that the project uses Python, and as such, there are many Python modules available.]
  Post a comment  •  Comments (8)  
  • Currently 1.60 / 5
  You rated: 3 / 5 (15 votes cast)
[7,239 views]  View Printable Version
Install Ubuntu Linux over the network with the help of a Mac UNIX
This hint is about installing Ubuntu Linux over the Internet on a PC compatible with network boot (PXE) without using a CD/DVD drive, a USB Flash drive, or having previously downloaded a full disc image.

You will need another computer on the same LAN. I will be using a Mac, hence why you're reading this hint here. Both computers obviously need Internet access.
read more (565 words)   Post a comment  •  Comments (22)  
  • Currently 2.71 / 5
  You rated: 5 / 5 (24 votes cast)
[16,012 views]  View Printable Version
Use OS X's trash in a Finder-like way from Terminal UNIX
I've written a few bash functions to interact with the normal Mac OS X trash can. This is actually slightly more complicated that it sounds at first, since the trash can is not just a folder somewhere. Each volume has its own trash, and your home folder has a trash can. Finder uses your home trash for any files on the boot volume, unless you have FileVault on.

Start by adding the following code (note you can check newer versions of the code on the mactrash SourceForge page) to your bash startup file (.bashrc or .profile).
#!/bin/bash -c 'echo This file is meant to be sourced.'

alias rm='del'
  # make rm(1) safe.
  # Remove or comment-out this line to return to normal rm(1) functionality.

function del ()
  if declare -F trash >/dev/null
    trash "$@"
    command rm -i "$@"

function trash ()
  local F
  local HOME_DEVICE="$(stat -f %Sd "$HOME")"
  local TRASHCAN=~/.Trash
    # Set this in advance _outside_ the loop below
  for F in "$@"
    if ! test -e "$F"
      echo "No such file or directory: $F" 1>&2
      return 4
    local DEVICE="$(stat -f %Sd "$F")"
    if [ x"$DEVICE" == x"" ] || [ x"$DEVICE" == x"???" ]
      echo "Can't locate trash for ${F}." 1>&2
      return 3
    if [ x"$DEVICE" != x"$HOME_DEVICE" ]
      TRASHCAN="$(trashOnDevice "$DEVICE")"
    if [ ! -d "${TRASHCAN}" ]
      command rm -f "${TRASHCAN}"
      if ! mkdir -m 700 "${TRASHCAN}"
        echo "$TRASHCAN is inaccessible at this time." | sed 's;'"$HOME"';~;g' 1>&2
        return 1
    local FinT="$(basename "$F")"
    if [ -e "${TRASHCAN}/${FinT}" ]
      FinT="$(date) ${FinT}"
    if ! mv -vn "$F" "${TRASHCAN}/${FinT}"
      echo "Unable to move $F to the trash." 1>&2
      return 2
  local TRASHSIZE="$(du -hs "${TRASHCAN}" 2>/dev/null | cut -f 1)"
  local TRASHCANloc="$(dirname "$TRASHCAN" | sed 's;^/Volumes/\(.*\)/.Trashes;\1;g' | sed 's;'"$HOME"';~;g' | sed 's;^/.Trashes;/;g')"
  echo "${TRASHSIZE:-  0B} in trash on $TRASHCANloc."

function emptytrash ()
  local TMPIFS="$IFS"
  local MOUNTS=( $(mount | sed -n 's:/dev/.* on \(.*\) (.*):\1:p') )
  local TRASHCANs=( "${HOME}/.Trash" $(IFS="$TMPIFS";for i in `seq 0 $(( ${#MOUNTS[@]} - 1 ))`; do echo "${MOUNTS[$i]}/.Trashes/$(id -u)"; done) )
  unset TMPIFS

  local TRASH_SIZE
  TRASH_SIZE="$( (for i in "${TRASHCANs[@]}"; do ls "$i"/; done) 2>/dev/null | wc -w)"
  if [ "$TRASH_SIZE" -gt 0 ]
    echo -n "Emptying trash"
    for i in "${TRASHCANs[@]}"
      tput smcup
      pushd "$i" 2>/dev/null && {
        srm -frsvz . 2>/dev/null ; popd ;
      tput rmcup
      echo -n .
    local DONE=
    [ `ls "${HOME}/.Trash" | wc -w` == 0 ] && DONE="Done."
    echo "$DONE"
    echo "Trash is empty."

function trashOnDevice ()
  local DEVICE="$1"
  local MOUNT="$(mount | sed -n 's:/dev/'"$DEVICE"' on \(.*\) (.*):\1:p')"
  if [ x"$MOUNT" == x"" ] || [ x"$MOUNT" == x"???" ]
    # If no mount point is found, then don't return the path to root!
    return 1
  elif [ x"$MOUNT" == x"/" ]
    # Encourage the resulting path to _not_ start with two slashes
  echo "$MOUNT/.Trashes/$UID"

# Usage : seq n m [i]
# echo all integers between n and m using a skip or increment of i
function seq ()
  [ "$1" ] || [ "$2" ] || return 1
  local x=$1;
  local y=$2;
  local i=${3:-1};
  local seperator="${4:- }"
  while [ $x -le $y ]
    echo -n $x"${seperator}";
    x=$(( $x + $i ));
Once you've added the above code to ~/.bashrc, you'll find that Terminal will now accept three new commands: del, trash, and emptytrash.
read more (472 words)   Post a comment  •  Comments (28)  
  • Currently 3.40 / 5
  You rated: 5 / 5 (15 votes cast)
[12,602 views]  View Printable Version