1. Understanding Files and Directories
Files: In Linux, everything is treated as a file. Files can contain text, programs, images, or any other type of data. They are organized within directormkdir: Creates a new directory. ies.
Directories (Folders): Directories are containers for files and other directories. They provide a way to organize and manage files on your system.
2. Basic Commands
ls
: Lists files and directories in the current directory.
ls
cd:
Changes the current directory.
cd <directory_name>
mkdir:
Creates a new directory.
mkdir <directory_name>
touch
: Creates a new empty file.
touch <file_name>
rm:
Deletes files or directories.
rm <file_name>
rm -r <directory_name> # To remove a directory and its contents recursively
pwd:
Prints the current working directory.
pwd
3. Storage Size
Bytes, Kilobytes, Megabytes, Gigabytes, Terabytes: These are units used to measure storage size. Here’s a quick reference: 1 Byte = 8 bits 1 Kilobyte (KB) = 1024 Bytes 1 Megabyte (MB) = 1024 Kilobytes 1 Gigabyte (GB) = 1024 Megabytes 1 Terabyte (TB) = 1024 Gigabytes
4. Checking Storage Usage
df:
Displays the amount of disk space available on the filesystems.
df -h
# -h for human-readable output
du
: Estimates file space usage.
du -sh <directory_name>
# -s for summary, -h for human-readable output
5. Example Usage
Let’s say we want to create a directory named “my_files”, navigate into it, and create a file named “example.txt”.
Create a directory:
mkdir my_files
Navigate into the directory:
cd my_files
Create a file:
touch example.txt
Check the contents of the directory:
ls
Check the storage usage of the directory:
du -sh .