CIS120 Linux Fundamentals by Scott Shaper

ls Command

Have you ever wanted to see what's inside a folder on your computer? That's exactly what the ls command does! Think of it like opening a drawer to see what's inside - it shows you all the files and folders in your current location. This is one of the most important commands you'll use in Linux, and we'll explore all the cool things it can do.

When to Use ls

Common Options

Option What It Does When to Use It
-l Shows detailed information (long format) When you need to know file sizes, dates, and permissions
-a Shows hidden files When you need to see all files, including system files
-h Shows sizes in KB, MB, GB When you want to understand file sizes easily
-t Sorts by date (newest first) When you're looking for recently modified files
-R Shows contents of subfolders When you need to see everything in a folder and its subfolders
-i Shows file inode numbers When you need to know the unique identifier for each file

Practical Examples

Basic Listing

This is the simplest way to see what's in your current folder:

ls

Output would be something like this:

assignments/  notes.txt  project1/  syllabus.pdf

This shows you all the visible files and folders in your current directory.

Long Format Listing (-l)

Use -l to see detailed information about files:

ls -l

Output would be something like this:

drwxr-xr-x 2 student class 4096 Jan 15 10:30 assignments
-rw-r--r-- 1 student class  1234 Jan 14 14:20 notes.txt
drwxr-xr-x 2 student class 4096 Jan 13 09:15 project1
-rw-r--r-- 1 student class  5678 Jan 12 11:45 syllabus.pdf

This shows you detailed information including: - File permissions (like rwxr-xr-x) - Number of hard links - Owner and group - File size in bytes - Last modified date and time - File name

Showing Hidden Files (-a)

Use -a to see all files, including hidden ones:

ls -a

Output would be something like this:

.  ..  .bashrc  .git  .config  assignments  notes.txt  project1  syllabus.pdf

This reveals: - . (current directory) - .. (parent directory) - Hidden files (starting with .) - Regular files and directories

Showing Inode Numbers (-i)

Use -i to see the inode numbers of files:

ls -i

Output would be something like this:

1234567 assignments
1234568 notes.txt
1234569 project1
1234570 syllabus.pdf

Each file has a unique inode number that identifies it in the filesystem. This is useful for: - Finding hard links to the same file - System administration tasks - Understanding file system structure

Tips for Success

Common Mistakes to Avoid

Best Practices