directory

A large collection of Unix/Linux ‘grep’ command examples

Linux grep commands FAQ: Can you share some Linux/Unix grep command examples?

Sure. The name grep means "general regular expression parser", but you can think of the grep command as a "search" command for Unix and Linux systems: it's used to search for text strings and more-complicated "regular expressions" within one or more files.

I think it's easiest to learn how to use the grep command by showing examples, so let's dive right in.

Unix find command: How to move a group of files into the current directory alvin May 16, 2018 - 9:51pm

I just bought a bunch of MP3 music files from Amazon, and when I downloaded the zip file they provide onto my Mac, it was a bunch of files in a bunch of subdirectories; not really convenient to work with when you’re trying to import them into iTunes. So I used this Unix find command to move all of the music files from the subdirectories they were scattered in into the root directory that was created when I expanded the zip file:

cd Amazon-Music-Folder
find . -type f -exec mv {} . \;

If you ever need to either copy or move a bunch of files with a single command, I hope this example shows the correct find command syntax for your needs. (If you need to copy the files, use the cp command instead of the mv command.)

A large collection of Unix/Linux ‘find’ command examples

Linux/Unix FAQ: Can you share some Linux find command examples?

Sure. The Unix/Linux find command is very powerful. It can search the entire filesystem to find files and directories according to the search criteria you specify. Besides using the find command to locate files, you can also execute other Linux commands (grep, mv, rm, etc.) on the files and directories you find, which makes find extremely powerful. 

LibGDX error: Your Android SDK path doesn’t contain an SDK

I don’t know much about LibGDX yet, but one thing I’ve learned is that if you get the LibGDX error message, “Your Android SDK path doesn’t contain an SDK,” it’s because the LibGDX setup tool doesn’t work automatically with the Android SDK tools that you download from the Android website, at least not the default tools. (That directory may work after you do some configuration with the sdkmanager, dunno.)

A Linux shell script to rename files with a counter and copy them

As a brief note today, I was recently looking for all Messages/iMessage files that are stored on my Mac, and I used this shell script to copy all of those files — many of which have the same name — into a directory named tmpdir, giving them all new names during the copy process:

count=1
for i in `cat myfiles`
do
    fname=`basename $i`
    cp $i tmpdir/${count}-${fname}
    count=`expr $count + 1`
done

How to search multiple jar files for a string or pattern (shell script)

Here’s a Unix shell script that I use to search Java Jar files for any type of string 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 it will search through all jar files in the current directory:

How to get Java/Scala system environment variables and properties

Want to get the system environment variables and/or properties from your Scala or Java application? This quick post shows what environment variables and properties are available.

Here’s a little Scala application that prints all the environment variables and properties. You’ll see that you can convert it to Java very easily:

How to create an SBT project directory structure with a shell script

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 18.1, “How to create an SBT project directory structure.”

Problem

SBT doesn’t include a command to create a new project, and you’d like to quickly and easily create the directory structure for a new project.

Solution

Use either a shell script or a tool like Giter8 to create your project’s directory structure. Both approaches are shown here.

Scala: How to run an external command (process) in a different directory

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is a very short recipe, Recipe 12.18, “How to run an external command (process) in a different directory.”

Problem

You want to use another directory as the base directory when running an external command.

How to list subdirectories beneath a directory in Scala

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 12.10, “How to list subdirectories beneath a directory in Scala.”

Problem

You want to generate a list of subdirectories in a given directory.

Solution

Use a combination of the Java File class and Scala collection methods: