Watching:

How to List Files and Directories on Your Mac OS X Computer


show more Listing files and directories provides you with in-depth training on IT. Taught by Kevin Skoglund as part of the Unix for Mac OS X Users show less
please wait ...

Listing files and directories

In the last movie we became familiar with the concept of the working directory and we saw how we could use pwd to show us our present working directory. Now what I want us to do is see how to see what files and folders are inside that present working directory, and we do that with the ls command. We got a peek at it earlier. ls on a line by itself will just list the contents of our present working directory. Desktop, Documents, Downloads, Library and so on. If we look over here that exactly matches what we see in the Finder window. Desktop, Documents, Downloads and so on.

In addition we can pass in some options to ls. We could do man ls and see a list of all of those, but I am just going to show you the couple that I think are the most important. ls -l is going to give us a different kind of listing. ls -l option, now we get them in a vertical format. Notice the last column there still has the file names, but going top to bottom and then over to the left, all those other columns give us information about the file, the size of it, the permissions on it, the owner of it, the time, all those things we'll talk about lot later on, we'll get into those, but just ls -l will show you this different version of it.

If we add another option to it, we can do it with or without the l, but I like doing it with it. ls -la and hit Return. Now we get that same list, but notice that we got a few extra files there. There is ., .., .CFUserTextEncoding, .DS_Store, .Trash and .bash_history. Now you may or may not have exactly those same ones. Don't worry about it. The important thing to understand is that the dot represents the current directory. That's all it is. It's that sort of symbol or a placeholder that means this directory that I'm in right now.

Dot dot refers to the parent of this directory. It's the directory that's right above this, and in this case because our pwd returns users kevin, .. is a reference to Users. But we are always going to have dot and dot dot to refer to those two directories. The other four files there are what we call dot files, because they begin with the dot and dot files are invisible config files. Notice that they don't show up here. The Finder is set to hide dot files by default.

We don't need to see them. They are just configuration files. So for example .Trash is files that are in the trash. That's where my trash is. If you ever wondered how does it know when files are in the trash, well, it moves them from let's say your desktop into this folder and it sits there waiting in this hidden folder until you throw them away, and then it empties out that folder. That's where those trash files are stored. Then we have DS_Store. That's actually for the Mac desktop, the Finder, to store different options about how we're viewing this folder.

Whether it is in this sort of layout, the size of the window, the position of the icons, all that gets stored in this little configuration DS_Store. Bash_history we'll talk about later, but that's where we store history of those commands that we have been typing and then user text encoding is another just configuration file that the Mac uses. Notice that there is also another difference here. Some of these have Ds at the front of the line while some of them just simply have dashes. The dashes is a file. The d is a directory. That's what it's letting you know. That's your tip-off of whether something is a directory or not, is whether that line begins with the D.

There is a third possibility that sometimes shows up there that we'll talk about later. Instead of D and dash you could have an L, which will be for a link or a shortcut. It's like an alias in Unix. So that's how we list the files. That's how we see the files that are there. We can pass in just ls, if we just want a very simple list. We can pass in ls -la if we want that longer list and actually one other thing I like to add as an option is ls -lah, and that returns the size of these different things in human readable format. 510 bytes, 15 kB, 1.1 k. That just gives us a nicer size that I think is a little more pleasant to read.

Listing files and directories
Video duration: 3m 59s 6h 35m Beginner

Viewers:

Listing files and directories provides you with in-depth training on IT. Taught by Kevin Skoglund as part of the Unix for Mac OS X Users

Subject:
IT
Software:
Mac OS X Unix
Author:
please wait ...