Hi this is Gary with MacMost.com.
Let me show you how you can work with your files in the Terminal instead of the Finder.
MacMost is brought to you thanks to a great group of supporters.
Go to MacMost.com/patreon.
There you can read more about it, join us and get exclusive content.
So if you've ever wondered if there's a way to type instead of drag and drop to access
your files, well there is!
You can use the Terminal to access your files, your folders, work with them, rename them,
move them around, open them, and do almost everything you could do in the Finder except
by typing instead of using the cursor.
Let me show you the most basic commands to get you started.
Alright, so let's launch Terminal and it's going to give us this default window.
Let's change it to something a little easier to look at.
I'm going to go to Shell, and Show Inspector, and switch to one of these other profiles
here.
I'm also going to use Command and + to make the font size a little bit bigger.
Then I'm going to stretch it out a bit.
You can go to Terminal Preferences and set these up as defaults if you want.
Now when you're working in the Terminal you're in a specific folder on your hard drive, just
like you are when working in the Finder.
So, for instance, in the Finder here I'm here at my Home folder level.
This is where this Finder window is working.
The same thing with the Terminal window.
It's somewhere as well.
You could find out where by doing PWD.
The WD for working directory.
You could see I'm also at the Home folder there.
So if I were to list the files there I should see the same files, actually folders, that
are here.
I can list them by doing LS.
Sure enough there are those same ones.
I can get a better list by doing LS space dash l (lower case l.)
This will put them in a list format here.
You could see things like modified time, the file size in bytes, folders of course generally
don't have much of a file size to them.
LS is the main command for being able to see your files.
So it has a lot of ways to modify it.
If you do MAN for manual and ls you'll get a complete list of all the ways to modify
it like that dash lower case l that I just showed you.
You can spacebar through this list and do Q to quit.
If I were to do ls then space dash l and also add the modifier capital S then I'm going
to get everything sorted by file size.
If I were to do ls then l and then H then it's going to give me the file sizes in b
for bytes, k for K, m for megs, and g for gigs.
It's a little easier to read.
If I wanted to sort it by time instead I can do ls dash l and then t for modify dates,
the most recent ones at the top.
If I wanted to change directory all I need to do is cd to change directory and then type
a directory name.
For instance let's go into the Documents folder.
I'll start typing documents but I don't have to type out the entire thing.
The real key to using Terminal is not typing every single character but using the auto
complete function which is the Tab key.
Since I've typed doc and there's only one thing here that starts with doc why should
I have to finish off typing the characters.
I just hit Tab and it finishes it for me.
It even puts a slash afterwards.
Then I hit Return and now you can see I'm at the Documents level.
I'll do ls dash l and I can see things that are in here.
If I want to go up I can do cd and then .. two dots goes up.
One dot kind of stands for the current directory and two dots stands for the directory above
it.
So now I'm back here.
Let's go back down and then let's go into one of these sub directories.
What happens if something has a space in it.
How do you deal with that?
Well, I'll start typing Project and then I can do a backlash space to represent a space
and then A. I could also do quotes.
So I could do "Project A".
Now if I list what's in here I'll see what's in that folder.
If I want to open a file in the Finder I would just double click it to open.
You can do the same thing here but it's the open command.
So type open and then start typing the name of the file.
So, for instance, I'll do My and then backslash space and S. I've started typing My Shared
File.
I'll do Tab to auto complete and I'll hit Return.
It's going to open up that file in the default app which is TextEdit in this case.
If I wanted to open it up in something else I could do the dash a and then the application.
Now I have to actually get the full path to the application.
So I can start typing the path with a slash which means the top level of this computer
and then a.
There's only one folder at the top level of this computer with A in it.
That's the application folder.
So I'll hit Tab and you can see it auto completes that.
I'll start typing Pages and I'll do Tab there to auto complete that.
Now that I've given the path to Pages if I hit Return then it will open the file but
now in Pages instead of TextEdit.
If I want to delete a file I use the rm command to remove a file.
So I'd do rm and I can start typing the command.
So like I can say this image here.
If you want to remove a folder you can do rmdir but that only works if the folder is
empty.
Otherwise you need to use rm and then dash and then capital R which means which means
recursively look inside that folder and delete everything in there and then give it the name
of the folder like Newfolder.
It will delete all the contents of the folder and the folder.
Of course it's a very dangerous command just as deleting something in the Finder is dangerous.
If you want to get information on a file you can do that with the File command.
Then type the name of the file, auto complete there, hit Return and you get all sorts of
stuff here like the fact that it's jpeg image data and even the size of the image itself.
You can also do mdls for metadata and this will give you a bunch of metadata attached
to the file.
Now what if you want to move a file.
Let's take a look at what we've got here.
I've got this folder called New Folder.
Let's move it into there.
So I can do mv for move and I could do p1 and have that auto complete there.
Then I can start typing the name of the file.
If I want it to be somewhere else completely I could start doing the path to the file.
You can do paths with a slash for the top level directory which probably isn't what
you want.
But you can use tilde slash for your Home directory.
So if I, for instance, know that the pictures folder is there I can do this to move it to
Pictures.
If I wanted to move inside of this current directory, into the New Folder one, I could
do it like that.
Now I can go into New Folder and look there and I can see that that file now has been
moved there.
I can also change its name using mv because mv you could get a full name.
So I could type the name of the current file and then I could give it a path to where I
want it to go and also include the new name for the file.
Or I could just forget about the path completely and I can call it what I want right here.
So I'll just call it new pic.jpeg.
So basically it's moving the file in place with a new name.
If you ever want to duplicate a file you can do that using ditto.
So I can include the file there as the first part and then I can give it something else
as the second.
Now I've got two of those.
You can do that for an entire folder.
If you've got a folder it's going to make a duplicate of everything in the folder as
well.
If you want to create a new folder you can do that with mkdir, make directory, and you
can call it whatever you want.
You can see there there's a new folder there now.
So now let me show you how to search in the Terminal.
So searching is a very important function of the Finder.
So you're going to want to do that in Terminal as well.
So here we have two files that start with the word new in it.
Let's go up a level, cd.. to go up, and now let's see if we can find the two files because
we don't see them here at this level.
To do a simple search we can use find and then dot slash for the current working directory.
You can do tilde slash for your entire home directory but that's going to include a lot
of different data, like reminders, and contacts, and such.
Slash is even worse because that's the top level of your computer so it includes like
all your system libraries and everything.
So getting to the right directory using dot slash ./ is a really good way to go.Then do
dash name, -name, and then quotes you can put the name.
Now if you don't know the exact name of the file that's okay.
You can use an asterisk for a wildcard.
We'll put that in quotes there and see what we get.
So we can see here inside New Folder we've got those two files.
Now a better way to search is to use mdfind which is Spotlight.
So Spotlight you can use in the Finder but you can also use it here in Terminal.
So if I do mdfind and then do something like newpic then it's going to return everything
it can find with either that in the file name or in the contents of the file as well.
A couple of extra tips here.
You may have noticed that I can do up arrow to go to the previous command.
So I can do up arrow to go to a previous command and then you can edit it by moving the cursor
with the arrow keys.
You can do Option and arrow key to quickly move through the line.
Also if you want to indicate a certain file or directory you can drag and drop from the
Finder into Terminal.
So I can do cd and I could switch to the Finder here.
If I were to drag and drop something like say the downloads folder into Terminal it
would put the full path there.
Then I could hit Return and now I've gone to that directory or performed that operation
on that file.
You can use this to get to very difficult places like, for instance, if I were to go
to iCloud Drive there's the Pages folder.
How do I get to the Pages folder.
Where's that even located considering it's in iCloud Drive.
It's not on my Home folder.
I could do cd there and I could drag this in and you can see it's going to give me the
very long path.
Not only is it hard to remember that but it's hard to type.
So it's easy to drag and drop.
Now I'm actually there.
Now I can look at what files are there and perform operations on them just like anywhere
else.
Now if you're fast at typing you may notice that you could do everything in the Terminal
just as fast as you could do it in the Finder.
Some things you can do faster.
Some things will take more time.
But it definitely is a viable alternative for a lot of people.
Plus you kind of look really cool doing it.