A concise guide to expanding the storage space on a Linux system using command-line utilities.
To view your current disk volumes and partitions:
lsblk
Viewing Volume Groups For detailed information about volume groups:
vgs -h
Increasing Partition Size To extend the size of a specific partition (e.g., /dev/sda 3):
sudo growpart /dev/sda 3
Confirming Changes Re-check your disk layout to confirm the partition changes:
sudo lsblk
Expanding Logical Volume To allocate all available free space to the logical volume (e.g., /dev/ubuntu-vg/ubuntu-lv):
sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
Resizing the Filesystem Finally, resize the filesystem to utilize the extended logical volume:
sudo resize2fs /dev/ubuntu-vg/ubuntu-lv
```
Ensure to replace /dev/sda 3 and /dev/ubuntu-vg/ubuntu-lv with your specific partition and volume group names as needed.
# nohup rsync
```bash
nohup rsync avzPh --delete user@ip:/location/ /location2 &
```
This is a command for copying files from one location to another using the rsync command.
The nohup command is used to run the command even if the user logs out of the system,
and the & symbol is used to run the command in the background.
The rsync command is typically used to synchronize files between two locations,
and the flags used in this command provide additional instructions for how the files should be copied:
a: This flag tells rsync to preserve the file permissions, ownership, and timestamps.
v: This flag enables verbose output, so that the user can see the progress of the file transfer.
z: This flag enables compression, which can speed up the transfer of files over the network.
P: This flag is a combination of the p and l flags, which tells rsync to preserve the file permissions and the symbolic links, respectively.
h: This flag tells rsync to print the output in a human-readable format.
--delete: This flag tells rsync to delete any files in the destination location that don't exist in the source location.
The command is copying files from the location /location/ on the remote system with the IP address ip and the username user
to the local location /location2/.
The rsync command will preserve the file permissions, timestamps, and symbolic links,
and it will compress the files and show the progress of the transfer.
It will also delete any files in the destination location that don't exist in the source location.
# du
```bash
du -hdl /folder
```
The du command is used to estimate file space usage, and the -hdl flags are used to provide additional instructions for how the command should run.
h: This flag tells du to print the output in a human-readable format.
d: This flag tells du to only show the total size of directories, rather than listing the sizes of individual files.
l: This flag tells du to count the sizes of symlinks instead of the sizes of the files they point to.
In this command, du is being run on the directory /folder/, and the output will show the total size of the directories within that folder, in a human-readable format. The l flag is included, so if there are any symlinks within /folder/, their sizes will be counted instead of the sizes of the files they point to.
## Cgange ownership of a folder to user1:
```bash
chmod -R 775 /home/user2
sudo chown -R user1:user1 /home/user2/
```
# Symlinks or Symbolic links
Symbolic links, also known as symlinks, are a way to create a link between a file or a directory in one location to a file or directory in another location. By using symlinks, you can maintain two separate and distinct repositories while linking specific files or directories between them. Here's how you can use symlinks to achieve this:
Clone both repositories: Clone both of the repositories that you want to link together to your local system.
Create a symlink: In the first repository, navigate to the directory where you want to create the symlink and use the following command to create a symlink:
bash
Copy code
ln -s /path/to/second/repo/directory linked_directory
Replace "/path/to/second/repo/directory" with the path to the directory in the second repository that you want to link. Replace "linked_directory" with the desired name for the symlink.
Verify the symlink: You can verify that the symlink was created successfully by using the following command:
bash
Copy code
ls -l linked_directory
The output should show that the symlink was created and is pointing to the directory in the second repository.
Commit and push changes: Commit the changes to the first repository and push them to the remote repository.
By using symlinks in this way, you can keep the two repositories separate, but still have access to specific files or directories in one repository from the other repository. Additionally, changes made to the linked files or directories in one repository will be reflected in the other repository, since they are linked together.
# get the a file content in bash:
```bash
# $(< path/to/tokenFile) will output file content as input for the command
# $(minikube ip) will get the minikube ip
curl -H "Authorization: Bearer Bearer $(< path/to/tokenFile)" -k https://$(minikube ip):8080
```
Certainly, the concept of learning 20% to achieve 80% effectiveness is often called the Pareto Principle. Here's a quick overview that should give you the core functionalities of `awk` and `sed`.
### AWK
1. **Print Columns**: The most basic usage is printing specific columns from a file.
```bash
awk '{ print $1, $3 }' file.txt
```
This prints the first and third columns of each line in `file.txt`.
2. **Pattern Matching**: Match lines containing a pattern and perform an action.
```bash
awk '/pattern/ { print $0 }' file.txt
```
This prints lines that contain the word "pattern".
3. **Variables**: Built-in variables like `NR` (line number), `NF` (number of fields), and `FS` (field separator).
```bash
awk '{ print NR, $0 }' file.txt # Line numbers
awk 'BEGIN { FS=":" } { print $1 }' /etc/passwd # Change field separator to ":"
```
4. **Arithmetic Operations**: Perform calculations on columns.
```bash
awk '{ sum += $1 } END { print sum }' file.txt # Sum of first column
```
5. **Control Structures**: Use `if`, `else`, `for`, etc.
```bash
awk '{ if ($1 > 10) print $0 }' file.txt # Print lines where the first field is greater than 10
```
### SED
1. **Substitution**: Replace the first occurrence of a pattern in each line.
```bash
sed 's/pattern/replacement/' file.txt
```
To replace all occurrences, add `g` at the end: `'s/pattern/replacement/g'`.
2. **Deletion**: Remove lines matching a pattern.
```bash
sed '/pattern/d' file.txt
```
3. **Insertion**: Add a line before or after a pattern.
```bash
sed '/pattern/i\NewLineTextHere' file.txt # Before
sed '/pattern/a\NewLineTextHere' file.txt # After
```
4. **Multiple Commands**: Combine multiple `sed` commands with `-e`.
```bash
sed -e 's/foo/bar/' -e '/bar/d' file.txt
```
This replaces "foo" with "bar" and then deletes lines containing "bar".
5. **In-Place Editing**: Modify files directly (be careful with this).
```bash
sed -i 's/foo/bar/g' file.txt
```
By mastering these fundamental features, you'll cover a majority of common text-processing tasks you might encounter.
### AWK Special Variables
1. **`$0`**: Entire line of input
2. **`$1, $2, ..., $n`**: Individual fields (columns) in the line
3. **`NF`**: Number of Fields in the line
4. **`NR`**: Number of Records processed so far
5. **`FNR`**: Number of Records processed in the current file
6. **`FS`**: Field Separator (default is whitespace)
7. **`OFS`**: Output Field Separator (default is a space)
8. **`ORS`**: Output Record Separator (default is a newline)
9. **`RS`**: Record Separator (default is a newline)
10. **`FILENAME`**: Current filename being processed
11. **`ARGC`**: Argument Count, number of command line arguments
12. **`ARGV`**: Argument Vector, array of command line arguments
13. **`BEGIN`**: Special block executed before reading any lines
14. **`END`**: Special block executed after reading all lines
### SED Special Characters and Sequences
1. **`&`**: Refers to the entire portion of the input that was matched
2. **`\1, \2, ..., \9`**: Captured sub-patterns in a regex
3. **`^`**: Beginning of the line
4. **`$`**: End of the line
5. **`/d`**: Delete command
6. **`/p`**: Print command
7. **`/s`**: Substitute command
8. **`/g`**: Global flag for substitution
9. **`/i`**: Case-insensitive flag for matching
10. **`/a`**: Append text after a line
11. **`/i`**: Insert text before a line
12. **`/c`**: Replace a line with new text
13. **`/q`**: Quit after the first match
14. **`/n`**: Apply the script to the nth line
15. **`/m,n`**: Apply the script to lines m through n
Understanding these special variables and sequences will enable you to make the most out of `awk` and `sed` for text processing tasks.
Certainly, examples will make the usage of these special variables and commands clearer. Since I can't directly execute shell commands like `awk` or `sed` in this environment, I'll describe what the commands would do.
### AWK Examples
1. **`$0` and `$1, $2, ..., $n`**
Command: `awk '{ print "Entire Line: " $0 "; First Column: " $1 }'`
Input: `Hello World`
Output: `Entire Line: Hello World; First Column: Hello`
2. **`NF` and `NR`**
Command: `awk '{ print "Line " NR " has " NF " fields" }'`
Input:
```
Hello World
How are you
```
Output:
```
Line 1 has 2 fields
Line 2 has 3 fields
```
3. **`FNR` and `FILENAME`**
Command: `awk 'FNR==1 { print "Processing " FILENAME }' file1.txt file2.txt`
Output:
```
Processing file1.txt
Processing file2.txt
```
4. **`FS` and `OFS`**
Command: `awk 'BEGIN { FS=":"; OFS="-" } { print $1, $2 }'`
Input: `Hello:World`
Output: `Hello-World`
5. **`ORS` and `RS`**
Command: `awk 'BEGIN { ORS=" "; RS=";" } { print $0 }'`
Input: `Hello;World`
Output: `Hello World`
### SED Examples
1. **`&`**
Command: `sed 's/word/(&)/g'`
Input: `word another word`
Output: `(word) another (word)`
2. **`\1, \2, ..., \9`**
Command: `sed 's/\(word\) another \(word\)/\2 another \1/'`
Input: `word another word`
Output: `word another word`
3. **`^` and `$`**
Command: `sed 's/^/Start: /; s/$/ :End/'`
Input: `Hello`
Output: `Start: Hello :End`
4. **`/d` and `/p`**
Command: `sed -n '/word/p; /delete/d'`
Input:
```
word
delete
```
Output: `word`
5. **`/s` and `/g`**
Command: `sed 's/word/replacement/g'`
Input: `word another word`
Output: `replacement another replacement`
I hope these examples help clarify the usage of special variables and commands in `awk` and `sed`.