Day 2 Summary
This summary covers the core concepts from the second day, focusing on filesystem navigation, file editing, access control, and advanced file searching techniques.
Session 4: The Linux Filesystem
This session introduces the hierarchical structure of the Linux filesystem and the essential commands for managing files and directories.
Filesystem Structure & Standard Directories
The Linux filesystem is a tree-like structure starting from the root directory, represented by /. All files and directories appear under the root directory, even if they are stored on different physical devices.
File Paths & Navigation
Paths are used to locate files and directories within the filesystem.
- Absolute Path: A path starting from the root (
/). Example:/home/user1/Documents/report.txt - Relative Path: A path starting from the current directory. Example:
Documents/report.txt
Navigation & Management Commands:
| Command | Description |
|---|---|
pwd | Print Working Directory. |
cd <path> | Change Directory. |
ls -lha | List directory contents in long, human-readable format, showing all files. |
mkdir -p <dir> | Create a directory, including parent directories if needed. |
cp -r <source> <dest> | Copy files or directories (recursively). |
mv <source> <dest> | Move or rename files or directories. |
rm -r <file/dir> | Remove files or directories (recursively). Use with caution. |
ln -s <target> <link_name> | Create a symbolic (soft) link. |
Finding Files and Checking Disk Space
The find command is a powerful utility for searching for files and directories based on various criteria such as name, size, owner, and modification time. The df command reports filesystem disk space usage.
Practical `find` Examples:
| Command | Explanation |
|---|---|
find /home -name "p*" | Searches inside the /home directory for any file or directory whose name starts with "p". |
find /home /tmp -name "p*" 2> /dev/null | Searches in /home and /tmp, redirecting errors (like "Permission denied") to /dev/null to hide them. |
find /home -name "s*" -type f | Finds items starting with "s" but limits results to files only (-type f). |
find /home -name "s*" -type d | Finds items starting with "s" but limits results to directories only (-type d). |
find /home -type f -size +200k | Finds all files in /home that are larger than 200 kilobytes. |
find /home -type f -size -10M | Finds all files in /home that are smaller than 10 megabytes. |
find /home -type f -size 0 | Finds all empty files (0 bytes in size). |
find /home -type f -mtime -1 | Finds files modified less than 1 day ago (within the last 24 hours). |
find /home -type f -mmin -15 | Finds files modified less than 15 minutes ago. |
find ... -exec cp {} /tmp/found-files/ \; | The -exec action performs a command on each found file. This example copies the file ({}) to another directory. |
find ... -exec rm {} \; | Destructive Command: This finds files and permanently deletes them. Use with extreme caution. |
`df` (Disk Free) Examples:
| Command | Description |
|---|---|
df | Displays filesystem usage in 1K blocks, which can be hard to read. |
df -h | Displays filesystem usage in human-readable format (K, M, G), which is much more useful. |
Sessions 5 & 6: Editing and Access Control
Editing Files with Gedit
gedit is a simple graphical text editor useful for creating and modifying text files, especially configuration files. It can be launched from the terminal with gedit <filename> & to keep the terminal available.
File Access Control
Linux controls access to files via permissions for the user (owner), group, and others. Each can have read (r), write (w), and execute (x) permissions.
Permission and Ownership Commands:
| Command | Description |
|---|---|
chmod 755 <file> | Sets permissions using octal notation (r=4, w=2, x=1). This example gives rwx to owner, and r-x to group/others. |
chmod g+w <file> | Adds write permission for the group using symbolic notation. |
chown <user>:<group> <file> | Changes the owner and group of a file. |
umask | Sets the default permissions for newly created files and directories. |