10 Basic Terminal Commands Every Digital Tech Should Know

One of the great aspects of the Mac OS is its FreeBSD roots, which provides a UNIX-like operating system under the hood. If our usual graphical interface is like driving a car from the driver's seat, we're going to learn to pop the hood and work directly on the engine. Once you discover this side of the Mac, you'll find a whole new level of power and control available to you.

Knowing how to utilize the Terminal on the Mac is an extremely important skill for any digital tech or DIT. In this post, I'll get you started with 10 commands that I find the most useful, along with a few additional commands. In a later post, I'll show you how to put the commands together to form a script, but let's first start with the basics.

Open the Terminal app within ~/Applications/Utilities.

Ahhh, the beauty of the command line prompt.

Now when we use the Terminal, this is actually a small program that allows us to communicate with the shell. Different UNIX-like operating systems have different variations of shells, but the default shell we'll be working with is called Bash. Sorry, enough of the geek talk about shells. Let's jump into the commands! 

#1. pwd - Where are we?

Start by typing the letters "pwd" which stands for "print working directory". From now on, we will be using the proper term, "directory", instead of "folder" when talking about the shell or Terminal. I'll use "folder" only when related to the Mac Finder. The pwd command will show the path of where you currently are within the filesystem. For instance, if you are on the Desktop, it would look like this after issuing the pwd command to the shell:

This shows us the Desktop is within "angelhernandez" which in turn is within "Users". If our objective was to delete some photos in the "Pictures" directory, we would realize we are not in the right place. 

#2. cd - Navigating the file system

The next command is "cd" which stands for "change directory". Now type the following:

cd ~/Pictures

followed by typing...


and you'll now see you have moved into the "Pictures" directory.

If you were observant, you'll notice we threw in a character we have not explained yet. The "~" at the beginning of the path is a shortcut that automatically fills in the location of your "home" directory. Your home directory is "/Users" followed by whatever your login name is. For instance, if your login name is "digitaltech" your "home" location would be "/Users/digitaltech". So by typing ~/Pictures, the shell is really seeing "/Users/digitaltech/Pictures".

#3. ls - What's inside?

Now that we are in Pictures, how do we see what files/folders are inside? Simply type the letters "ls" (not the number one or the letter eye; lowercase LS) which stands for "list" - it's the equivalent of turning the lights on in a dark room.


We can now see what files and folders are in the current directory. 

#4. rm - Deleting files

I hate to empty the Trash on a job. A much safer method for removing files and folders from your computer or external drives is to use the "rm" command with the "-i" option. With shell commands, you can pass them various options to control how they run. All commands have different sets of options. If you ever want to fully dive into a command and all of its options, type "man commandName". So for "rm" we'd type "man rm". This will display a "manual" page for the command. 

Type "q" to quit or exit the man page.

Type "q" to quit or exit the man page.

We can now see that "-i" will ask us to confirm the deletion before doing so. Let's go ahead and delete the file I have in my Picture directory named unnamed.jpg.

rm -i unnamed.jpg

That's all there is to it! Commands are so simple and fast to use.

A common scenario on a photo shoot is the need to delete files to create space on a hard drive. Rather than move these files or folders to the Trash and then empty it, a better solution is to use the Terminal and rm -i or rm -fR.

** Warning, the latter -fR option is very powerful. It will recursively delete everything within a folder and will not ask you before removing. Be absolutely sure you have the correct target folder before issuing this command. There is no going back!

Here's how I would go about deleting a large amount of data on a drive that I was 100% sure was backed up.

A. Create a folder called "_DELETE-ME" (you can name it anything)
B. Move everything I want to delete inside this folder. 
C. Use the Terminal and type: 


#5. mv - Move files

Above we mentioned moving files. To move both files and directories/folders, you should type:

mv fileName /newLocation/

#6. cp - Copy files

Exactly the same as mv, but this time we use cp.

cp fileName /newLocation

#7. du -skh * - locate what's using all your hard drive space!

This is an awesome command and a great way to discover what files and folders are eating up your hard drive space. Try taking a glance at your own system now by typing:

du -skh ~/*

You will quickly see a list of all files and folders within your home directory and their respective sizes. This is a much faster method than using the Finder.

#8. setfile -d '11/15/2016 17:50:10' folderName

Have you ever had a copy operation interrupted and ended up with a grayed out folder that you are unable to open?

In these instances most of the data probably copied, so it's a shame to remove the grayed out folder and start the copy over. Rather, let's fix it and then Chronosync back to the folder to finish the copy.

To fix these corrupted folders, we need to set the date attribute of the directory. Here's the command to return the directory to a normal color and status, which allows you to open and work with the folder once again.

setfile -d '11/15/2016 17:50:10' folderName


#9. find /Volumes/LaCie-Drive/161115_MyShoot/Output -type f -name *jpg | wc -l

The above commands is one of my all time favorites for photo shoot use. It allows you to easily and quickly count every type of a file in a specific location.

For instance, let's say my session titled "161115_MyShoot" resides on my external drive "LaCie-Drive". Before handing the drive to the client, I need to confirm that all 8,745 captures were processed into JPEGs without error. Unfortunately they are spread out in their shot folders - 50 folders to be exact. Am I to go folder by folder to count them? No way! Simply enter the command below:

find /Volumes/LaCie-Drive/161115_MyShoot/Output -type f -name *jpg | wc -l


> 8745

Great! Now let's verify that we have the exact same number of RAW files on the drive:

find /Volumes/LaCie-Drive/161115_MyShoot/Capture -type f -name *EIP | wc -l

> 8745

Perfect. Notice in the second example, I changed the target directory to "Capture" and the file type to count as EIP. The number of RAW files and JPEGs match, so we are good to go. There's no faster way to run such verification.

#10. diff -rq folder1 folder2 - What's the difference?

One of the worst feelings as a tech is when you process out a large number of shots and then when you compare the JPEGs and TIFFs, the folder count is off by 1. One shot did not process, but you have no idea which one. The command below will save your sanity and your precious time:

diff -rq folder1 folder2

The resulting output will tell you the difference. Here's a very simple example. Look at the contents of folders A & B and then the result of the command.

That's your crash course for today! This is a very basic set of commands, but it's enough to get you started in the command line world. If you'd like to learn more, here's a great site to explore. http://ryanstutorials.net/linuxtutorial/

Further Resources