current directory

Unix find command: How to move a group of files into the current directory

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.)

How to change the Mac Terminal title from the command line

Mac Terminal FAQ: How can I change the title on the Mac Terminal app from the Mac/Unix command line?

I've been working on a project where I have three Mac Terminal tabs open at one time, and I found it was much easier to work this way when I changed the title on each Terminal window. This helped me easily identify what I was doing in each Terminal window.

Changing the Mac Terminal title

The basic escape sequence you need to change the Terminal title from the command line is this:

How to get the current directory in a Scala application

Depending on your needs there are a couple of ways to get the current working directory in a Scala application.

1) Using System.getProperty

The most obvious/direct approach is to use the Java System.getProperty method, passing in "user.dir" as a parameter:

The Linux pwd command (and Linux command line prompts)

Linux current directory FAQ: How do I show what directory I'm currently in on a Unix or Linux system?

Just use the Unix/Linux pwd command, like this:

pwd

If you're in a directory named /home/al, the output looks like this:

$ pwd
/home/al

If you're in a directory named /tmp, the output looks like this:

$ pwd
/tmp

That's all there is to the pwd command.

A Bourne shell script that loops through all files in the current directory

Linux shell script for loop FAQ: Can you share an example of a Linux shell script for loop, for instance, to do something for every file in the current directory?

Here's a shell script that you'll find on all the Unix, Linux, and Mac OS X computers I've worked on. The general process of this script is "for every file in the current directory do XYZ".

Mac OS X Finder FAQ: How to open the Finder from a Terminal window

Mac Terminal Finder FAQ: How can I open a Mac Finder window from the current directory of a Mac Terminal window?

To open a Finder window in the current directory of your Mac Terminal just issue this Mac open command:

open .

Yes, that is a decimal after the open command. The decimal is the Unix way of referring to the current directory.

Java: How to get the current user directory in a Java application

Java current directory FAQ: Can you share an example of how to determine the current directory in Java?

You can determine the current directory your application is started in using Java's System.getProperty() method and the user.dir property, like this: