Is there a differernce between directories and files when using the CLI (command line interface)?

I just completed the first course in Learn the CLI. I was wondering what difference (if any) there is between a directory and file? It seems that maybe there is, but I couldn’t find any explanation in the lessons.

For reference, I followed this Codecademy video on how to download Git Bash (to practice what I’ve learned so far) for my Windows 10 OS. I’m not familiar with Mac or Unix based operating systems. Also, if I am using Git Bash incorrectly, please let me know. I understand that Windows Powershell is the CLI for Windows, but Codecademy recommended Git Bash. Thank you!

A directory is like a tree. There is a root directory, or parent and from it there are branches which are children.

The explanation is right on the first page of that lesson:
" A filesystem organizes a computer’s files and directories into a tree structure:

  1. The first directory in the filesystem is the root directory . It is the parent of all other directories and files in the filesystem.
  2. Each parent directory can contain more child directories and files. In the filesystem on the right, blog/ is the parent of 2014/ , 2015/ , and hardware.txt .
  3. Each directory can contain more files and child directories. The parent-child relationship continues as long as directories and files are nested."

And an image is provided for reference:

1 Like

Thanks for your reply! Just making sure I understand: a directory is not the same as a file, right? If so, what exactly is a directory?

Files are objects. Directories are tree nodes. Think of them as the starting point of a new branch. Branches can have other branches, and they can have leaves, but leaves cannot have branches. They are termination points.

If you call up the directory (ls) you’ll see that directories have a different Mode than files, and they also do not have file length.

directory_vs_file

3 Likes

Ah, I’m grasping the difference now. Much appreciated!

1 Like