Boost Your Productivity with Advanced Linux Command Tricks
This article introduces a collection of practical, intermediate‑level Linux commands—including custom bash prompts, powerful find usages, permission shortcuts, alias tricks, awk data extraction, xargs chaining, variable handling, I/O redirection, and the fzf fuzzy finder—to help IT professionals work more efficiently in DevOps and everyday shell environments.
As an IT professional, mastering Linux commands is essential; even on Windows or macOS you’ll encounter situations that require Linux, especially when working with Docker images or DevOps tasks.
This article shares a set of daily‑used, advanced commands for those new to Linux or looking to deepen their knowledge, deliberately skipping basic commands like
cdor
ls.
1. Custom Bash Prompt
Modify the
PS1variable to simplify the prompt. Example:
<code>export PS1="[\u@\W]\$"</code>Here
\ushows the username and
\Wshows the current directory;
$appears for non‑root users,
#for root. Add the command to
~/.bashrcfor persistence.
2. Find Command Enhancements
Search files and directories, then count lines in each
.htmlfile:
<code># Find a file
find ~ -type f -name data-model.ts
# Find a directory
find ~ -type d -name angular15
# Count lines in all .html files
find src/app/ -name "*.html" -exec wc -l {} \;</code>Using
+instead of
\;aggregates the total line count:
<code>find src/app/ -name "*.html" -exec wc -l {} +</code>3. Change File and Directory Permissions
Permission bits follow the
rwxmodel (read = 4, write = 2, execute = 1). Common examples:
<code># Share a folder (read/write/execute for owner, read/execute for group and others)
chmod 755 <path-to-your-folder>
# Share a non‑executable file
chmod 644 <path-to-your-file>
# Make a file executable
chmod +x <path-to-your-file></code>4. Alias rm to Move Files to Trash
<code>alias rm='gio trash'</code>5. Use Aliases to Simplify Long Commands
<code># Common aliases
alias dc="docker compose"
alias prettier="npx prettier -w"
alias eslint="npx eslint --fix"
alias pre="pre-commit run --files"
# Chain commands for container updates
alias update-container="docker-compose pull <service-name> && docker-compose stop <service-name> && yes | docker-compose rm <service-name> && docker-compose up -d <service-name>"</code>6. Extract Data with awk
Example: ping
google.comand print only the time values:
<code>ping google.com -c 2 | grep -iE 'time=.*ms' | awk 'BEGIN {FS="="} {print $NF}'</code>Key points:
-iEmakes
grepcase‑insensitive;
BEGINruns before processing;
FSsets the field separator;
$NFreturns the last field.
Simplified forms:
<code>ping google.com -c 2 | grep -iE 'time=.*ms' | awk -F"=" '{print $NF}'
ping google.com -c 2 | awk -F"=" '/time=.*ms/ {print $NF}'</code>7. Chain Commands with xargs
<code># Show size of each file in current directory
ls | xargs -I % du -sh %
# Copy all JPEGs from Downloads to Pictures
find ~/Downloads/ -name "*.jpeg" | xargs -I {} cp {} ~/Pictures/
# Change permissions of all directories to 755
find . -type d | xargs -I {} chmod 755 {}
# Change permissions of all files to 644
find . -type f | xargs -I {} chmod 644 {}</code>The
-Ioption defines a placeholder (commonly
%or
{}).
8. Pass Variables to Scripts
<code># Inline variables
USERNAME=johndoe PASSWORD=12345 bash some_script.sh
# Load from a file
# variables.env
USERNAME=johndoe
PASSWORD=12345
# Run script with variables from file
env $(grep -v '^#' variables.env | xargs) bash some_script.sh</code>9. Redirect STDOUT and STDERR
<code># Redirect STDOUT to a file
ls -al existing.txt >out.log
# Redirect STDOUT and STDERR to separate files
ls -al existing.txt non-existing.txt 1>out.log 2>error.log
# Combine both streams into one file
ls -al existing.txt non-existing.txt &>combined.log
# Discard all output
ls -al existing.txt non-existing.txt &>/dev/null</code>Note: The > syntax is supported by Bash, not all shells.
10. Command‑Line Fuzzy Finder ( fzf )
Install
fzfto enhance
CTRL‑Rhistory search.
<code># Linux
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
~/.fzf/install # accept defaults
# macOS
brew install fzf
$(brew --prefix)/opt/fzf/install</code>After installation,
fzfprovides an interactive, fuzzy‑searchable list of previous commands.
This collection of Linux commands aims to improve efficiency; while it cannot cover every possible command, it offers a practical reference for daily work.
Efficient Ops
This public account is maintained by Xiaotianguo and friends, regularly publishing widely-read original technical articles. We focus on operations transformation and accompany you throughout your operations career, growing together happily.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.