I’m on a journey to become a DevOps professional, so like many others, I jumped straight into Docker—it’s undeniably essential. I even learned the basics check out this guide. But later, I realized just how important Linux is, so I naturally started with Bash😅.
(No output; the text is appended to greetings.txt.)
7. Additional Helpful Commands
history – Viewing Command History
Review commands you’ve recently executed.
Usage:
history
Sample Output:
1 ls -l
2 cd Documents
3 cat file.txt
...
alias – Creating Command Shortcuts
Simplify long commands by creating aliases.
Example:
alias ll='ls -alF'
Output:
(No output; the alias is now set for the current session. Add to your ~/.bashrc for persistence.)
df and du – Disk Space Usage
Monitor your disk usage.
df – Display disk free space in a human-readable format:
df -h
Sample Output:
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 50G 20G 28G 42% /
tmpfs 7.8G 0 7.8G 0% /dev/shm
du – Show disk usage for files and directories:
du -sh *
Sample Output:
4.0K file.txt
1.2M Documents
500K Downloads
8. Pipes and Redirection
Pipes and redirection are powerful features in Bash that allow you to control how data flows between commands and files, enabling you to build complex command sequences and automate tasks efficiently.
Pipes (|)
Purpose:
A pipe ( | ) takes the output (stdout) of one command and sends it directly as input (stdin) to another command.
Example 1: Paginating Output
ls -l | less
Explanation:
ls -l produces a detailed list of files.
less displays this output one page at a time.
Example 2: Filtering Data
dmesg | grep "error"
Explanation:
dmesg outputs system messages.
grep "error" filters for lines containing “error”.
Redirection
Redirection lets you change where the output of a command goes or where the command reads its input.
Standard Output Redirection (>)
**Purpose:**Redirects command output to a file, overwriting the file if it exists.
Example:
echo "Hello, Linux!" > greetings.txt
Explanation:
Writes “Hello, Linux!” to greetings.txt.
Appending Output (>>)
**Purpose:**Appends command output to the end of a file instead of overwriting it.
Example:
echo "Welcome back!" >> greetings.txt
Explanation:
Adds “Welcome back!” to the end of greetings.txt.
Standard Input Redirection (<)
**Purpose:**Directs a command to take input from a file.
Example:
sort < unsorted.txt
Explanation:
sort reads from unsorted.txt and outputs sorted results.
Combining Pipes and Redirection
You can mix pipes and redirection for advanced tasks. For example:
Save Filtered Output to a File:
dmesg | grep "error" > errors.txt
Explanation:
Filters dmesg output for “error” and saves it to errors.txt.
9. Best Practices and Tips for Beginners
**Double-check before deleting:**Always review what you’re deleting, especially when using recursive options like rm -rf.
**Use man or --help:**If in doubt, check the manual or use command --help for guidance.
**Keep your system updated:**Regularly run commands like sudo apt update (on Debian-based systems) to maintain software currency.
**Experiment safely:**Use a test directory or virtual machine to try out commands without risking important files.
10. Conclusion
That’s all for not, this guide covers the essentials of the Linux Bash terminal—from navigation and file management to searching, permissions, and system maintenance. With these commands, sample outputs, and best practices at your fingertips, you’re well on your way to mastering the Linux command line.a critical skill for any aspiring DevOps professional.