Linux Basics: Filesystem Structure, Navigation, and File Management
The root directory / sits at the top of the hierarchy, where all other partitions are mounted. Key directories define their purposes: /etc for configurations, /var for dynamic data, /proc and /sys as virtual interfaces to the kernel.
/
├── etc # system and app configurations
├── var # variable data: logs, cache, queues
├── proc # kernel and process status
├── sys # devices and drivers
├── tmp # temporary files
├── home # user home directories
├── root # root user's home
├── dev # device files
├── usr # programs and libraries
├── bin # essential utilities (symlink to /usr/bin)
├── sbin # admin commands (symlink to /usr/sbin)
├── opt # third-party software
├── run # runtime process data
├── mnt # manual mount points
└── boot # bootloader and kernel files
/etc: Centralized Configurations
Holds config files for services, network settings, and users. Key files include /etc/passwd for user accounts, /etc/fstab for mount points, /etc/hosts for local hostname resolution, and /etc/ssh/sshd_config for SSH settings.
/var: Dynamic Data
Stores changing files like logs in /var/log, mail in /var/mail, print queues in /var/spool, and web server content in /var/www. It's your first stop for troubleshooting.
Virtual Filesystems: /proc and /sys
/proc provides real-time data on processes and the kernel: /proc/cpuinfo for CPU details, /proc/meminfo for memory stats, /proc/1/ for the init process. /sys offers an interface to devices, letting you tweak driver and hardware parameters on the fly.
User Directories and Devices
/home/username houses personal files and configs (like .config and .ssh). /root is isolated for the root user. /dev represents hardware: /dev/sda for a disk, /dev/null to discard output, /dev/random for entropy.
Navigation: ls, cd, pwd
ls lists directory contents with flags for more details.
ls -l: permissions, owner, size, date.ls -a: hidden files.ls -lh: human-readable sizes (KB/MB/GB).ls -lt: sort by time.ls -R: recursive listing.
cd changes directories:
cd /etc: absolute path.cd ..: go up one level.cd ~: home directory.cd -: previous directory.
pwd prints the current path: pwd -P resolves symlinks.
Finding Files: find and locate
find searches recursively based on criteria.
Examples:
find . -name "*.log": log files.find /var -type f: files only.find / -size +100M: files over 100MB.find /var/log -mtime -1: logs modified in the last day.find /tmp -name "*.tmp" -delete: clean up temp files.
locate uses a database for speed:
locate passwd.sudo updatedbto refresh the index.
On Ubuntu 22.04+, use plocate for better performance.
tree visualizes directory structures: tree -L 2 -a -I "node_modules".
File Management: cp, mv, rm
cp copies:
cp file.txt /tmp/.cp -r dir1/ /backup/.cp -ppreserves metadata.cp -uupdates only newer files.
mv moves or renames: mv old.txt new.txt, mv *.log /archive/.
rm deletes without a trash bin:
rm -r dir/.rm -rf /— extremely dangerous, never run.rm -iprompts for confirmation.
Creating and Linking: mkdir, touch, ln
mkdir -p /path/to/dir creates nested directories.
touch file.txt creates an empty file or updates timestamps: touch -t 202501011200 file.txt.
ln creates links:
ln file.txt hardlink.txt— hard link (shares inode).ln -s file.txt symlink.txt— symbolic link (points to path).
Hard links don't work across filesystems; symlinks are flexible but break if the original is deleted.
Key Takeaways:
/procand/sysare in-memory, not on disk—purely for kernel runtime data.findis versatile;locateis fast with a maintained index.rm -rfdemands caution—no recycle bin safety net.mkdir -pandcd -are scripting essentials.- Hard vs. symbolic links: pick based on needs (shared data vs. path reference).
— Editorial Team
No comments yet.