bash
Move the file `sales.csv` to the `data` directory and rename it to `sales-2023.csv` without overwriting an existing file using the `-n` option. This demonstrates file renaming and moving with safety against overwriting.
mv
bash
Move the file `sales.csv` to the `data` directory and rename it to `sales-2023.csv` without overwriting an existing file using the `-n` option. This demonstrates file renaming and moving with safety against overwriting.
mv
bash
Count the number of lines, words, and bytes in the `README.txt` file using the `wc` command. This demonstrates basic file statistics in Bash.
wc
bash
Extract specific columns (2 to 5 and 8) from a CSV file (`sales.csv`) using the `cut` command with a comma as the delimiter. This demonstrates how to select and display specific fields from a CSV file.
cut
bash
Open and view the contents of the `README.txt` file using the `less` command, allowing for easy navigation and reading within the terminal.
less
bash
Find all files with the `.ipynb` extension in the current directory and its subdirectories using the `find` command. This demonstrates searching for specific file types recursively.
find
bash
Display disk usage statistics for all files and directories in the current directory, showing sizes in a human-readable format. This command recursively lists the sizes of files and directories.
du
bash
List all files and directories recursively starting from the current directory. This command shows the contents of each directory and its subdirectories in a hierarchical format.
ls
bash
List files and directories in the current directory with detailed information, including file sizes in a human-readable format. This demonstrates the use of the `ls` command with the `-lh` options for detailed and human-readable output.
ls
bash
List all files and directories, including hidden ones, in the current directory using the `ls` command with the `-a` option. This demonstrates how to view all contents of a directory in Bash.
ls
bash
This snippet lists all directories in the `PATH` environment variable by splitting it into individual paths using `${PATH//:/ }` and then using `find` to locate directories within those paths. This demonstrates how to manipulate and search the `PATH` in Bash.
find
bash
This code demonstrates the use of `PIPESTATUS` in Bash to check the exit status of commands in a pipeline. It pipes the string `'foo'` through `grep` and `sed`, then uses `PIPESTATUS` to retrieve the exit status of a specific command in the pipeline (e.g., `grep` or `sed`). This is useful for debugging or conditional logic based on pipeline command success.
printf grep sed
bash
Read Bash documentation using the `info` command. The first command opens the Bash manual, the second searches for the "Bash Features" section, the third opens the manual at node 6, and the fourth searches for all topics related to Bash. This demonstrates how to navigate and search the Bash info documentation.
info
bash
Search for `info` related commands using `apropos`, filter results with `grep`, and explore the `info` documentation using `man`, `info`, and `info 5`. This demonstrates how to access and navigate `info` documentation.
apropos grep man info
bash
Display Bash documentation using `apropos` to search for related manual pages and `man` to view the Bash manual. This demonstrates how to access and read Bash documentation directly from the command line.
apropos man
bash
Use `fgrep` (or `grep -F`) to search for the literal string "foobar" in `file.txt`. This demonstrates searching for a fixed string rather than a regular expression.
fgrep
bash
Search for lines in `file.txt` that start with `foo` and end with `bar`, then filter out any lines containing `baz`. This demonstrates combining `grep` with a pattern and using `grep -v` to exclude specific matches.
grep
bash
This snippet demonstrates various useful options for the `grep` command: - `grep -r` recursively searches for a pattern in a directory. - `grep -n` includes line numbers in the output. - `grep -rI` recursively searches but ignores binary files. These options enhance the functionality of `grep` for different use cases.
grep
bash
Count the number of lines in `file.txt` that match the regex pattern `^foo.*bar$`. The `-c` option in `grep` is used to print the count of matching lines instead of the lines themselves. This demonstrates how to count occurrences of a specific pattern in a file.
grep
bash
Print to stdout all lines from `file.txt` that match the regex pattern `^foo.*bar$`, which matches lines starting with "foo" and ending with "bar". This demonstrates using `grep` to filter lines based on a regular expression.
grep
bash
Replace every occurrence of the string `okay` with `great` in `file.txt` using `sed`. The `-i` flag modifies the file in place, overwriting the original content. This demonstrates in-place file editing with `sed`.
sed