guest@linuxthings:~/guides$ man filesystem
The Filesystem
Linux files are organized into a single hierarchy rooted at '/'. Unlike Windows, there are no drive letters (C:, D:). Drives are mounted at directories within the tree.
Key Directories
Directory | Purpose |
|---|---|
/ | Root directory |
/bin, /usr/bin | Programs for all users |
/sbin, /usr/sbin | Programs for system administration |
/usr/local | Software installed locally, outside the distro's packages |
/etc | System configuration files |
/home | User home directories |
/root | The superuser's home directory |
/boot | The kernel and boot loader files |
/lib, /usr/lib | Shared libraries used by programs |
/opt | Optional, self-contained third-party software |
/var | Variable files (logs in /var/log, mail, spools, caches) |
/tmp | Temporary files (often cleared on reboot) |
/dev | Device files (disks, terminals) |
/media, /mnt | Mount points for removable and temporary filesystems |
/proc | Process and kernel information (virtual filesystem) |
/sys | Kernel and device internals (virtual filesystem) |
On many modern distributions /bin and /sbin are just symbolic links into /usr.
Paths
An absolute path starts at the root (/home/dan/notes.txt). A relative path starts from your current directory (notes.txt, ../photos). Two special names work everywhere: . is the current directory and .. is its parent. Filenames are case-sensitive, so Notes.txt and notes.txt are different files.
Navigation
pwd # Print Working Directory
cd /usr/bin # Change Directory to absolute path
cd .. # Go up one level (parent)
cd ../docs # Up one level, then into docs
cd ~ # Go to your home directory
cd ~fred # Go to user fred's home directory
cd - # Go to the previous directory
cd # Go to home directory (same as cd ~)Listing Files (ls)
ls -a # List all files (including hidden dot files)
ls -l # Long listing (permissions, size, date)
ls -lh # Long listing with human-readable sizes (KB, MB)
ls -ld dir # Show the directory itself, not its contents
ls -R # Recursive listing
ls -d */ # List only directories
ls -S # Sort by size
ls -lt # Sort by modification time, newest first
ls -ltr # Oldest first (reverse the sort)
ls -F # Mark types: / directory, * executable, @ link
\ls # Run the real ls, bypassing any aliasReading a Long Listing
ls -l notes.txt
-rw-r--r-- 1 smith users 1168 Oct 28 14:02 notes.txtFrom left to right: file type and permissions, number of hard links, owner, group, size in bytes, last modification time and name. The first character is the type: - regular file, d directory, l symbolic link, b block device, c character device, p named pipe, s socket.
Peeking at the Kernel
Files under /proc and /sys are generated on the fly by the kernel. They look empty to ls but have contents when you read them.
cat /proc/version # Kernel version (same as uname -a)
cat /proc/cpuinfo # Processor details
cat /proc/meminfo # Memory details
cat /proc/uptime # Seconds since boot
ls /proc/$$ # Information about your current shell process