files

Scala cookbook recipes

Wow, I began by writing a few Scala programming tutorials just because I like the language, and as I look here a couple of months later I now have more than sixty tutorials. As a result, I thought I'd start organizing them here in the form a Scala Programming Cookbook.

Here's my current collection of Scala FAQs and recipes, in a "cookbook" format.

How to search multiple jar files for a string or pattern

Here's a shell script that I use that search Java jar files for any type of pattern. You can use it to search for the name of a class, the name of a package, or any other string/pattern that will show up if you manually ran jar tvf on each jar file. The advantage of this script -- if you're a Unix, Linux, or Cygwin user -- is that this script will search through all jar files in the current directory.

Scala - How to open and read files in Scala

Scala file FAQ: How do I open and read files in Scala?

When you're writing Scala scripts, you often want to read text files. Fortunately it's pretty easy to open and read from a file in Scala. You can just use an approach like this:

Mac backups - handling spaces in filenames with find, tar, and xargs

This morning I decided to take a few minutes to backup all the songs I've purchased over the last half-year. These are all on my Mac OS X system, under the Music folder in my home directory.

The problem with trying to do this with standard Unix tools is that all these subdirectories and filenames have spaces in their names. Just looking at the Music folder, it contains many directory names like this:

Those Mac .DS_Store files

Mac .DS_Store files FAQ: What are these .DS_Store files on my Mac, and how can I get rid of them?

Those crazy Mac .DS_Store files (also referred to as "dsstore" files) finally got to me, so I did some research on where they come from, and how to get rid of them (or more accurately, how you can't get rid of them).

Here's what I've learned about Mac OS X .DS_Store files.

Use sed to modify files in place

sed command FAQ: How can I use the Unix/Linux sed command to edit (modify) files in place?

The short answer is that you just need to use the -i or --in-place sed arguments, as shown in the sed man page:

-i[SUFFIX], --in-place[=SUFFIX]

edit files in place (makes backup if extension supplied)

Then, if you have a file named 'hello.txt' with contents like this:

jello, world
this is a test

you can then run a sed command like this to modify that file:

Where are Java WebStart files kept on Mac OS X 10.6?

Mac Java WebStart FAQ: Where are Java WebStart files (Jar files) kept on Mac OS X systems? And how can I delete WebStart apps on a Mac?

Java WebStart Jar files are kept below this directory on Mac OS X 10.6:

/Users/al/Library/Caches/Java/cache

More than likely you're asking because you want to delete these Java WebStart files on your Mac. The easiest way to delete them is:

Find command - Find files not matching a pattern

Unix/Linux find "patterns" FAQ: How do I find files or directories that don't match a specific pattern (files not matching a regex pattern, or filename pattern)?

In my case I just ran into a situation where I needed to find all files below the current subdirectory that are NOT named with the filename pattern "*.html" . Fortunately with the newer Unix/Linux find syntax this solution is pretty easy, you just include the "-not" argument, like this:

The Linux cut command

Linux cut command FAQ: Can you share some Linux cut command examples?

The Linux cut command is a really great command filter to know. You can use it to do all sorts of cool things when processing text files and text in command pipelines.

Using the cut command with /etc/passwd

For a first cut command example, I'll use the /etc/passwd file on my Unix system. I use this file because fields in the file are separated by the ":" character, which make it very easy to work with.

The Linux chown command

Unix/Linux chown FAQ: How do I use the chown command?

The chown command is most commonly used by Unix/Linux system administrators who need to fix a permissions problem with a file or directory, or many files and many directories.

For instance, suppose you want files to be owned by the user "nobody", but when you issue an ls command, you see that they're owned by the user "fred", like this:

Syndicate content