Snitize Chapter 6

This commit is contained in:
ganome 2024-09-07 09:29:54 -06:00
parent 61db30e0cb
commit 4543302bce
Signed by untrusted user who does not match committer: Ganome
GPG Key ID: 944DE53336D81B83
12 changed files with 241 additions and 569 deletions

View File

@ -21,84 +21,58 @@ These tools are often used together to create compressed archives.
Basic syntax: tar [options] [archive_name] [files_to_archive] Basic syntax: tar [options] [archive_name] [files_to_archive]
Common options: Common options:
- c: Create a new archive - -c: "C"reate a new archive
- x: Extract files from an archive - -x: E"x"tract files from an archive
- v: Verbose mode (list files processed) - -v: "V"erbose mode (list files processed)
- f: Specify the archive file name - -f: Specify the archive "f"ile name
- -t: Lis"t" whats inside the archive
- -C: CAPITAL C will "C"hange the directory to output the extracted contents
Examples: Examples:
- Create an archive: ### - Create an archive:
``` - `tar -cvf archive.tar file1 file2 directory1` # "C"reate an archive called archive.tar using file1, file2, and directory1.
tar -cvf archive.tar file1 file2 directory1 ### - Extract an archive:
``` - `tar -xvf archive.tar -C ~/extracted/` # Will change to the home "~" directory and then into the extracted directory before extracting the archive.
- Extract an archive: ### - List contents of an archive:
``` - `tar -tvf archive.tar`
tar -xvf archive.tar
```
- List contents of an archive:
```
tar -tvf archive.tar
```
## 3. Using gzip: ## 3. Using gzip:
Basic syntax: gzip [options] [file_name] Basic syntax: gzip [options] [file_name]
Common options: Common options:
- d: Decompress - -d: Decompress
- r: Recursive (compress files in directories) - -r: Recursive (compress files in directories)
- v: Verbose mode - -v: Verbose mode
- [number]: Compression level (1-9, 9 being highest) - -[1-9]: Compression level (1-9, 9 being highest)
Examples: Examples:
- Compress a file: ### - Compress a file with a compression level:
``` - `gzip -9 file.txt` # gzip a file using the best compression "-9" available.
gzip file.txt ### - Decompress a file:
``` - `gzip -d file.txt.gz`
- Decompress a file:
```
gzip -d file.txt.gz
```
- Compress with highest level:
```
gzip -9 file.txt
```
## 4. Combining tar and gzip: ## 4. Combining tar and gzip:
tar can use gzip compression directly with the 'z' option. tar can use gzip compression directly with the 'z' option.
- Create a compressed archive: ### - Create a compressed archive:
``` - `tar -czvf archive.tar.gz directory1` # Will "c"reate a tar archive, then g"z"ip it.
tar -czvf archive.tar.gz directory1 ### - Extract a compressed archive:
``` `tar -xzvf archive.tar.gz`
- Extract a compressed archive:
```
tar -xzvf archive.tar.gz
```
## 5. Advanced usage and options: ## 5. Advanced usage and options:
- Exclude files or directories: ### - Exclude files or directories:
``` - `tar -czvf archive.tar.gz directory1 --exclude=*.log`
tar -czvf archive.tar.gz directory1 --exclude=*.log ### - Update an existing archive:
``` - `tar -uvf archive.tar newfile` # This will add the newfile into the existing archive.tar.
- Update an existing archive: ### - Use bzip2 compression (often better for text):
``` - `tar -cjvf archive.tar.bz2 directory1`
tar -uvf archive.tar newfile ###- Preserve file permissions:
``` - `tar -cpvf archive.tar directory1`
- Use bzip2 compression (often better for text): ###- Split large archives:
``` - `tar -cvf - directory1 | split -b 1G - archive.tar.part`
tar -cjvf archive.tar.bz2 directory1
```
- Preserve file permissions:
```
tar -cpvf archive.tar directory1
```
- Split large archives:
```
tar -cvf - directory1 | split -b 1G - archive.tar.part
```
## 6. Best practices and tips: ## 6. Best practices and tips:
@ -107,5 +81,3 @@ tar can use gzip compression directly with the 'z' option.
- Use compression levels wisely (higher levels are slower) - Use compression levels wisely (higher levels are slower)
- Consider using xz for better compression (use -J option with tar) - Consider using xz for better compression (use -J option with tar)
- For large backups, consider using incremental backups with tar's --listed-incremental option - For large backups, consider using incremental backups with tar's --listed-incremental option
This guide covers the basics and some advanced usage of tar and gzip in Linux.

View File

@ -1,29 +0,0 @@
## Certainly! Let's delve into compression and archiving using **gzip** and **tar** in **Linux Mint**:
1. **Tar (Tape Archive)**:
- **Tar** combines multiple files or directories into a single archive file.
- Basic usage:
- To create a tar archive: `tar -cvf archive.tar files_or_directories`
- To extract from a tar archive: `tar -xvf archive.tar`
- Combine with compression tools for smaller archives.
2. **Gzip**:
- **Gzip** compresses files individually.
- Basic usage:
- To compress a file: `gzip filename` (creates `filename.gz`)
- To decompress: `gzip -d filename.gz`
3. **Combining Tar and Gzip**:
- Create a compressed tar archive (`.tar.gz` or `.tgz`):
```
tar -czvf archive.tar.gz files_or_directories
```
Remember, these commands help manage files efficiently! Feel free to explore further or ask more questions. 😊🚀
Source: Conversation with Copilot, 7/12/2024
- [(1) How to obtain maximum compression with .tar.gz? - Super User.](https://superuser.com/questions/514260/how-to-obtain-maximum-compression-with-tar-gz.)
- [(2) How to Compress and Extract Files Using the tar Command on Linux.](https://www.howtogeek.com/248780/how-to-compress-and-extract-files-using-the-tar-command-on-linux/.)
- [(3) File Compression and Archiving Using tar, gzip, zip, etc..](https://cfcs2r.com/index.php/courses/linux-file-system-basics/lessons/file-compression-and-archiving-using-tar-gzip-zip-etc/.)
- [(4) Tar command Compress and Extract Archives - ComputerNetworkingNotes.](https://www.computernetworkingnotes.com/linux-tutorials/tar-command-compress-and-extract-archives.html.)
- [(5) How to archive a file with tar gz. and gzip command..](https://nexonhost.com/how-to-archive-a-file-with-tar-gz-and-gzip-command/.)

View File

@ -1,28 +0,0 @@
## Certainly! Let's explore directories and symbolic links in **Linux Mint**:
1. **Directories (Folders)**:
- Directories are like containers that organize files. They hold files and other directories.
- When you navigate through your file system, you're moving between directories.
- Common terminal commands related to directories:
- `ls`: Lists files and directories in the current working directory³.
- `cd`: Changes the current directory (e.g., `cd Documents`).
2. **Symbolic Links (Symlinks)**:
- Symlinks are advanced shortcuts.
- A symlink points to another file or directory, even though it appears as if it's the actual file.
- To create a symlink using the `ln` command:
```
ln -s /path/to/original /path/to/link
```
- For example, creating a symlink from your Downloads folder to your Desktop:
```
ln -s /home/username/Downloads /home/username/Desktop
```
Remember, directories organize files, and symlinks provide flexible references to other locations! Feel free to explore further or ask more questions. 😊🚀
Source: Conversation with Copilot, 7/12/2024
- [(1) The beginners guide to using terminal on Linux Mint - FOSS Linux.](https://www.fosslinux.com/103546/the-beginners-guide-to-using-terminal-on-linux-mint.htm.)
- [(2) How to Create and Use Symbolic Links (aka Symlinks) on Linux.](https://www.howtogeek.com/287014/how-to-create-and-use-symbolic-links-aka-symlinks-on-linux/.)
- [(3) Open a terminal window and change to the directory where you.](https://forums.linuxmint.com/viewtopic.php?t=97386.)
- [(4) How to Find Files and Directories in Linux Mint 20 LinuxWays.](https://linuxways.net/mint/how-to-find-files-and-directories-in-linux-mint-20/.)

View File

@ -7,25 +7,26 @@
### 2. Types of directories: ### 2. Types of directories:
- Root directory: The top-level directory in the file system hierarchy, typically represented by "/" on Unix-like systems. - Root directory: The top-level directory in the file system hierarchy, typically represented by "/" on Unix-like systems.
- Home directory: The default directory for a user, usually containing personal files and configurations. - Home directory: The default directory for a user, usually containing personal files and configurations. "~"
- Parent directory: The directory one level above the current directory, represented by "..". - Parent directory: The directory one level above the current directory, represented by "..".
- Current directory: The directory you're currently in, represented by ".". - Current directory: The directory you're currently in, represented by ".".
- Subdirectory: Any directory contained within another directory. - Subdirectory: Any directory contained within another directory. "/usr/bin" - bin is a subdirectory of /usr.
### 3. Directory operations: ### 3. Directory operations:
- Create: mkdir (make directory) - Create: mkdir (make directory)
- Delete: rmdir (remove directory) or rm -r (remove recursively) - Delete: rmdir (remove directory - must be empty) or rm -rf ("f"orce remove "r"ecursively, even if not empty)
- Change: cd (change directory) - Change: cd (change directory)
- List contents: ls (list) or dir (on Windows) - List contents: ls (list)
- View path: pwd (print working directory) - View path: pwd ("p"rint "w"orking "d"irectory)
### 4. Directory permissions: ### 4. Directory permissions:
On Unix-like systems, directories have read (r), write (w), and execute (x) permissions. The execute permission allows users to enter the directory. On Unix-like systems, directories have read (r), write (w), and execute (x) permissions. The execute permission allows users to enter the directory.
- See the section on [Permissions](../05%20-%20Linux%20Permissions%20and%20Ownership/Understanding%20File%20Permissions.md) for examples.
### 5. Hidden directories: ### 5. Hidden directories:
In Unix-like systems, directories starting with a dot (.) are hidden by default. In Unix-like systems, directories starting with a dot (.) are hidden by default.
## Symlinks (Symbolic Links): ## Symlinks (Symbolic Links) or shortcuts (Windows):
### 1. Definition: ### 1. Definition:
A symlink is a special type of file that points to another file or directory. It's similar to a shortcut in Windows or an alias in macOS. A symlink is a special type of file that points to another file or directory. It's similar to a shortcut in Windows or an alias in macOS.
@ -36,9 +37,7 @@
### 3. Creating symlinks: ### 3. Creating symlinks:
Use the ln command with the -s option: Use the ln command with the -s option:
``` `ln -s target_path link_path` # Create a symbolic link at link_path to the target_path
ln -s target_path link_path
```
### 4. Advantages of symlinks: ### 4. Advantages of symlinks:
- Save space by avoiding duplicate files - Save space by avoiding duplicate files
@ -52,11 +51,11 @@
- If the target is deleted, the symlink becomes a "dangling" or "broken" link. - If the target is deleted, the symlink becomes a "dangling" or "broken" link.
### 6. Identifying symlinks: ### 6. Identifying symlinks:
- Use ls -l to see detailed file information. Symlinks are indicated by an "l" at the start of the permissions string. - Use `ls -l` to see detailed file information. Symlinks are indicated by an "l" at the start of the permissions string.
- The file command can also identify symlinks. - The file command can also identify symlinks.
### 7. Following symlinks: ### 7. Following symlinks:
- Some commands (like cp) don't follow symlinks by default. Use the -L or --follow options to change this behavior. - Some commands (like cp) don't follow symlinks by default. Use the `-L` or `--follow` options to change this behavior.
### 8. Symlinks in different operating systems: ### 8. Symlinks in different operating systems:
- Unix-like systems (Linux, macOS): Native support for symlinks. - Unix-like systems (Linux, macOS): Native support for symlinks.
@ -67,9 +66,6 @@
- Many systems implement symlink protections to mitigate these risks. - Many systems implement symlink protections to mitigate these risks.
### 10. Use cases: ### 10. Use cases:
- Maintaining multiple versions of configuration files
- Creating shortcuts in the file system - Creating shortcuts in the file system
- Managing shared libraries - Managing shared libraries
- Facilitating easier software updates - Facilitating easier software updates
Understanding directories and symlinks is crucial for effective file system management, particularly in Unix-like environments. They provide powerful tools for organizing and accessing files efficiently.

View File

@ -7,92 +7,65 @@ There are several ways to create files in Linux:
### - a. Using touch: ### - a. Using touch:
The `touch` command is the simplest way to create an empty file. The `touch` command is the simplest way to create an empty file.
```bash `touch filename.txt` # This creates an empty file named "filename.txt" in the current directory.
touch filename.txt
```
This creates an empty file named "filename.txt" in the current directory.
### - b. Using redirection: ### - b. Using redirection:
You can use output redirection to create a file with content. You can use output redirection to create a file with content.
```bash `echo "Hello, World!" > newfile.txt` # This creates a file named "newfile.txt" containing the text "Hello, World!".
echo "Hello, World!" > newfile.txt
```
This creates a file named "newfile.txt" containing the text "Hello, World!".
### - c. Using text editors: ### - c. Using text editors:
You can create and edit files using text editors like nano, vim, or gedit. You can create and edit files using text editors like nano, vim, or gedit.
```bash - `nano newfile.txt` # Basic editor that comes on most distros
nano newfile.txt - `vim newfile.txt` # More advnaced editor
vim newfile.txt - `xed newfile.txt` # GUI text editor included with Linux Mint Cinnamon
gedit newfile.txt - `gedit newfile.txt` # Gnome's in-house text editor
```
These commands open the respective text editor with a new file named "newfile.txt". These commands open the respective text editor with a new file named "newfile.txt".
## 2. Deleting Files ## 2. Deleting Files
To delete files in Linux, you can use the `rm` (remove) command: When deleting files in the linux terminal - there is no UNDO! To delete files in Linux, you can use the `rm` (remove) command:
- a. Deleting a single file: ### a. Deleting a single file:
```bash - `rm filename.txt`
rm filename.txt
```
- b. Deleting multiple files: ### b. Deleting multiple files:
```bash - `rm file1.txt file2.txt file3.txt`
rm file1.txt file2.txt file3.txt
```
- c. Deleting files with a specific pattern: ### c. Deleting files with a specific pattern:
```bash - `rm *.txt` # This removes all files with the .txt extension in the current directory.
rm *.txt
```
This removes all files with the .txt extension in the current directory.
- d. Deleting files interactively (prompts for confirmation): ### d. Deleting files interactively (prompts for confirmation):
```bash - `rm -i filename.txt`
rm -i filename.txt
```
- e. Deleting files forcefully (use with caution): ### e. Deleting files forcefully (use with caution):
```bash - `rm -f filename.txt`
rm -f filename.txt
```
Note: Be extremely careful when using `rm`, especially with wildcards or the `-f` option, as deleted files cannot be easily recovered. Note: Be extremely careful when using `rm`, especially with wildcards or the `-f` option, as deleted files cannot be recovered.
## 3. Renaming Files ## 3. Renaming Files
In Linux, renaming is done using the `mv` (move) command: In Linux, renaming is done using the `mv` (move) command:
- a. Basic renaming: ### a. Basic renaming:
```bash - `mv oldname.txt newname.txt`
mv oldname.txt newname.txt
```
- b. Renaming multiple files using a pattern: ### b. Renaming multiple files using a pattern:
To rename multiple files, you can use a loop in the shell. For example, to change the extension of all .txt files to .md: To rename multiple files, you can use a loop in the shell. For example, to change the extension of all .txt files to .md:
```bash ```
for file in *.txt; do for file in *.txt; do
mv "$file" "${file%.txt}.md" mv "$file" "${file%.txt}.md"
done done
``` ```
- c. Renaming with a backup: ### c. Renaming with a backup:
```bash `mv -b oldname.txt newname.txt` # This creates a backup of the destination file if it already exists.
mv -b oldname.txt newname.txt
```
This creates a backup of the destination file if it already exists.
- d. Interactive renaming (prompts before overwriting): ### d. Interactive renaming (prompts before overwriting):
```bash `mv -i oldname.txt newname.txt`
mv -i oldname.txt newname.txt
```
## Additional Tips: ## Additional Tips:

View File

@ -1,32 +0,0 @@
## Certainly! Let's explore file management tasks in **Linux Mint**. Here are some essential commands:
1. **Creating a File**:
- To create a new file, use the `touch` command followed by the desired filename:
```
touch sample.txt
```
2. **Copying Files**:
- The `cp` command copies a file. For example:
```
cp file.txt new-file.txt
```
3. **Moving or Renaming Files**:
- The `mv` command moves files from one location to another. It's also used for renaming files:
```
mv old-file.txt new-file.txt
```
4. **Removing Files**:
- To delete a file, use the `rm` command:
```
rm unwanted-file.txt
```
Remember, these commands empower you to manage files efficiently! Feel free to ask if you need further assistance. 😊🚀
Source: Conversation with Copilot, 7/12/2024
- [(1) How to create, copy, move, and remove files and directories in Linux.](https://www.thegeeksearch.com/how-to-create-copy-move-and-remove-files-and-directories-in-linux/.)
- [(2) How to Create, Delete, & Rename a File in Linux - Hivelocity.](https://www.hivelocity.net/kb/how-to-create-delete-rename-a-file-in-linux/.)
- [(3) Linux Mint - Community.](https://community.linuxmint.com/tutorial/view/1162.)

View File

@ -2,137 +2,89 @@
##1. Basic Syntax: ##1. Basic Syntax:
The basic syntax of the find command is: The basic syntax of the find command is:
``` `find [path] [expression]` # Where [path] is the directory you want to search in, and [expression] defines the search criteria.
find [path] [expression]
```
Where [path] is the directory you want to search in, and [expression] defines the search criteria.
## 2. Searching by Name: ## 2. Searching by Name:
- To find files by name: - To find files by name:
``` - `find /path/to/search -name "filename"` # Perform a case-sensitive search "-name"
find /path/to/search -name "filename"
```
- Use wildcards for pattern matching: - Use wildcards for pattern matching:
``` - `find /path/to/search -name "*.txt"`
find /path/to/search -name "*.txt"
```
- For case-insensitive search: - For case-insensitive search:
``` - `find /path/to/search -iname "filename"` # Perform a insensitive case search.
find /path/to/search -iname "filename"
```
## 3. Searching by Type: ## 3. Searching by Type:
- Find only directories: - Find only directories:
``` - `find /path/to/search -type d`
find /path/to/search -type d
```
- Find only regular files: - Find only regular files:
``` - `find /path/to/search -type f`
find /path/to/search -type f
```
- Find symbolic links: - Find symbolic links:
``` - `find /path/to/search -type l`
find /path/to/search -type l
```
## 4. Searching by Size: ## 4. Searching by Size:
- Find files larger than 100MB: - Find files larger than 100MB:
``` - `find /path/to/search -size +100M`
find /path/to/search -size +100M
```
- Find files smaller than 1KB: - Find files smaller than 1KB:
``` - `find /path/to/search -size -1k`
find /path/to/search -size -1k
```
- Find files exactly 50 bytes: - Find files exactly 50 bytes:
``` - `find /path/to/search -size 50c`
find /path/to/search -size 50c
```
## 5. Searching by Time: ## 5. Searching by Time:
- Find files modified in the last 7 days: - Find files modified in the last 7 days:
``` - `find /path/to/search -mtime -7`
find /path/to/search -mtime -7
```
- Find files accessed more than 30 days ago: - Find files accessed more than 30 days ago:
``` - `find /path/to/search -atime +30`
find /path/to/search -atime +30
```
- Find files whose status was changed within the last hour: - Find files whose status was changed within the last hour:
``` - `find /path/to/search -cmin -60`
find /path/to/search -cmin -60
```
## 6. Searching by Permissions: ## 6. Searching by Permissions:
- Find files with exact permissions: - Find files with exact permissions:
``` - `find /path/to/search -perm 644`
find /path/to/search -perm 644
```
- Find files with at least these permissions: - Find files with at least these permissions:
``` - `find /path/to/search -perm -644`
find /path/to/search -perm -644
```
## 7. Logical Operators: ## 7. Logical Operators:
- AND operation (implicit): - AND operation (implicit):
``` - `find /path/to/search -name "*.txt" -size +1M`
find /path/to/search -name "*.txt" -size +1M
```
- OR operation: - OR operation:
``` - `find /path/to/search \( -name "*.txt" -o -name "*.pdf" \)`
find /path/to/search \( -name "*.txt" -o -name "*.pdf" \)
```
- NOT operation: - NOT operation:
``` - `find /path/to/search ! -name "*.txt"`
find /path/to/search ! -name "*.txt"
```
## 8. Actions: ## 8. Actions:
- Print results (default action): - Print results (default action):
``` - `find /path/to/search -name "*.txt" -print`
find /path/to/search -name "*.txt" -print
```
- Execute a command on found files: - Execute a command on found files:
``` - `find /path/to/search -name "*.txt" -exec cat {} \;`
find /path/to/search -name "*.txt" -exec cat {} \;
```
- Delete found files (use with caution): - Delete found files (use with caution):
``` - `find /path/to/search -name "*.tmp" -delete`
find /path/to/search -name "*.tmp" -delete
```
## 9. Limiting Depth: ## 9. Limiting Depth:
- Search only in the current directory: - Search only in the current directory:
``` - `find /path/to/search -maxdepth 1 -name "*.txt"`
find /path/to/search -maxdepth 1 -name "*.txt"
```
- Limit search to 3 levels deep: - Limit search to 3 levels deep:
``` - `find /path/to/search -maxdepth 3 -name "*.txt"`
find /path/to/search -maxdepth 3 -name "*.txt"
```
## 10. Performance Optimization: ## 10. Performance Optimization:
- Use '-xdev' to stay on one filesystem: - Use '-xdev' to stay on one filesystem:
``` - `find /path/to/search -xdev -name "*.txt"`
find /path/to/search -xdev -name "*.txt"
```
- Optimize for large directories: - Optimize for large directories:
``` - `find /path/to/search -name "*.txt" -fprintf /dev/stdout '%p\0' | xargs -0 process`
find /path/to/search -name "*.txt" -fprintf /dev/stdout '%p\0' | xargs -0 process
```
## 11. Advanced Examples: ## 11. Advanced Examples:
- Find all empty directories: - Find all empty directories:
``` - `find /path/to/search -type d -empty`
find /path/to/search -type d -empty
```
- Find all files owned by a specific user: - Find all files owned by a specific user:
``` - `find /path/to/search -user username`
find /path/to/search -user username
```
- Find files and compress them: - Find files and compress them:
``` - `find /path/to/search -name "*.log" -exec gzip {} +`
find /path/to/search -name "*.log" -exec gzip {} +
```
This guide covers most common use cases of the 'find' command. Remember that 'find' is very powerful and flexible, allowing you to combine these options in various ways to create complex search criteria. ## 12. Find Alternatives:
**Using `locate`**:
- The `locate` command quickly searches for files and directories by their names. Here's the basic syntax:
```
locate {filename}
```
- For example, to locate a file named `resolv.conf`, you can run:
```
locate resolv.conf
```

View File

@ -1,31 +0,0 @@
## Certainly! In **Linux Mint**, you can search for files and directories using various methods in the terminal. Let's explore a few options:
1. **Using `locate`**:
- The `locate` command quickly searches for files and directories by their names. Here's the basic syntax:
```
locate {filename}
```
- For example, to locate a file named `resolv.conf`, you can run:
```
locate resolv.conf
```
2. **Using `find`**:
- The `find` command is more versatile and allows you to search based on various criteria.
- Basic syntax for finding files:
```
find /path/to/search -type f -name file-to-search
```
- Replace `/path/to/search` with the directory where you want to search and `file-to-search` with the desired filename.
3. **Third-Party Tools**:
- If you prefer graphical tools, consider using applications like **Nemo** (the default file manager in Cinnamon) or **Catfish** for file searches.
Feel free to choose the method that suits your workflow! 😊🚀
Source: Conversation with Copilot, 7/12/2024
- [(1) How do I search files and folders on Linux Mint 18.1 Cinnamon?.](https://unix.stackexchange.com/questions/343172/how-do-i-search-files-and-folders-on-linux-mint-18-1-cinnamon.)
- [(2) How to Search File Content in Linux Mint - Softhints.](https://softhints.com/how-to-search-file-content-in-linux-mint/.)
- [(3) How to Find Files and Directories in Linux Mint 20 LinuxWays.](https://linuxways.net/mint/how-to-find-files-and-directories-in-linux-mint-20/.)
- [(4) How to Search for Files from the Linux Command Line - freeCodeCamp.org.](https://www.freecodecamp.org/news/how-to-search-for-files-from-the-linux-command-line/.)
- [(5) undefined.](https://itsfoss.com/tiny-features-linux-mint-cinnamon/.)

View File

@ -1,38 +1,77 @@
## Certainly! Let's dive into the concepts of **I/O redirection** and **piping** in **Linux Mint**: # Linux I/O redirection and piping.
1. **I/O Redirection**: 1. Basic Concepts
- **Standard Input (stdin)**, **Standard Output (stdout)**, and **Standard Error (stderr)** are essential file descriptors for communication between programs and the outside world. 2. Input Redirection
- **stdin**: Default input source (usually keyboard input). 3. Output Redirection
- **stdout**: Default output destination (typically the terminal). 4. Error Redirection
- **stderr**: Alternative output for errors. 5. Piping
- We can redirect these streams to/from files or other commands. 6. Advanced Techniques
2. **Redirection Operators**: ## 1. Basic Concepts:
- `>`: Redirects stdout to a file (overwrites existing content).
```
ls > files
```
- `>>`: Appends stdout to a file.
```
ls -1 *.txt >> files
```
- `2>`: Redirects stderr to a file.
```
command_that_might_fail 2> error.log
```
3. **Piping (`|`)**: In Unix/Linux, there are three standard streams:
- Connects the stdout of one command to the stdin of another. - Standard Input (stdin): 0
- Useful for chaining commands: - Standard Output (stdout): 1
``` - Standard Error (stderr): 2
ls | grep "pattern"
```
Remember, mastering I/O redirection and piping enhances your command-line skills! Feel free to explore further or ask more questions. 😊🚀¹²⁴ By default, stdin is the keyboard, while stdout and stderr are both the terminal.
Source: Conversation with Copilot, 7/12/2024 ## 2. Input Redirection:
- [(1) Pipes and Redirection in Linux | Baeldung on Linux.](https://www.baeldung.com/linux/pipes-redirection.)
- [(2) Basic Guide to Input Output (I/O) Redirection in Linux - OperaVPS.](https://bing.com/search?q=linuxmint+I%2fO+redirection+and+piping.) The < symbol is used for input redirection.
- [(3) Learn The Basics of How Linux I/O (Input/Output) Redirection ... - Tecmint.](https://www.tecmint.com/linux-io-input-output-redirection-operators/.)
- [(4) Basic Guide to Input Output (I/O) Redirection in Linux - OperaVPS.](https://operavps.com/docs/input-output-redirection-in-linux/.) Example:
- [(5) 6.2 Using I/O Redirection and Piping.](https://www.oreilly.com/library/view/linux-fundamentals/9780135560396/LFUN_01_06_02.html.) - `sort < file.txt` # This command sorts the contents of file.txt.
## 3. Output Redirection:
The > symbol is used for output redirection. It creates a new file or overwrites an existing one.
The >> symbol appends to an existing file or creates a new one if it doesn't exist.
Examples:
- `echo "Hello, World!" > greeting.txt` # Create or overwrite file called "greeting.txt" with "Hello World!"
- `echo "How are you?" >> greeting.txt` # Append or addon to the end of "greeting.txt" with "How are you?"
## 4. Error Redirection:
You can redirect stderr using 2> or 2>>.
Example:
- `ls /nonexistent 2> error.log` # pipe the error log from the `ls` command into "./error.log"
To redirect both stdout and stderr to the same file:
- `command > output.log 2>&1`
## 5. Piping:
The | symbol is used for piping. It sends the output of one command as input to another.
Example:
- `ls -l | grep "\.txt"` # This lists all files and then filters for those ending in .txt.
## 6. Advanced Techniques:
### a) Here Documents:
```
cat << EOF > file.txt
Line 1
Line 2
EOF
```
#This will write "Line 1 Line2" into "file.txt" and only stop writing new data when it reaches the line "EOF" (End Of File)
- b) Process Substitution:
- `diff <(ls dir1) <(ls dir2)`
- c) Redirecting stdout and stderr to different files:
- `command 1> output.log 2> error.log`
- d) Discarding output:
- `command > /dev/null 2>&1`
- e) tee command (writing to both file and stdout):
- `echo "Hello" | tee file.txt` # This command will wrte "Hello" to stdout (screen) and to the file "file.txt" simultaneously
- f) Named Pipes (FIFOs):
- `mkfifo mypipe`
- `command1 > mypipe & command2 < mypipe`

View File

@ -1,100 +0,0 @@
# Linux I/O redirection and piping.
1. Basic Concepts
2. Input Redirection
3. Output Redirection
4. Error Redirection
5. Piping
6. Advanced Techniques
## 1. Basic Concepts:
In Unix/Linux, there are three standard streams:
- Standard Input (stdin): 0
- Standard Output (stdout): 1
- Standard Error (stderr): 2
By default, stdin is the keyboard, while stdout and stderr are both the terminal.
## 2. Input Redirection:
The < symbol is used for input redirection.
Example:
```bash
sort < file.txt
```
This command sorts the contents of file.txt.
## 3. Output Redirection:
The > symbol is used for output redirection. It creates a new file or overwrites an existing one.
The >> symbol appends to an existing file or creates a new one if it doesn't exist.
Examples:
```bash
echo "Hello, World!" > greeting.txt
echo "How are you?" >> greeting.txt
```
## 4. Error Redirection:
You can redirect stderr using 2> or 2>>.
Example:
```bash
ls /nonexistent 2> error.log
```
To redirect both stdout and stderr to the same file:
```bash
command > output.log 2>&1
```
## 5. Piping:
The | symbol is used for piping. It sends the output of one command as input to another.
Example:
```bash
ls -l | grep "\.txt"
```
This lists all files and then filters for those ending in .txt.
## 6. Advanced Techniques:
- a) Here Documents:
```bash
cat << EOF > file.txt
Line 1
Line 2
EOF
```
- b) Process Substitution:
```bash
diff <(ls dir1) <(ls dir2)
```
- c) Redirecting stdout and stderr to different files:
```bash
command 1> output.log 2> error.log
```
- d) Discarding output:
```bash
command > /dev/null 2>&1
```
- e) tee command (writing to both file and stdout):
```bash
echo "Hello" | tee file.txt
```
- f) Named Pipes (FIFOs):
```bash
mkfifo mypipe
command1 > mypipe & command2 < mypipe
```
These techniques allow for powerful data manipulation and process control in the Linux environment. They're essential for scripting, data processing, and system administration tasks.

View File

@ -2,22 +2,15 @@
## 1. Basic Usage: ## 1. Basic Usage:
The fundamental syntax of grep is: The fundamental syntax of grep is:
``` - `grep [options] pattern [file...]`
grep [options] pattern [file...]
```
Example: Example:
``` - `grep "error" logfile.txt` # This searches for the word "error" in logfile.txt.
grep "error" logfile.txt
```
This searches for the word "error" in logfile.txt.
## 2. Case Sensitivity: ## 2. Case Sensitivity:
- By default, grep is case-sensitive. - By default, grep IS case-sensitive.
- Use -i for case-insensitive search: - Use `-i` for case-insensitive search:
``` - `grep -i "eRRor" logfile.txt` # This will return all occurances of "error" in any case sensitivity. Error, erRor, ERROR, etc...
grep -i "error" logfile.txt
```
## 3. Regular Expressions: ## 3. Regular Expressions:
grep supports regular expressions for powerful pattern matching. grep supports regular expressions for powerful pattern matching.
@ -26,71 +19,55 @@
- *: Matches zero or more of the preceding character - *: Matches zero or more of the preceding character
- ^: Matches the start of a line - ^: Matches the start of a line
- $: Matches the end of a line - $: Matches the end of a line
- []: Matches any single character in brackets - [ ]: Matches any single character in brackets
Example: Example:
``` - `grep "^Error" logfile.txt` # Lines starting with "Error"
grep "^Error" logfile.txt # Lines starting with "Error" - `grep "failed$" logfile.txt` # Lines ending with "failed"
grep "failed$" logfile.txt # Lines ending with "failed" - `grep "t[ae]st" logfile.txt` # Matches "test" or "tast"
grep "t[ae]st" logfile.txt # Matches "test" or "tast"
```
## 4. Extended Regular Expressions: ## 4. Extended Regular Expressions:
Use -E option or egrep command for extended regex: Use -E option or egrep command for extended regex:
``` - `grep -E "Error|Warning" logfile.txt` # Searches for "Error" or "Warning" in "logfile.txt"
grep -E "Error|Warning" logfile.txt - `egrep "Error|Warning" logfile.txt` # Same as above
egrep "Error|Warning" logfile.txt
```
## 5. Inverting the Match: ## 5. Inverting the Match:
-v option inverts the match, showing lines that don't match: -v option inverts the match, showing lines that don't match:
``` - `grep -v "success" logfile.txt` # Match any line that does not contain the work "success" in logfile.txt
grep -v "success" logfile.txt
```
## 6. Displaying Line Numbers: ## 6. Displaying Line Numbers:
-n option shows line numbers: `-n` option shows line numbers:
``` - `grep -n "error" logfile.txt`
grep -n "error" logfile.txt
```
## 7. Counting Matches: ## 7. Counting Matches:
-c option counts the number of matching lines: `-c` option counts the number of matching lines:
``` - `grep -c "error" logfile.txt`
grep -c "error" logfile.txt
```
## 8. Showing Context: ## 8. Showing Context:
- -A n: Shows n lines after the match - `-A n`: Shows n lines after the match
- -B n: Shows n lines before the match - `-B n`: Shows n lines before the match
- -C n: Shows n lines before and after the match - `-C n`: Shows n lines before and after the match
Example: Example:
``` - `grep -C 2 "critical error" logfile.txt` # Match "critical error" inside "logfile.txt" and show 2 lines above/below each occurance.
grep -C 2 "critical error" logfile.txt
```
## 9. Recursive Search: ## 9. Recursive Search:
-r option searches recursively through directories: `-r` option searches recursively through directories:
``` - `grep -r "TODO" /path/to/project`
grep -r "TODO" /path/to/project
```
## 10. Matching Whole Words: ## 10. Matching Whole Words:
-w option matches whole words only: `-w` option matches whole words only:
``` - `grep -w "log" logfile.txt`
grep -w "log" logfile.txt
```
## 11. Displaying Filename: ## 11. Displaying Filename:
- -H: Always print filename - `-H`: Always print filename
- -h: Never print filename - `-h`: Never print filename
``` - `grep -H "error" *.log`
grep -H "error" *.log
```
## 12. Quiet Mode: ## 12. Quiet Mode:
-q option suppresses output, useful in scripts: `-q` option suppresses output, useful in scripts:
``` ```
if grep -q "error" logfile.txt; then if grep -q "error" logfile.txt; then
echo "Errors found" echo "Errors found"
@ -99,52 +76,35 @@
## 13. Using grep with Pipes: ## 13. Using grep with Pipes:
grep works well with pipes for filtering output: grep works well with pipes for filtering output:
``` - `ps aux | grep "nginx"`
ps aux | grep "nginx"
```
## 14. Multiple Patterns: ## 14. Multiple Patterns:
Use -e option for multiple patterns: Use `-e` option for multiple patterns:
``` - `grep -e "error" -e "warning" -e "critical" logfile.txt`
grep -e "error" -e "warning" -e "critical" logfile.txt
```
## 15. Reading Patterns from a File: ## 15. Reading Patterns from a File:
-f option reads patterns from a file: `-f` option reads patterns from a file:
``` `grep -f patterns.txt logfile.txt`
grep -f patterns.txt logfile.txt
```
## 16. Binary Files: ## 16. Binary Files:
- -a: Process binary files as text `-a` Process binary files as text
- --binary-files=without-match: Assume binary files don't match - \-\-binary-files=without-match: Assume binary files don't match
``` `grep -a "string" binary_file`
grep -a "string" binary_file
```
## 17. Colorizing Output: ## 17. Colorizing Output:
--color option highlights matches: `--color` option highlights matches:
``` - `grep --color "error" logfile.txt`
grep --color "error" logfile.txt
```
## 18. Excluding Files: ## 18. Excluding Files:
--exclude option excludes files from the search: `--exclude` option excludes files from the search:
``` - `grep "TODO" --exclude="*.o" -r .`
grep "TODO" --exclude="*.o" -r .
```
## 19. Including Only Certain Files: ## 19. Including Only Certain Files:
--include option includes only specified files: `--include` option includes only specified files:
``` - `grep "function" --include="*.c" -r .`
grep "function" --include="*.c" -r .
```
## 20. Null-Separated Output: ## 20. Null-Separated Output:
-Z option outputs a zero byte after filename: `-Z` option outputs a zero byte after filename:
``` - `grep -lZ "error" *.log | xargs -0 rm`
grep -lZ "error" *.log | xargs -0 rm
```
This guide covers many of grep's powerful features. Remember to consult the man pages (`man grep`) for more detailed information and additional options.

View File

@ -37,13 +37,13 @@ TBA
2. Contributors - That's Y'all. Combing through the content I have cherry picked and telling me what improvements can be made. 2. Contributors - That's Y'all. Combing through the content I have cherry picked and telling me what improvements can be made.
## Milestones ## Milestones
1. Generated all content at request of another project using AI; and not error correcting. 1. Sanitize current content of hyperlinks.
2. Acknowledging the obvious problems with the generated content and planning steps forward. 2. Remove duplicate data in content
3. Broke free from the AI generated content of LinuxLighthouse (MIT License). 3. Reorganize some material into proper topics.
4. Correct everything I was told to intentionally leave wrong in the AI generated content (most of this curriculum). 4. Add some hyperlinks to relevant material and projects.
## Relevant Links ## Relevant Links
[LightHouse Linux](https://github.com/jajunk/LightHouseLinuxMasterMDFiles/) (MIT License) - AI generated content Coming Soon
## Issue Template ## Issue Template
[Issue Template](./IssueTemplate.md) [Issue Template](./IssueTemplate.md)