Introduction to the Linux Filesystem and Basic Commands
Introduction
"Hello everyone! In this blog, we’ll cover the basics of the Linux filesystem and introduce a few essential commands."
Filesystem Concept
"The filesystem in Linux is organized as a hierarchical tree starting from the root (/
), branching out into various directories. Navigating and understanding this structure is crucial for deepening your Linux knowledge."
Default Directories in Linux
"These directories are set up automatically when you install Linux:"
/bin
: Contains essential binaries needed to boot your system.
What are binaries? Think of them like executable files for your operating system (OS). When you install Linux, it’s similar to installing any software on your computer. You download an ISO image, which extracts files and organizes them in specific locations. After installation, each time the OS runs, it triggers certain files to operate, which are stored in the/bin
directory./home
: The home directory, similar to the Desktop folder on Windows. When you log in to Linux, this is your landing point, where you’ll store personal documents and downloads./etc
: Stores configuration files for the system and applications.
Example: This is similar to the installation paths chosen on Windows. When software is installed, configuration files are stored here./var
: Contains variable files, like logs.
Example: For instance,/var/log
holds system log files where you can track actions taken on your system./tmp
: A temporary file storage area, automatically cleared on reboot./dev
: Contains device files (e.g., hard drives, USB devices).
This directory holds details about your hardware components./proc
: Contains information about system processes./mnt
and/media
: Default mount points for external devices like USBs and DVDs.
Filesystem Types
Ext4: The most widely used on Linux, reliable and high-performing.
XFS: Optimized for large files, often used in enterprise environments.
Btrfs: Supports advanced features like snapshots, which allow you to save the filesystem’s state.
FAT32/exFAT: Commonly used on USB drives to ensure compatibility with Windows.
Basic Commands in Linux
For navigating and managing files:
ls
: Lists directory contentsls -l
: Shows a detailed listls -a
: Includes hidden files
cd
: Changes directorycd ..
: Goes up one levelcd ~
: Returns to the home directory
pwd
: Prints the current directory path
For working with files and directories:
touch filename.txt
: Creates an empty file or updates the timestampmkdir new_folder
: Creates a directorymkdir -p /path/to/multiple/folders
: Creates nested folders
rm filename.txt
: Deletes a filerm -r folder_name
: Deletes a directory and its contents
cp file1 file2
: Copies a filecp -r folder1 folder2
: Copies a folder
mv oldname.txt newname.txt
: Moves or renames a file
For viewing and editing files:
cat file.txt
: Displays file contentsless file.txt
: Opens a file in a scrollable viewhead -n 10 file.txt
: Shows the first 10 linestail -n 10 file.txt
: Shows the last 10 linestail -f logfile.log
: Follows real-time updates (useful for logs)
Conclusion
"Understanding the Linux filesystem is the backbone of system administration. If you’re going to work with Linux, start by understanding the system’s structure. In the next blog, we’ll cover permissions and delve into more filesystem commands."
Subscribe to my newsletter
Read articles from Nithish S directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by