What Do Terminal Commands Actually Do?

Most Mac Terminal commands posted online are actually simple commands that just change a preference for an app or part of macOS. When you use a command like "defaults write" all it is doing is editing a small preference file in your user Library folder. Take a look at what actually is changed.
Video Transcript / Captions
Closed captioning for this video is available on YouTube: What Do Terminal Commands Actually Do?.

So if you've been using Macs for awhile you probably are familiar with Terminal commands that look like this. As a matter of fact a lot of people just call these Terminal Commands even though they are a very specific type of Terminal Command. In this case it's, defaults write com.apple.screencapture type jpg. The idea here is that you're setting a hidden preference. There's a preference inside of Mac OS for what file type to use for screen capture. PNG is the default but you can use jpg or pdf as well. But there's no place in the interface to actually select this. So you're left with going to Terminal, typing this command, hitting Return and then a lot of times you also have to do something like, type something like killall SystemUIServer basically restarting that part of your Mac so that the change takes effect.

Now you may be familiar with this. You may have done this for all sorts of different settings on your Mac. You may see web pages that are recommending or go to the Terminal to do this. But what does it really do? What is this command actually doing? It's actually very simple so I want to take the time to explain it to you.

What this is actually doing is just changing a little bit of text inside of a file. Let's go to the Finder and in the Finder here I'm going to go to my home folder, MacMost. But I'm going to go to the Library inside of it. The easiest way to get to the Library folder, because it's typically hidden, is to click Go and hold the Option key down on your keyboard. You'll see the Library popup as an option. When I'm in Library I can go down and look at Preferences. Preferences will show me all of these files. You notice the names look kind of like what part of that command is. In fact, you've got one that matches that perfectly. You've got, right here, com.apple.screencapture.plist.

Now I'm going to open this up in a text editor so you can see it. Normally you wouldn't do this but I want to show you what this is. So basically it just has some header information here and then it has a bunch of definitions. Key is what and the string here is what it is set to. So location is set to the Desktop. Type is set to jpg. Ah, okay, so that's where the setting is. Sometimes if you look at this before you ever mess with it in Terminal it won't even be there. Like the type, jpg, it won't be there. It'll just be blank. Nothing will be there for type at all.

Now if I were to go back into Terminal here and type this command again and change to pdf. Now if I were to go and look at that file again, so I'll open it up again, you can see it actually changed it to pdf. So that is all that command is doing. It's altering the text inside these little preference files. You don't want to go editing these files manually because you can see there's a lot of nuance here. You know, there's this whole idea of encasing things in these tags, string, key, all of that. There's only certain things that can be accepted like type. It has got to be typed exactly that way, etc.

So you don't want to mess with these manually. That's why typically these preferences are changed when you use something like System Preferences or like a Preference say, inside of the Finder here. If I go to Preferences and there's a bunch of selections here. These will change it for you in the right way. But when you don't have an option for it that's when you have to go to the Terminal and use these defaults right. Most typical Mac users will never have to change any of these. But if you do ever change them I think it's a good idea to know what exactly you're changing. You're just changing this little text file and changing a preference by using these commands in the Terminal rather than using a checkbox or a popup menu somewhere in some preference part of an app.

Comments: 3 Responses to “What Do Terminal Commands Actually Do?”

    1 year ago

    The important thing is not the command itself, but the ability to combine these commands, i.e. use built-in Unix programs, in a shell script, so you can automate tasks, perform complex operations, implement other people’s solutions. You can integrate it into the GUI using Automator (Service/Workflow) or BitBar, or direct shell scripts in file managers that support it, e.g. Nimble Commander. Most Mac users fear the command line, but in reality the command line is the best friend you’ll ever have.

    Andrea Grasselli
    11 months ago

    Thank you Gary, very interesting!

    Andrea Grasselli
    11 months ago

    … and very well explained!

Comments Closed.