Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhanced Lessons #77

Merged
merged 2 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified collection-one/modules/.DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
# Unit 2: Basic Commands Overview

Welcome to "Basic Commands," a pivotal unit in our Command Line module. Here, you'll delve into the fundamental commands that are the building blocks of any successful command-line operation. Whether you're a software engineer, writer, or instructor based in Atlanta, mastering these essential commands is key to enhancing your productivity in various tech-related roles.
Welcome to "Basic Commands," a cornerstone unit within our Command Line Fundamentals module. This unit is designed with an understanding that the command line is not just a tool but a powerful ally in the tech world. Whether you're transitioning from a military role into software engineering, embarking on a new journey as a writer, or stepping into the tech scene in Atlanta as an instructor, mastering these fundamental commands will significantly boost your efficiency and confidence in tech-related tasks.

## Table of Contents

1. **[Navigating Directories](navigating-directories.md)**: Begin by learning how to navigate directories efficiently, a fundamental skill for effective command-line usage.
1. **[Navigating Directories](navigating-directories.md)**: Start your command line journey by learning how to navigate the digital terrain of directories. Just as you navigated complex terrains in your previous roles, this skill will help you move through your projects with ease.

2. **[File Operations](file-operations.md)**: Explore essential file operations, including copying, moving, and deleting files, enabling you to manage your files seamlessly.
2. **[File Operations](file-operations.md)**: Dive into essential file operations such as copying, moving, and deleting. Think of this as organizing your digital toolkit, ensuring that everything you need is right where you need it, when you need it.

3. **[Listing and Filtering Files](listing-and-filtering-files.md)**: Discover how to list and filter files to find what you need quickly, streamlining your workflow.
3. **[Listing and Filtering Files](listing-and-filtering-files.md)**: Learn the art of listing and filtering files, akin to reconnaissance missions where quick, accurate information is key to decision-making.

4. **[File Permissions](working-with-permissions.md)**: Gain a deep understanding of file permissions, ensuring you have the necessary access to perform actions on files and directories.
4. **[File Permissions](working-with-permissions.md)**: Understanding file permissions is crucial for maintaining the security and integrity of your data. This lesson parallels securing and controlling access to sensitive information, a familiar concept for veterans.

5. **[Disk and Directory Usage](disk-and-directory-usage.md)**: Learn how to monitor disk and directory usage, allowing you to manage your system resources effectively.
5. **[Disk and Directory Usage](disk-and-directory-usage.md)**: Monitor your disk and directory usage to manage resources efficiently, much like logistical planning and resource allocation in military operations.

6. **[Wildcards](wildcards.md)**: Master the use of wildcards to perform advanced operations on multiple files simultaneously.
6. **[Wildcards](wildcards.md)**: Mastering wildcards allows you to efficiently perform actions on multiple files simultaneously, enhancing your ability to handle broad tasks with precision.

7. **[File Paths](file-paths.md)**: Understand file paths, a critical aspect of working with files and directories on the command line.
7. **[File Paths](file-paths.md)**: Grasp the concept of file paths, essential for locating and working with files. This is your map through the vast landscape of your file system, guiding you to your objectives swiftly and accurately.

This unit equips you with the essential tools needed to manage your files and directories effectively, making your time on the command line both productive and efficient. Whether you're setting up projects, automating tasks, or managing system resources, these foundational commands are essential in achieving your goals. Enjoy your journey through the Basic Commands unit!
This unit is designed to arm you with the command line skills necessary for effective file and directory management, setting a foundation for further exploration and mastery of the tech domain. Whether setting up projects, automating tasks, or managing system resources, these skills are indispensable.

Remember, the transition to tech is a journey akin to mastering a new language or navigating a new terrain. Each command you learn and each task you accomplish brings you one step closer to your goal. Embrace the challenge, and enjoy the journey through the Basic Commands unit!
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Disk and Directory Usage in Linux

Understanding how to manage disk and directory usage is crucial for maintaining a healthy and efficient system. This lesson covers four fundamental commands that are indispensable for this purpose: `df`, `du`, `fdisk`, and `stat`.

## `df` - Disk Free
The `df` command displays the amount of disk space used and available on your filesystems. It's particularly useful for getting a quick overview of your system's disk usage.

### Usage
```bash
df -h
```
The `-h` option formats the output in a human-readable form, showing sizes in KB, MB, or GB as appropriate.

### Example
Imagine you're preparing to deploy new software or updates and need to ensure you have enough disk space. Use `df -h` to quickly check available space across all mounted filesystems.

## `du` - Disk Usage
The `du` command estimates the space used by directories and files. It's essential for identifying what's consuming your disk space, especially when cleaning up or auditing system storage.

### Usage
```bash
du -sh /path/to/directory
```
The `-s` option provides a summary for the specified directory, and `-h` makes the output human-readable.

### Example
To keep your system organized, akin to planning a field operation with precision, you might use `du` to pinpoint high-usage areas that require cleanup.

## `fdisk` - Disk Partition Manipulation
`fdisk` is a powerful tool for manipulating disk partitions. While its use is more advanced and typically reserved for system administrators, understanding its function is beneficial.

### Usage
```bash
sudo fdisk -l
```
The `-l` option lists all partitions on all disks, helping identify available storage devices and their partition schemes.

### Example
Before creating a new partition for a project, you'd use `fdisk -l` to identify the appropriate disk and its current partition layout, similar to assessing a terrain before establishing a base.

## `stat` - File or Filesystem Status
The `stat` command provides detailed information about files or filesystems, including size, permissions, and last access time.

### Usage
```bash
stat filename
```

### Example
When verifying the integrity of files or when conducting a detailed audit of file access times and permissions, `stat` offers a comprehensive overview, akin to a detailed after-action report.

## Summary and Best Practices
Efficient management of disk and directory usage is akin to ensuring operational readiness in a military context. Regularly monitoring disk space, organizing files and directories, and being proactive about system maintenance can prevent issues before they arise.

### Exercises
1. **Disk Space Audit:** Use `df` to identify filesystems with less than 10% free space.
2. **Cleanup Operation:** Find the top 5 largest directories or files in your home directory using `du`.
3. **Partition Planning:** List all disk partitions and identify a disk with free space for a new partition.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,19 +1,74 @@
# File Operations
# Advanced File Operations in Linux

## `cp`
The `cp` or "Copy" command is used for copying files and directories from one location to another. You can copy multiple files at once, or even entire directories with the `-R` option for recursive copy.
Managing files and directories efficiently is a fundamental skill for navigating and operating within a Linux environment. This lesson delves into essential commands that enable you to copy, move, remove, and manage files and directories.

## `mv`
The `mv` or "Move" command is used to move or rename files and directories. It can function within the same directory to rename a file or between directories to move files.
## `cp` - Copy Files and Directories
The `cp` command allows you to copy files and directories, offering flexibility in how data is duplicated across the system.

## `rm`
The `rm` or "Remove" command is used to delete files. Use cautiously, as this deletes files permanently. The `-r` option can remove directories and their contents recursively.
### Usage
```bash
cp source_file target_file
cp -R source_directory target_directory
```
The `-R` option enables recursive copying, essential for directories. To preserve file attributes, consider the `-p` option.

## `touch`
The `touch` command is used to create empty files quickly. It can also update the access and modification times of existing files.
### Example
Copy a deployment checklist from one directory to another, ensuring you have backups of critical files.

## `mkdir`
The `mkdir` or "Make Directory" command is used to create new directories.
## `mv` - Move or Rename
The `mv` command serves dual purposes: moving files between directories and renaming them.

## Summary
Understanding file operations is crucial when working in a command-line environment. The `cp` command allows for copying files, while `mv` enables moving and renaming operations. The `rm` command is used for deletion, but must be used carefully to avoid unintentional data loss. The `touch` and `mkdir` commands make file and directory creation a simple task. Mastering these commands will make your daily tasks more efficient and automated.
### Usage
```bash
mv old_filename new_filename
mv file_to_move target_directory/
```

### Example
Rename a file to reflect its updated status or move it to a designated archive directory, much like reorganizing gear for efficiency and readiness.

## `rm` - Remove Files and Directories
The `rm` command deletes files and directories, a powerful but potentially dangerous tool.

### Usage
```bash
rm filename
rm -r directory_name
```
Use `-i` for interactive deletions, prompting for confirmation—a good practice to avoid accidental data loss.

### Example
Securely removing temporary files or decommissioning outdated documents, akin to clearing a site after mission completion.

## `touch` - Create or Update Files
The `touch` command is versatile, allowing you to create new, empty files or update the timestamps of existing ones.

### Usage
```bash
touch new_file
```

### Example
Quickly creating a new file for jotting down operations notes or updating the timestamp to reflect a review or modification.

## `mkdir` - Create Directories
The `mkdir` command is straightforward yet essential for organizing files and directories.

### Usage
```bash
mkdir new_directory
```
To create a directory structure in one command, use `mkdir -p parent_directory/new_directory`.

### Example
Setting up a new directory for a project or operation, ensuring a structured and organized workspace.

## Summary and Best Practices
File management commands are the backbone of system navigation and organization. By mastering these commands, you enhance your operational efficiency, drawing parallels to meticulous planning and execution in military operations.

### Exercises
1. **Backup Operation:** Use `cp` to create backups of your personal files in a separate directory.
2. **Reorganization Drill:** Move files from multiple locations into a single, organized directory.
3. **Cleanup Mission:** Safely remove temporary or unneeded files from your system, using `rm -i` to review each file before deletion.

Adopting a disciplined approach to file management, akin to strategic military planning, ensures your system remains efficient, organized, and operational.
61 changes: 50 additions & 11 deletions collection-one/modules/command-line/basic-commands/file-paths.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,55 @@
# File Paths
# Navigating File Paths in Linux

## Relative Paths
These are paths that are relative to the current directory. They do not start with the root directory `/`.
Navigating through the filesystem efficiently is crucial for command-line proficiency. This lesson explores the concepts of relative and absolute file paths and introduces commands that help manage and interpret these paths.

## Absolute Paths
These paths start with the root directory and provide the full path to a file or directory.
## Relative vs. Absolute Paths

## `realpath`
The `realpath` command resolves symbolic links and outputs the absolute path to a file or directory.
- **Relative Paths** refer to a location that is relative to the current directory. They do not begin with a slash (`/`) and are used to navigate within the filesystem based on the current location.

- Example: If you're in `/home/user` and want to access `documents`, the relative path would be `documents/filename`.

## `dirname`
The `dirname` command outputs the directory part of a file path, stripping the last portion that is generally the filename.
- **Absolute Paths** specify the full path to a file or directory from the root of the filesystem. They always start with a slash (`/`), indicating the root directory.

- Example: The absolute path to a file might be `/home/user/documents/filename`.

## Summary
Understanding the concept of file paths, both relative and absolute, is fundamental when navigating and operating in a command-line environment. The `realpath` and `dirname` commands can be particularly useful for script-based tasks that require manipulating or identifying paths.
## Understanding `realpath`

The `realpath` command is used to resolve any symbolic links and return the absolute path of a given file or directory.

### Usage
```bash
realpath relative/path/to/file
```

### Example
Find the absolute path of a file when writing scripts that require a full path regardless of the current working directory.

## Using `dirname` and `basename`

- **`dirname`** extracts the directory path from a given file path, effectively removing the filename from the path.

```bash
dirname /path/to/file/filename
```

This command would output `/path/to/file`, useful for scripts needing to work with directory paths.

- **`basename`** complements `dirname` by extracting the filename from a given path.

```bash
basename /path/to/file/filename
```

This command would return `filename`, ideal for cases where you need just the file name without the preceding path.

## Summary and Best Practices

Understanding and effectively using file paths are foundational skills for navigating the Linux filesystem. By mastering relative and absolute paths, and utilizing commands like `realpath`, `dirname`, and `basename`, you can streamline your workflow and enhance script automation.

### Exercises

1. **Path Exploration:** Navigate to your home directory using both a relative path and an absolute path from different starting points.
2. **Path Manipulation:** For a given file, use `realpath` to find its absolute path, `dirname` to extract its directory path, and `basename` to get just the filename.
3. **Scripting Challenge:** Write a simple script that takes a file path as an input, checks if the file exists, and then prints the file’s directory and name separately.

Emphasizing hands-on practice and real-world applications makes these concepts more accessible and relevant, especially for veterans transitioning their operational planning and navigation skills to a digital environment.
Loading
Loading