Fun With Mac Terminal Commands - Hands-On Mac 5

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey it's time for hands-on Mac today we're gonna delve into the command line [Music] hands-on Mac is brought to you from twits lastpass studios you're focused on security but learn your employees LastPass can sure they are by making access and authentication seamless whether they're working in the office or remote visit lastpass.com slash twit to learn more this is Troy's hands-on Mac is brought to you by IT Pro TV visit IT Pro TV slash twit and use the code twit 30 for an additional 30 percent off for the lifetime of your active subscription [Music] hey everybody welcome to hands-on Mac I'm Leo Laporte Mac lover since 1984 one of the reasons I love the Mac is because it is a version of UNIX the mothership of operating systems mackintoshes operating system is based on BSD the berkeley systems distribution and even more to the point than all of that where it came from or what it is is the fact that you have a UNIX style command line available to you at all times in the Macintosh and you can install unix-style tools so for the next few episodes we're gonna talk about that and how to use the command line how to install those tools using a system called homebrew and then even in a couple of episodes how to set up your system automatically or almost automatically using homebrew and some of its features but let's first start with the terminal I showed you last week the terminal program I use and recommend I term too you can see I've got it up here on the screen and I'm gonna we're gonna work here in the command line so let's talk a little bit about it I when you get a Macintosh you get a terminal I've replaced it with a third-party terminal I term 2 you also get a command line environment a shell as we call it the original Mac shell was four years something called bash the bourne-again shell which is a very common shell it's often used on Linux as well Apple in the most recent recent version of Mac OS Catalina's replaced that with Z shell which is a little bit more modern I use another shell entirely called fish which is even more modern but none of that's gonna matter because the simple commands I'm going to show you today will work on any of the above it will affect though what your prompt looks like and as you can see I've opted for a simple fish prompt that shows me and I'll zoom in on this so you can see it what directory I'm in that's this little tilde and then the dollar sign says okay type something here and then of course there's the the caret saying this is where your typing will go let's talk first about directories directories are just like folder you have in fact they show up folders show up as part of your directories in the command line if I ask it what's my current working directory or PWD you'll see that I'm in the folder slash users slash léo that front slash means it's the very top level directory and if you open your macintosh explorer you'll see the finder you'll see oh yeah there's users and then inside users each user has its own directory in this case I'm in the lio directory so that's my home directory and a shortcut for home is this little tilde in fact I could even say let's say I want to go to a directory called Documents I could say slash you know tilde slash documents whoops and there it is that's the actual directory that tilde is expanded by the shell into slash users slash Leah so that's the first thing to understand and now I'm in the Documents folder I actually didn't want to be so let's go back to our home directory and that's a simple command CD for change directory if you type CD and a directory name it'll go to that directory let's say I go CD tilde slash desktop and now I'll be in the directory called desktop you see but if I just type CD without anything I'll go right back home so that's a first shortcut to know and and use CD moves you around in directories remember directors are the same thing as folders and you can go into a you know a deep level if slash slash slash is that deep as you want but you can always come back to the home directory the top-level directory by typing CD want to know what's in the directory well on Windows use the der command in unix-like operating systems you use the LS command think of it as short for lists one of the things about UNIX I should probably explain before we go much further is the is the whole kind of ethos of Linux and UNIX in general is simple programs that do one thing well and the operating system is constructed in such a way the you can daisy-chain programs using what they call a pipe so you can get the output of one program to go into the input of another program with a pipe command and then the output of that into another one so the idea of unix is simple short commands simple utilities that do one thing well and then the ability to daisy-chain them to do more elaborate things so that's a good thing to understand before we go much further because that is kind of key to the whole operation here LS and I'm gonna zoom out because it's gonna spit out a lot of text here LS lists the files in a directory ready whew there they are now that's a pretty simple listing I don't get much information about those files it's just the talked the directories and their file names I can get more information by using switches commands can be followed by sub commands usually preceded by a dash although some programs use a double dash in this case one of the most common is - a so I'm saying let's get a command listing but I want it for all the files in the directory that's gonna be a longer listing that's gonna show hidden files in on Mac OS and other unix-like operating systems files that have the name preceded by a period are not usually shown so you can see I have a bunch of directories and files here but if I do LS - a it's going to show you more it's going to show you the ones that begin with periods as well as all of those other directories these are hidden files that won't show up normally either in Macintosh finder or on the command line there's also LS dash L which is short for long and that's going to give me much more information about the file this is actually probably a useful thing to look at because so tell you a little bit about how UNIX operating systems work we see we have the Applications folder that's yep the Mac Applications folder we see its creation or modification date in this case it's the creation date of the folder we see its size we see who owns it now this is an interesting kind of additional piece of information unikz Mac OS being a UNIX is a multi-user system so every user has not only the name of the user but also the group they're a member of in this case I'm Leo the user and I am a member of the staff group usually members of many groups staff is a group name used by Mac OS that that's useful later because you can assign permissions to access folders to both the individual the user and the group the user is in these are the permissions themselves this is where it gets a little weird wonky and complicated then this is a directory that's what the D means and in this directory the user that's the first three letters you see there's three sets of three letters the first is the user then the group the users in and then everyone else so in this case the group and the everyone else have no access at all to this folder but I have access to read it write it and execute it now you might say well how do you execute a folder you don't but to get a listing you have to have execute permissions so that's why I have execute permissions this this folder the audio folder has more extended permissions the group can execute in other words list it and read it but they can't write to it there's no W there this gets a little complicated I'm not sure I want to get too far down this road but it will lead us to the next command which is chmod this is where you change permissions now this is useful for two reasons sometimes we want to reduce the permissions for security purposes for instance if you have a GPG the encryption technology or SSH the secure shell technology you want a restrict who can access those folders who can list them who can execute files in them who can read them and who can write them because for security reasons you don't want the world to be able to see everything your in your GPG keys your encryption keys or your SSH keys so it's very important to set those permissions properly now setting permissions there's two ways to do it with the chmod command you can either add so let's say I'm gonna change that Applications folder so I'm going to type applications and I'm gonna add I want to change this permission to say that the user can't execute it so I'm gonna user minus X oops I did the wrong order though let's do it this let's do it the right order so first we do u minus X and then we do applications notice that fish and most shells are doing auto completion when I type the first few letters of applications it actually offers me what it thinks is the right choice and I just press tab saves me some typing so now let's go back and do a LS long and look at applications and I should have yes I did I took away the X permissions so now if I try to list applications it'll say no you don't have permission let's fix that right now because I want to be able to list my applications so again chmod and I'm gonna say instead of you notice this it remembers the last time I typed a command and I'm gonna change that to plus these are shown you can also be doing this in in hexadecimal so the X is the one bit the W is the 2 bit and the R is the 4 bit so it's possible to do the same thing with numbers in fact you can set the whole directory with 3 X adesso mole numbers 7 7 7 would give it all permissions watch I'll do that chmod 7 7 7 applications now we'll do it LS long take a look at the applications and you see I've turned on all permissions for applications probably don't want it set like that so maybe we'll go back to the way it was which is chmod remember I had all permissions for the user 7 but I didn't have any permissions for the group or the world that would be 700 does that make sense and now we'll do an LS dash L and if I go back I've set it back to the way it was so what we're seeing here which is rwx blank blank blank blank blank blank is the same as 700 all right here's an exercise how would I show this though there's a 7 in the first position the second position R dash X there's a 1 that plus 0 plus 4 that's a 5 same thing here so this setting is 7 5 5 if I did chmod 755 that would change applications to the audio setting etc etc you might say how do I remember all of this well that leads us to a really useful command man that's the man pages and almost all Unix commands have man pages generated when you install the tool in this case if I type man chmod that's gonna get the manual for the command it's a little cryptic these are the switches - f hv - R - L that's all of these and then the file name so if for instance I typed as I first had typed it backwards and said what the heck happened I did it wrong I put the file name first not last oh yeah I can go back and do the manual this explains what it does it shows what all the switches are and it uses a pager which means it's only going to show the first page and then if I press spacebar it'll show the next page if i press b it'll go back to the first age and if I press Q it exits out so those are very handy ways to look at the manual pages for the commands you want so we've learned LS we've learned CD we've learned man there are many many more commands available to you I could go on and on and on but it's handy to know at least that many and the man command is the most useful command if at any time you don't know how something works having the man command is is the key to understanding it there's one more tool that I have installed and I'll show you real quickly this is a T's for next week I use brew to install programs I'll show you how to do this it's called TLDR and it's a very useful command for finding first brew is gonna update itself look at all the sources make sure it has the latest versions of all the files that's the updating and then it's going to if I don't have TLD arrow and they are installed here it's going to install it TL DR is a man command that just does as you would expect from the name to long didn't read just as a few simple useful tools for you now I've installed TL DR after a bit of churning you'll get used to all this stuff that spit out by the way--by terminals and in the long run you you ignore a lot of it but eventually you'll find it's useful it's telling you something let's try TL DR for the chmod command and you'll like the results of this because it's just gonna be very simple this is just the basics you need to know chmod changes the access permissions of a file or directory and it even gives you some sample commands we already learned this one you plus X give the user owns a file the right to execute it you plus read write and that's really handy so TLDR is a nice little command I'll show you what Bru is and and how I install this a little bit later so some of the commands are pretty obscure in fact Apple has a whole bunch of other tools that you can use I'll give you just as an example and it'll teach us one more important thing to understand about the command line the command line you when you use it you're operating as yourself as the user but there may be times when you operate want to operate as an administrator and to operate as an administrator there's two ways to do it one you could login as the root user use the command su super user do as you do is a predicate to any other command that you want to use so it'll ask me for the super user password it actually asked me for my password and if I have administrator rights I'll be able to execute it this is a good example software update is a command that Apple gives you it's not on all UNIX machines I'm going to update my system with this command it's now asking me for my user password and if I'm in the list of super users or people who are allowed to do this I'll be able to execute the command this is a security procedure which is really great super users can do everything including erase the whole Drive if I type RM which is remove - RF which means recursive and force and the wildcard star which means all files this will delete everything from my hard drive this is a very dangerous command and you shouldn't be able to execute this unless you're the super user so I'm gonna leave this out I won't hit return because I don't want to take any chances here's a useful command that Apple gives you it's a command to change the NVRAM the non-volatile Ram is where Apple stores a bunch of information about the system normally you don't modify it but you can from the command line and here's a really useful tool I'm gonna show you one of the commands which is start up you capitalization is important here equals percent zero zero modern Macintosh computers don't have the bong that you start up with bong and I think a lot of us want to have that bong so if you have a modern Mac laptop and you want to start up long to come back this is the command you'd use it says notice the command is startup Butte it says startup mute equals and in this case false all right I think I typed a double equals let me change that equals zero zero that's going to turn off the startup mute by the way notice I didn't have to type my password again the password is remembered for about 15 minutes so if you execute sequential sudo commands after the first one you won't have to enter it again for a little while now to turn it back on what do you think NVRAM that's the command this is the parameter notice there's no - that's how Apple does it start up mute equals how would we make this true 0 1 0 1 is true zero zeros false now I have no bonging sound on my iMac when I start up actually that's probably the way I wanted you'll see Apple has a whole bunch of commands like software update and NVRAM that are unique to the Apple operating system and many of these are only accessible to the command line so a lot of times you'll see I'm gonna change kind of fundamental ways that the Apple Macintosh OS works you can't do it in a GUI you can't do it the startup preference of pain you can only or the preference patent system preference pane you can only do it with a command line so it's good to know some command lines we'll talk more about fish my favorite shell at later times and I'm gonna show you brew next week which is something everybody who uses the Mac command line should have on their Macintosh it's an easy way to add additional Unix commands and really make your Mac's sing all right a little tour of the command line it's worth spending some time with it remember that man command and you're also plenty of tutorials online that will give you lots of different commands you can play with but those are the basics thanks for joining us of course hands on mech brought to you by our great friends at IT Pro TV it's made learning IT and finishing IT certificates possible students are able to learn quickly at IT Pro TV right now with everything that's going on in the world with travel restrictions and social distancing and shelter-in-place it's never been a better time go to IT Pro TV slash twit sign-up for the remote learning opportunities that IT Pro TV has to offer go to IT Pro TV slash twit use the code twit 30 you'll get an additional 30 percent off the lifetime of your active subscription that's IT Pro dot TV slash to it and don't forget that offer code twit 30 IT Pro TV build or expand your IT career and enjoy the journey I'm Leo Laporte thanks for this little command-line adventure more hands-on Mac next Friday I'll see you then bye-bye [Music]
Info
Channel: Hands-On Mac
Views: 15,013
Rating: undefined out of 5
Keywords: TWiT, Hands-On Mac, Leo Laporte, Mac help, Mac how-to, Mac Terminal, Mac Terminal commands
Id: ctF-S3RLcME
Channel Id: undefined
Length: 21min 53sec (1313 seconds)
Published: Fri Apr 17 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.