`
A structured way to store and manage files. Acts as a interface between the OS and the storage device.
FAT(File Allocation Table): Used in older Windows systems. Simple and easy to implement, but lacks features like journaling and permissions.
NTFS(New Technology File System): Used in modern Windows systems. Supports large file sizes, file permissions, journaling, compression and encryption.
ext4: Used in Linux systems. Also supports large file sizes, journaling, and file permissions.
HFS+(Hierarchical File System) / APFS(Apple File System): Used in macOS systems. Supports journaling, encryption, and file permissions.
In Linux, the file system organizes files and directories into a hierarchical structure.
| Directory | Description |
|---|---|
/ |
Root Directory: The top-level directory in the file system hierarchy. |
/bin |
Binaries: Contains essential binary executables like ls, cp, mv. |
/boot |
Boot Files: Contains boot loader files and the kernel image. |
/dev |
Devices: Contains device files for hardware devices. |
/etc |
Configuration Files: Contains system-wide configuration files. passwd, fstab… |
/home |
Home Directories: Contains user home directories. |
/lib |
Libraries: Contains shared libraries used by binary executables in /bin and /sbin. |
/media |
Removable Media: Mount point for removable media like USBs. |
/mnt |
Mount Point: Temporary mount point, when manually mounting a storage. |
/opt |
Optional: Contains optional software packages. |
/proc |
Process Information: Virtual filesystem with information about the system processes and hardware. |
/root |
Root User: Home directory for the root user. |
/sbin |
System Binaries: Contains essential system binaries like init, shutdown. |
/tmp |
Temporary Files: Contains temporary files created by applications. |
/usr |
User Binaries: Contains user binaries, libraries, documentation. |
/var |
Variable Files: Contains variable data like logs, mail, cache. |
In Linux, file permissions define who can read, write or execute a file.
Each file and directory has 3 permissions for groups, User(u) -> owner, Group(g) -> group memebers that share access, Others(o) -> all teh other users.
Permissions are represented by 3 characters:
r -> Read, represented by 4.w -> Write, represented by 2.x -> Execute, represented by 1.Permissions are represented by 3 sets of characters:
rwxrw-r-- -> is divided into 3 sets, rwx for owner, rw- for group, r-- for others.
rwxrw-r-- -> 764 in octal representation.
rwx can be represented by 4 + 2 + 1 = 7.
lsList files and directories.
ls -l # Long listing format
ls -a # List all files including hidden files
ls -lh # Human-readable file sizes
touchCreate an empty file.
touch file.txt
touch file1.txt file2.txt
catConcatenate and display file content.
cat file.txt
cat file1.txt file2.txt
cat > file.txt # Create a file and write content
cat >> file.txt # Append content to a file
cat file.txt | less # Display file content page by page
cpCopy files and directories.
cp file.txt newfile.txt
cp -r dir1 dir2 # Copy directories recursively
mvMove or rename files and directories.
mv file.txt newfile.txt
mv file.txt dir/ # Move file to a directory
rmRemove files and directories.
rm file.txt
rm -r dir/ # Remove directories recursively
chmodChange file or directory permissions.
Numeric Mode: chmod 755 file.txt -> rwxr-xr-x
Symbolic Mode: chmod u+r file.txt -> Adds read permission for the owner.
Symbolic Mode Syntax:
u -> User, g -> Group, o -> Others, a -> All.+ -> Add permission, - -> Remove permission, = -> Set permission.chmod u+x file.txt # Add execute permission for the owner
chmod g-w file.txt # Remove write permission for the group
chmod o=r file.txt # Set read permission for others
chmod 755 file.txt # Set permissions using numeric mode
chownChange file or directory owner.
chown user:group file.txt # Change owner and group
chown user file.txt # Change owner
chown :group file.txt # Change group
chgrpChange file or directory group.
chgrp group file.txt # Change group
chgrp :group file.txt # Change group
umaskSets the default file permissions when a file is created umask is reponsible to set its permissions.
umask 022: sets default permissions to 755 for directories and 644 for files.umask 022 -> 777 - 022 = 755 for directories. 777 is the default permission for directories.
umask 022 -> 666 - 022 = 644 for files. 666 is the default permission for files.
If the umask is set to 022, the default permissions for files will be 644 and for directories will be 755. Which is by default in most of the systems.
statDisplays detailed information about a file, including its permissions.
stat file.txt
stat -c %a file.txt # Display only the permissions