From 9790d42a2945c6d93232e99aef9108a2c23a2820 Mon Sep 17 00:00:00 2001 From: Jerome Hardaway Date: Wed, 7 Feb 2024 21:44:51 -0500 Subject: [PATCH] add remainder of basic commands --- .../listing-and-filtering-files.md | 75 +++++++++++++++--- .../basic-commands/navigating-directories.md | 77 ++++++++++++------- .../command-line/basic-commands/wildcards.md | 70 ++++++++++++++--- .../working-with-permissions.md | 62 ++++++++++++--- 4 files changed, 225 insertions(+), 59 deletions(-) diff --git a/collection-one/modules/command-line/basic-commands/listing-and-filtering-files.md b/collection-one/modules/command-line/basic-commands/listing-and-filtering-files.md index 5c2784c..3d02538 100644 --- a/collection-one/modules/command-line/basic-commands/listing-and-filtering-files.md +++ b/collection-one/modules/command-line/basic-commands/listing-and-filtering-files.md @@ -1,16 +1,69 @@ -# Listing and Filtering Files +# Navigating and Understanding Your Files with Command Line Tools -## `ls` -We've covered `ls` in the previous lesson, but it's worth noting that it's crucial for both navigating directories and listing files. +## Introduction +In the digital terrain of your computer, just like navigating through unknown territories, the command line is your map and compass. Mastering file management commands is akin to developing land navigation skills, enabling you to efficiently locate, list, and manage your files and directories. This lesson builds on the basics and delves deeper into the tools at your disposal. -## `find` -The `find` command is a powerful tool that searches for files and directories based on various criteria like name, size, or modification time. +## `ls` - The First Step in Digital Reconnaissance -## `locate` -The `locate` command offers a quicker but less updated search compared to `find`. It relies on a database that's updated regularly to provide fast results. +Previously, we introduced `ls`, a command akin to a quick perimeter check. It's your first line of inquiry into the current directory, revealing the files and subdirectories it contains. -## `which` -The `which` command locates the directory where a particular executable is stored, making it easier to understand your system's command structure. +### Usage and Options +- **Basic command**: `ls` lists all files and directories. +- **View hidden files**: `ls -a` reveals all files, including hidden ones (those starting with a dot `.`). +- **Detailed listing**: `ls -l` provides detailed information, including permissions, number of links, owner, group, size, and modification date. +- **Combine options**: `ls -la` combines both to give a detailed list of all files. -## Summary -Listing and filtering files are daily tasks for anyone working with the command line. `ls` provides the basics, while `find` and `locate` offer advanced search functionalities. The `which` command is particularly helpful for understanding the location of installed executables. +### Example +```bash +ls -l +``` +This command will display a detailed list of all files and directories, not including hidden files. + +## `find` - The Advanced Search Operation + +Think of `find` as your mission to locate a specific target. It's more sophisticated and can search the entire directory tree based on criteria like name, size, and modification time. + +### Key Features +- **Find by name**: `find /path/to/search -name "filename"` +- **Find by type**: `find /path/to/search -type f` for files, `d` for directories. +- **Find by modification time**: `find /path/to/search -mtime -days` (`-days` for files modified in the last `days`). + +### Example +```bash +find ~ -name "*.txt" +``` +This searches for all `.txt` files in the user's home directory. + +## `locate` - The Rapid Reconnaissance Tool + +`locate` is like having aerial reconnaissance at your disposal. It provides a fast search of a database that indexes all files and directories. However, remember this database might not have the latest intel since it's updated periodically (usually daily). + +### How It Works +- **Basic search**: `locate filename` +- **Update database**: `sudo updatedb` (to refresh the database) + +### Example +```bash +locate project.txt +``` +This command quickly searches for `project.txt` across all indexed locations. + +## `which` - Identifying Your Tools + +In the field, knowing the location of your resources is crucial. Similarly, `which` helps you find the path to executable files, essentially showing where your software tools are stored. + +### Usage +```bash +which python +``` +This command will show the path to the Python interpreter if it's installed and in your system's PATH. + +## Summary - Your Command Line Toolkit + +Understanding and utilizing `ls`, `find`, `locate`, and `which` are akin to basic navigation skills in unfamiliar territory. They empower you to: +- Quickly list and assess the contents of directories. +- Conduct thorough searches for files based on specific criteria. +- Rapidly locate files using an indexed database. +- Determine the installation path of your command-line tools. + +In the next lesson, we'll explore how to manipulate these files and directories, moving from reconnaissance to establishing your base. Stay tuned for more tools to enhance your command line proficiency. \ No newline at end of file diff --git a/collection-one/modules/command-line/basic-commands/navigating-directories.md b/collection-one/modules/command-line/basic-commands/navigating-directories.md index 459ada5..eee2bc1 100644 --- a/collection-one/modules/command-line/basic-commands/navigating-directories.md +++ b/collection-one/modules/command-line/basic-commands/navigating-directories.md @@ -1,36 +1,61 @@ -# Navigating Directories +# Mastering Command Line Navigation -## `cd` -The `cd` or "Change Directory" command is a cornerstone of command line navigation. Not only does it allow you to traverse into child and parent directories, but it also supports a variety of flags and special characters for advanced navigation. For instance, `cd -` switches you to the last directory you were in, and `cd ~` takes you straight to the home directory. Specifying the full path, either absolute or relative, lets you jump to any directory in the system. +## Introduction +Command line navigation is akin to tactical movement in unfamiliar terrain. Knowing how to efficiently move through your file system's directories is essential, similar to navigating through various environments. This lesson delves into the core commands and advanced techniques for directory navigation, providing you with the skills to maneuver through the digital landscape of your computer. -### Advanced Usage -- `cd ..` moves you one directory up (parent directory). -- `cd ../..` takes you two directories up. -- `cd /` navigates to the root directory. -- `cd .` keeps you in the current directory but is useful in scripts. +## `cd` - The Tactical Advance -## `ls` -The "List" command (`ls`) is more than just a simple directory listing tool. By leveraging various flags, you can uncover a wealth of information. The `-l` flag gives you detailed file attributes like permissions, owner, group, file size, and modification date. The `-a` flag shows hidden files, which are usually configuration files starting with a dot (`.`). Combining flags like `ls -lah` gives a long listing of all files, including hidden ones, with sizes in human-readable format. +The `cd` (Change Directory) command is your primary maneuver for moving between folders. It's like plotting a course on your map, guiding you to your next position. -### Advanced Usage -- `ls -S` sorts files by size. -- `ls -t` sorts files by modification time. -- `ls -r` reverses the sort order. -- `ls *.txt` lists all text files in the directory. +### Key Commands and Techniques +- **Back to base**: `cd` or `cd ~` takes you to your home directory, your digital base camp. +- **Retrace your steps**: `cd -` switches you back to the last directory you visited, perfect for when you need to return to your previous position. +- **Advance or retreat**: `cd ..` moves you up one level (to the parent directory), while specifying a path moves you to a specific location. -## `pwd` -While it may seem straightforward, the "Print Working Directory" (`pwd`) command has its nuances. It helps orient yourself in the system, which is crucial in scripts and when using other commands that require a full directory path. The `-P` flag can be used to show the physical directory, without any symbolic links. +### Practical Example +```bash +cd ~/Documents/Training +``` +This command moves you directly into the `Training` folder within `Documents` from anywhere in the system. -### Advanced Usage -- `pwd -P` shows the true physical directory, devoid of any symbolic links. +## `ls` - Reconnaissance + +`ls` provides intelligence on the contents of directories, akin to scanning an area with binoculars. + +### Advanced Recon Techniques +- **In-depth intel**: `ls -l` for detailed information on files and directories. +- **Uncover hidden assets**: `ls -a` to reveal hidden files, which can be crucial configuration files or directories. +- **Sort and prioritize**: `ls -S` sorts by size, helping identify the largest files at a glance. + +### Example +```bash +ls -lah +``` +This gives a detailed listing of all files, including hidden ones, in a human-readable format. + +## `pwd` - Confirming Your Position -## `tree` -Beyond providing a hierarchical layout of directories, the `tree` command has its own set of powerful features. You can limit the depth of the tree structure using the `-L` flag followed by a number, such as `tree -L 2` to show only two levels. You can also use the `-d` flag to only show directories, ignoring the files. +Just as you periodically check your GPS coordinates, `pwd` confirms your current directory, ensuring you're where you need to be. ### Advanced Usage -- `tree -a` shows hidden files. -- `tree -d` shows only directories. -- `tree -L 2` limits the display to two levels. +- **True position**: `pwd -P` displays the physical directory path, bypassing any symbolic links, offering a clear understanding of your location. + +## `tree` - The Aerial View + +The `tree` command offers a bird's-eye view of your directory structure, laying out the terrain so you can plan your moves. + +### Advanced Scouting +- **Selective reconnaissance**: `tree -L 2` limits the view to two levels deep, helping focus on immediate areas of interest. +- **Directory focus**: `tree -d` displays only directories, omitting files for a clearer view of the structure. + +### Example +```bash +tree -L 2 -d +``` +This will display a two-level deep directory structure, showing folders only. + +## Summary - Command Line Navigation Tactics + +Mastering `cd`, `ls`, `pwd`, and `tree` equips you with the essential skills for efficient file system navigation. These commands are not just tools but part of an integrated strategy for managing and understanding your digital environment. By applying these techniques, you enhance your ability to move through your system's directories with confidence and precision, akin to navigating through complex terrain. -## Summary -Becoming proficient in navigating directories requires more than just understanding the basics; it involves mastering advanced flags and understanding how these commands interact with the file system and each other. Commands like `cd`, `ls`, `pwd`, and `tree` aren't just isolated tools but part of an interconnected toolkit that allows for highly efficient and precise file and directory management. Grasping these concepts will significantly improve your command-line proficiency. +Stay tuned for further lessons that will expand your toolkit, enabling you to not just navigate but also to manipulate and manage your digital landscape effectively. \ No newline at end of file diff --git a/collection-one/modules/command-line/basic-commands/wildcards.md b/collection-one/modules/command-line/basic-commands/wildcards.md index 40f3e9f..2f049ee 100644 --- a/collection-one/modules/command-line/basic-commands/wildcards.md +++ b/collection-one/modules/command-line/basic-commands/wildcards.md @@ -1,16 +1,64 @@ -# Wildcards +# Command Line Wildcards: The Art of Precision and Efficiency -## `*` -The asterisk wildcard matches zero or more characters in a filename or directory name. +## Introduction +In the world of command line operations, wildcards serve as your precision tools for identifying and acting upon groups of files and directories. Much like using specific coordinates to define an operation area, wildcards help you specify which files to include in your command, making your actions more efficient and targeted. -## `?` -The question mark wildcard matches any single character in place of the question mark. +## `*` - The Broad Sweep -## `[]` -The square brackets wildcard matches any one of the enclosed characters. Ranges can also be specified, like `[a-z]`. +The asterisk `*` wildcard is like a wide-net search, capturing a broad range of targets. It matches zero or more characters, allowing you to select files and directories that fit a general pattern. -## `{}` -The curly braces wildcard is used for pattern matching. It allows you to specify a list of strings to match against. +### Usage +- **Select all files**: `ls *` lists all files in the directory. +- **Pattern matching**: `rm *.txt` removes all files that end with `.txt`. -## Summary -Wildcards provide a way to simplify complex command-line operations. Understanding how to use `*`, `?`, `[]`, and `{}` will make tasks like file searching, renaming, and copying much more efficient. +### Example +```bash +ls *.jpg +``` +This command lists all JPEG image files in the current directory, regardless of their names. + +## `?` - The Single Recon + +The question mark `?` wildcard is your precision tool for when you know part of the filename but require flexibility on a single character. It matches exactly one character in a filename or directory name. + +### Usage +- **Find specific files**: `ls ??.txt` lists files with exactly three characters in their name, ending in `.txt`. + +### Example +```bash +ls report_?.txt +``` +This would match `report_1.txt`, `report_2.txt`, but not `report_10.txt`. + +## `[]` - The Selective Filter + +Square brackets `[]` allow for targeted operations within a specified range or set of characters, akin to choosing a squad based on specific criteria. + +### Usage +- **Character range**: `ls [a-c]*.txt` finds files starting with `a`, `b`, or `c` and ending with `.txt`. +- **Specific characters**: `ls report_[123].txt` matches `report_1.txt`, `report_2.txt`, and `report_3.txt`. + +### Example +```bash +ls photo_[a-c].jpg +``` +This command lists JPEG photos named `photo_a.jpg`, `photo_b.jpg`, and `photo_c.jpg`. + +## `{}` - The Strategic Grouping + +Curly braces `{}` are used for specifying discrete, non-overlapping patterns, similar to deploying multiple units to different locations based on distinct orders. + +### Usage +- **Multiple patterns**: `cp {file1.txt,file2.txt} /destination/` copies `file1.txt` and `file2.txt` to the specified destination. + +### Example +```bash +ls {*.txt,*.pdf} +``` +This command lists all text and PDF files in the current directory, treating each pattern as a separate operation. + +## Summary - Enhancing Command-Line Operations with Wildcards + +Wildcards are invaluable for streamlining and executing complex file management tasks with precision. By mastering the use of `*`, `?`, `[]`, and `{}`, you gain the ability to perform targeted searches, modifications, and operations on your files and directories. This skillset not only increases efficiency but also enhances your capability to manage the digital landscape with the same strategic acumen applied in military and logistical planning. + +Understanding and applying these wildcard patterns empowers you to navigate and manipulate your file system with confidence and precision, mirroring the tactical decision-making skills honed in the field. \ No newline at end of file diff --git a/collection-one/modules/command-line/basic-commands/working-with-permissions.md b/collection-one/modules/command-line/basic-commands/working-with-permissions.md index 6775f9d..82fc347 100644 --- a/collection-one/modules/command-line/basic-commands/working-with-permissions.md +++ b/collection-one/modules/command-line/basic-commands/working-with-permissions.md @@ -1,16 +1,56 @@ -# Working with Permissions +# Command Line Mastery: Managing Permissions -## `chmod` -The `chmod` or "Change Mode" command is used to modify file and directory permissions. It allows you to set permissions for the owner, group, and others using either symbolic representation or octal numbers. +## Introduction +In the digital environment, managing access to your files and directories is akin to securing a perimeter or controlling access to sensitive information. Permissions determine who can read, write, or execute files, paralleling how clearance levels work in a military or secure facility. This lesson covers the fundamental commands for managing permissions on your system: `chmod`, `chown`, `chgrp`, and `umask`. -## `chown` -The `chown` or "Change Owner" command allows you to change the ownership of a file or directory. You can specify both the user and the group that should own the file. +## `chmod` - Setting Access Protocols -## `chgrp` -The `chgrp` or "Change Group" command changes the group ownership of a file or directory. This is often used in tandem with `chown` for more granular control. +The `chmod` (Change Mode) command adjusts the permissions of files and directories, similar to establishing who has access to specific areas in a secure facility. -## `umask` -The `umask` command sets the default permissions for newly created files and directories. It's a way to control the initial permission settings in a systematic manner. +### Symbolic and Octal Modes +- **Symbolic Representation**: Uses letters `r` (read), `w` (write), `x` (execute), and operators `+` (add), `-` (remove), `=` (set exactly) to define permissions. +- **Octal (Numeric) Representation**: Uses numbers to represent permissions (4 for read, 2 for write, 1 for execute). -## Summary -Understanding and managing permissions is a critical aspect of system administration and file management. The `chmod`, `chown`, `chgrp`, and `umask` commands provide the tools you need to control access to your files securely. +### Examples +```bash +chmod u+x file.txt +``` +This command grants execute permission to the user (owner) of `file.txt`. + +```bash +chmod 755 script.sh +``` +Sets the permissions of `script.sh` to `rwxr-xr-x`, allowing the owner full rights, and the group and others to read and execute. + +## `chown` - Commanding Ownership + +The `chown` (Change Owner) command is used to transfer file or directory ownership, akin to reassigning responsibility for a mission or task. + +### Usage +```bash +chown user:group file.txt +``` +This changes the ownership of `file.txt` to "user" and assigns it to the "group" group. + +## `chgrp` - Aligning Group Control + +`chgrp` (Change Group) modifies the group ownership of files or directories, ensuring that operational tasks can be shared among a specific team or unit. + +### Example +```bash +chgrp team project/ +``` +Assigns the `project` directory's group ownership to "team", facilitating shared access. + +## `umask` - Establishing Default Security + +`umask` sets the default creation permissions for new files and directories, similar to setting standard operating procedures for handling new information or assets. + +### Understanding `umask` +The `umask` value subtracts permissions from the default settings. A `umask` of `022` ensures that new files (usually `666`) are created with `644` (`rw-r--r--`) and directories (usually `777`) with `755` (`rwxr-xr-x`). + +## Summary - The Command Line's Security Framework + +Understanding and effectively managing file and directory permissions with `chmod`, `chown`, `chgrp`, and `umask` commands is crucial for maintaining system security and operational integrity. These tools allow you to precisely control access, reflecting the meticulous planning and security considerations vital in military operations and secure environments. + +Mastering these commands enhances your ability to protect and manage resources, ensuring that access is granted appropriately and in line with your objectives.