Labs ICT
โญ Pro Login

Listing Files

You've moved around, but how do you see what's actually inside a directory? That's where ls comes in โ€” the single most-used command in Unix. You'll type it hundreds of times a day once you get comfortable.

List files โ€” ls

Plain ls shows you the names of files and directories in your current location.


$ ls
Desktop  Documents  Downloads  Music  Pictures
    

Simple enough. But ls really shines when you add flags.

Try it Yourself โ†’

ls -l โ€” long format

Add -l and you get the detailed view โ€” permissions, owner, size, and modification date.


$ ls -l
drwxr-xr-x  2 you  you  4096 Jun 15 10:30 Documents
-rw-r--r--  1 you  you   142 Jun 14 09:15 notes.txt
    

That first column shows the file type (d for directory, - for regular file) and permissions. The numbers after are the file size in bytes and the timestamp.

ls -a โ€” show hidden files

Files starting with a dot are hidden in Unix. ls -a reveals them.


$ ls -a
.  ..  .bashrc  .profile  Documents
    

Notice . and .. always appear. Hidden files are usually configuration files โ€” .bashrc, .gitconfig, .ssh.

ls -h โ€” human-readable sizes

Combine -h with -l to get sizes in KB, MB, GB instead of raw bytes.


$ ls -lh
-rw-r--r--  1 you  you  1.2M Jun 15 10:30 bigfile.zip
    

Much easier to read than 1234567 bytes.

Combining flags

You can combine flags however you like. The most common combo is ls -la โ€” show everything, detailed view. Or ls -lah for the full picture with readable sizes.


$ ls -lah
total 28K
drwxr-xr-x  4 you  you 4.0K Jun 15 10:30 .
drwxr-xr-x  8 you  you 4.0K Jun 14 08:00 ..
-rw-r--r--  1 you  you  220 Jun 14 08:00 .bash_logout
-rw-r--r--  1 you  you 3.7K Jun 14 08:00 .bashrc
-rw-r--r--  1 you  you  807 Jun 14 08:00 .profile
    

This is the view I use 90% of the time. Get used to typing ls -la โ€” it's muscle memory for every Unix user.

๐Ÿงช Quick Quiz

What flag shows hidden files when listing a directory with ls?