Listing files in Git & Command Line
Topic 3 of 32 · 8 minFree lessonYou've used ls to see the folders you can move into. It can do a lot more. It can look inside any folder without going there, show files that are usually hidden, and tell you how big each file is.
These are the moves you'll use every day to find your way around a project.
Listing another folder
Give ls the path of a folder, and it lists that folder instead of the one you're in. The terminal stays where it was:
You looked inside notes and website, but pwd shows you never left your home folder. Any path works here, relative or absolute.
Several folders at once
Give ls more than one folder, and it lists each one under its name, with a blank line between them:
The names in front of the colons tell you which list is which.
Hidden files
A name that starts with a dot is a hidden file: ls leaves it out, so it doesn't clutter the list. Programs often keep their settings in hidden files.
An option is an argument that starts with - and changes how a command works. The -a option, short for "all", makes ls show hidden files too:
There's a hidden .reminder.txt in notes. The list also starts with . and .., which every folder has. You met .., the folder above, in the last topic. A single . means "this folder".
Most of the time you don't need those two. -A, with a capital A, shows hidden files but leaves out . and ..:
Your home folder has a hidden file too: .gitconfig holds settings for Git, which you'll meet later in this course.
The long format
-l, short for "long", shows one file per line, with details:
Read each line from left to right:
- The first character is the type:
-for a file,dfor a folder. - The next nine letters say who may read, change or run the file. Skip them, and the small number after them, for now.
learner learneris the account that owns the file, and its group.- The number before the date is the size in bytes. A byte holds one plain letter, space or line break, so
todo.txtholds 53 of them. - Then comes the date and time it last changed, and finally its name.
The total line at the top counts disk space. You can ignore it.
One name per line
ls fits names into columns to save space. -1 (the number one) puts each name on its own line instead, so a long list reads from top to bottom:
Files or folders?
Plain ls shows files and folders in the same way. ls -l tells them apart: folders start with d.
website is a folder. Its size, 4096, is the room a folder keeps for its list of names, not the size of what's inside.
If you give ls the path of a file, it prints the file's name back. With -l, you get that file's details:
ls-a. Without the dash, ls looks for a file called a.ls -la is the same as ls -l -a: the long format, with hidden files too.Try it yourself
Run the code in the editor and answer 8 practice questions on listing files. It's free, you only need an account.