Browsing the blog archives for March, 2009.

Bash – Write A Sequential For Loop

Examples

bashterm

A sequential for loop in bash script is accomplished in the following example:

for i in {1..100}
do
    # Do something here
    echo "${i}"
done

This example iterates from 1 to 100 (inclusive) and prints the index number.

Note: This only works in modern versions of bash (3.x+).

No Comments

OS X – Empty Trash Command Line

Examples

apple-logo

It is possible to empty the trash in OS X from the command line by running the following command in the terminal:

rm -Rf ~/.Trash/*

This command permanently removes all the files you have placed in your OS X trash bin.

2 Comments

Bash Find On A Large Dataset – Write The Results To A File

Examples

A fast bash based solution for executing a find on a directory with a lot of files that you want to log to a file:

find /my/data/  -name '*.xml' -type f -fprint my_xml_files.txt

This example looks in the /my/data/ directory for all files with the xml extension and then writes the results to the my_xml_files.txt file.

No Comments