lsList directory contents
ls shows what's in a directory. With a few options it also shows permissions, owners, sizes and times, hidden files, and lets you sort by size or age: the first thing you check on any box.
ls [OPTION]... [FILE]...You've just logged in to a server and want to see what's in your home directory and an app folder.
lsThe program that lists directory entries.
ls opens the directory and reads its entries with the getdents system call. A directory is just a list of names, each pointing to an inode number. For a plain listing that is all ls needs. With -l it also calls stat (or statx) on every entry to read the inode: type and permission bits, owner and group IDs (turned into names through /etc/passwd and /etc/group), size, link count and timestamps. That is why ls -l on a directory with a million files is slow while plain ls is fast, and why a listing can show a name whose stat fails (a broken symlink or a file deleted mid-listing).
A directory only stores names and inode numbers; -l reads every inode to fill in the other columns.
The shell starts the ls program with two arguments: the option -l and the path /app.
-lLong format: type, permissions, links, owner, group, size, mtime, name-aInclude hidden entries (names starting with .), plus . and ..-ALike -a, but without . and ..-hHuman-readable sizes with -l: 1.1K, 23M, 4.2G-tSort by modification time, newest first-SSort by size, largest first-rReverse the sort order (oldest or smallest first)-RRecurse into subdirectories-dList a directory itself, not its contents-iShow each entry's inode number-1One name per line (handy in scripts and pipes)--color=autoColour by type: blue directories, green executables, cyan linksls -l | grep '^d' to count directories, then parsing columns with cutls output is for humans: names with spaces or newlines break column parsing, and the format differs between systems.
find . -maxdepth 1 -type d | wc -lls -lS /var/log to find what's filling the diskls only sizes the files in that one directory; a 30 GB subdirectory shows as 4096 bytes.
du -sh /var/log/* | sort -hls dir/*.log when there are 200,000 log filesThe shell expands the glob first and can fail with 'Argument list too long' before ls even runs.
find dir -name '*.log' | headReading 'total 32' as 32 filestotal is the number of 1K disk blocks used by the listed files, not a count of entries.
ls -A | wc -lTry these on a Linux machine of your own. Each task has a hint and a solution.
List everything in your home directory, including hidden files, with human-readable sizes.
In /var/log, show the three largest files.
Show the permissions of the /tmp directory itself, not its contents. What is the extra letter at the end?
Find out whether /usr/bin/python3 is a real file or a link, and where it points.
lsList directory contents
ls shows what's in a directory. With a few options it also shows permissions, owners, sizes and times, hidden files, and lets you sort by size or age: the first thing you check on any box.
ls [OPTION]... [FILE]...You've just logged in to a server and want to see what's in your home directory and an app folder.
lsThe program that lists directory entries.
ls opens the directory and reads its entries with the getdents system call. A directory is just a list of names, each pointing to an inode number. For a plain listing that is all ls needs. With -l it also calls stat (or statx) on every entry to read the inode: type and permission bits, owner and group IDs (turned into names through /etc/passwd and /etc/group), size, link count and timestamps. That is why ls -l on a directory with a million files is slow while plain ls is fast, and why a listing can show a name whose stat fails (a broken symlink or a file deleted mid-listing).
A directory only stores names and inode numbers; -l reads every inode to fill in the other columns.
The shell starts the ls program with two arguments: the option -l and the path /app.
-lLong format: type, permissions, links, owner, group, size, mtime, name-aInclude hidden entries (names starting with .), plus . and ..-ALike -a, but without . and ..-hHuman-readable sizes with -l: 1.1K, 23M, 4.2G-tSort by modification time, newest first-SSort by size, largest first-rReverse the sort order (oldest or smallest first)-RRecurse into subdirectories-dList a directory itself, not its contents-iShow each entry's inode number-1One name per line (handy in scripts and pipes)--color=autoColour by type: blue directories, green executables, cyan linksls -l | grep '^d' to count directories, then parsing columns with cutls output is for humans: names with spaces or newlines break column parsing, and the format differs between systems.
find . -maxdepth 1 -type d | wc -lls -lS /var/log to find what's filling the diskls only sizes the files in that one directory; a 30 GB subdirectory shows as 4096 bytes.
du -sh /var/log/* | sort -hls dir/*.log when there are 200,000 log filesThe shell expands the glob first and can fail with 'Argument list too long' before ls even runs.
find dir -name '*.log' | headReading 'total 32' as 32 filestotal is the number of 1K disk blocks used by the listed files, not a count of entries.
ls -A | wc -lTry these on a Linux machine of your own. Each task has a hint and a solution.
List everything in your home directory, including hidden files, with human-readable sizes.
In /var/log, show the three largest files.
Show the permissions of the /tmp directory itself, not its contents. What is the extra letter at the end?
Find out whether /usr/bin/python3 is a real file or a link, and where it points.