Difference Between bin and sbin

Ever been curious about the difference between bin and sbin? The ‘s’ in sbin means ‘system’. Therefore, system binaries reside in sbin directories.

As you may have noticed, there are a number of different bin directories in Linux. The best reference I’ve found for an understanding of various Linux folders is man hier. It provides a brief explanation of the Filesystem Hierarchy Standard (FHS) in Linux. I’ve included a summary of the various bin and sbin definitions below:

    This directory contains executable programs which are needed
    in single user mode and to bring the system up or repair it.

    Like /bin, this directory holds commands needed to boot the 
    system, but which are usually not executed by normal users.

    This is the primary directory for executable programs. Most
    programs executed by normal users which are not needed for 
    booting or for repairing the system and which are not
    installed locally should be placed in this directory.

    This is where programs which are local to the site typically

    Binaries for programs local to the site.

    Locally installed programs for system administration.

If you want to create your own scripts and make them available to all users, you’re pretty safe adding them to /usr/local/bin. If you want to run scripts using cron or crontab, simply use the full path to the command (i.e. /home/user/command).

What I do is add my scripts to my local bin (~/bin) and then I create a symbolic link in /usr/local/bin to the commands I want to make public. As a result, I can manage all my scripts from the same directory but still make some of them publicly available since /usr/local/bin is added to $PATH.

Show/Hide Invisible Files on Mac & Other Secrets

Showing hidden files can be somewhat of a pain in Mac OS X. I’ve come up with a number of ways to make it easier for myself.

The simplest, most direct way of doing this is a command in the Terminal. One way is to navigate to the appropriate directory in Terminal and type ls -lha. Alternatively, you can type ls -lha <path/to/directory>. This will give you a list of all the hidden files for that directory. But maybe you aren’t proficient with Terminal commands and/or you need to do some file manipulation and/or you don’t want to use the CLI.

Much like my post Hide Desktop Icons on Mac, I’ve created a little script I call hidden that automatically shows and hides hidden files.


# checks file visibility and stores value in a variable
isVisible="$(defaults read com.apple.finder AppleShowAllFiles)"

# toggle file visibility based on variable
if [ "$isVisible" = 1 ]; then
	defaults write com.apple.Finder AppleShowAllFiles -bool false
	defaults write com.apple.Finder AppleShowAllFiles -bool true

# force changes by restarting Finder
killall Finder

Paste that code into a text editor, save it to a directory in your $PATH and make it executable (chmod 755 <filename>).

HideSwitch ScreenshotTwo other alternatives I’ve stumbled upon are HideSwitch and Secrets Prefpane (at the time of this post the site was down. Get it at MacUpdate instead.) HideSwitch is just a simple mini-app with two buttons to hide and show hidden files. Secrets Prefpane is a just that: a button that shows up as a system preference and turns into a prefpane once clicked. However Secrets is quite powerful and can do a lot more than just show and hide files. Secrets includes a variety of features, such as:

  • Selecting the format and destination folder of saved screenshots
  • Changing the login window desktop picture
  • Changing Dock effects
  • Seeing the contents of folders when QuickLooking (I don’t think this works on Lion)
  • Enabling the debug menu in iCal

Those are just a few that I’ve found useful and interesting. Since it’s free, you may want to download it and check it out. Might have a feature you’ve been dying to have. Secrets also taps into many of the preferences of your other programs such as Adium, iTunes, Cyberduck, Skype, Preview, Transmission, etc.

Secrets Prefpane Screenshot

Clock In, Clock Out

I’ve worked (and presently work) a number of jobs where I have to keep track of my own hours. As with any repetitive task, the answer is to automate. So tracking your hours isn’t hard or time consuming, but having your computer do it for you while learning a little scripting appeals to me more. Thus, I concocted a nice little bash shell script with a pinch of Ruby–for the heavy lifting.

The script/program is simple. It’s called clock. All you do is type clock into the Terminal (mac) and…WAHLA! You’re clocked in. When you want to clock out, type clock again and you’re clocked out. Each time you clock in or out, the program records a timestamp with the date and time. After each clock out, it records the number of hours worked during that session. When it’s time to submit your timecard so you can receive your paycheck, simply type clock -f to finalize your timecard. This will sum your session hours and rename the timecard with the start and end date so you know the period.

I’ve included a zip archive of the files (clock, timeadd.rb, timediff.rb) so if you find yourself in the same boat you can give the program a shot. I suggest you add them to your own “bin” folder in your home directory like I’ve done. If you aren’t familiar with this concept, let me give a short explanation.

Dedicating a directory in your home folder is convenient if you like to write various little programs/scripts. It allows you to…segregate these from the built in programs/scripts that come with your OS so they are easily accessible and you remember which ones are yours. To make these programs work just like the rest of the programs (e.g. ls, rm, less, pwd, etc.) add the directory to your $PATH as follows:

export PATH=$PATH:/Users/USERNAME/bin

Of course, be sure to replace USERNAME with the obvious. You can type this command into the CLI or you can just add it to your .profile file in your home directory. If you don’t have a .profile file, go ahead and create one. Every time you open Terminal (or another CLI), the .profile file is read and executed, thus you will never have to type in those commands again manually.

Two more things to make this work:

  1. Make sure to open clock in a text editor and change the path where the timecard-current.txt will be saved (in addition to any other paths).
  2. Make sure to install the appropriate gems for the Ruby scripts. Simply type the following into Terminal:
    gem install chronic_duration time_diff

If you have any thoughts, suggestions or questions, please comment. I value feedback.