Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
10 Lesser Known Effective Linux Commands
Linux is a powerful operating system widely used in software development, web hosting, and cloud computing. While most users know basic commands like ls, cd, and cp, Linux offers many lesser-known commands that can significantly boost productivity. These hidden gems can automate complex tasks, save time, and simplify system administration. Let's explore 10 effective but underutilized Linux commands.
1. 'rename' Command
The rename command allows you to rename multiple files at once using Perl regular expressions. This is far more powerful than renaming files one by one.
rename 's/oldname/newname/' files
For example, to change all .txt files to .md files:
rename 's/\.txt$/.md/' *.txt
You can also add prefixes, remove spaces, or change case:
rename 's/ /_/g' * # Replace spaces with underscores rename 'y/A-Z/a-z/' * # Convert to lowercase
2. 'at' Command
The at command schedules one-time tasks to run at specific times, unlike cron which handles recurring tasks.
echo "/path/to/script.sh" | at 2:30 PM at 10:00 AM tomorrow << EOF echo "Backup completed" | mail user@domain.com EOF
Use atq to list scheduled jobs and atrm to remove them:
atq # List pending jobs atrm 3 # Remove job number 3
3. 'nc' (Netcat) Command
Often called the "Swiss Army knife of networking", nc can establish network connections, transfer files, or even create simple servers.
nc 192.168.1.100 8080 # Connect to host on port 8080 nc -l 9999 # Listen on port 9999 echo "Hello" | nc host 1234 # Send data to remote host
You can use it for port scanning or file transfers:
nc -zv google.com 80-90 # Port scan range 80-90 nc -l 9999 > received_file # Receive file on port 9999 nc target_host 9999 < file.txt # Send file to target
4. 'xargs' Command
The xargs command builds and executes commands from standard input, making it perfect for pipeline operations.
find . -name "*.txt" | xargs rm # Delete all .txt files
ls *.jpg | xargs -I {} cp {} /backup/ # Copy with placeholder
echo "file1 file2 file3" | xargs -n 1 ls -l # Process one at a time
Handle files with spaces using null delimiters:
find . -name "*.txt" -print0 | xargs -0 rm
5. 'watch' Command
The watch command repeatedly executes a command and displays the output in real-time, perfect for monitoring system changes.
watch -n 2 "df -h" # Monitor disk usage every 2 seconds watch -d "ps aux | grep apache" # Highlight differences watch -n 0.5 "netstat -tuln" # Monitor network connections
The -d flag highlights differences between updates, making it easy to spot changes.
6. 'split' Command
The split command divides large files into smaller, manageable chunks based on size or line count.
split -b 100M bigfile.txt part # Split by size (100MB chunks) split -l 1000 logfile.txt line # Split by lines (1000 lines each) split -n 5 data.txt chunk # Split into 5 equal parts
To reassemble split files:
cat part* > reassembled_file.txt
7. 'tee' Command
The tee command reads from standard input and writes to both standard output and files simultaneously, like a T-junction in plumbing.
ls -la | tee file_list.txt # Save and display output echo "Log entry" | tee -a log.txt # Append to file and display ps aux | tee process_list.txt | grep apache
This is invaluable for logging command output while still seeing it on screen.
8. 'jobs' and 'nohup' Commands
Manage background processes efficiently with jobs, bg, fg, and nohup.
./long_script.sh & # Run in background jobs # List background jobs fg %1 # Bring job 1 to foreground bg %2 # Send job 2 to background nohup ./script.sh & # Run immune to hangups
Use nohup for processes that should continue running even after you log out.
9. 'pgrep' and 'pkill' Commands
These commands provide more precise process management than traditional ps and kill combinations.
pgrep -f "python script.py" # Find process by full command line pkill -f "backup" # Kill processes matching pattern pgrep -u username # Find processes by user pkill -TERM apache2 # Send specific signal
Much cleaner than ps aux | grep process | kill combinations.
10. 'column' Command
The column command formats text into neat columns, making data more readable.
mount | column -t # Format mount output in columns cat /etc/passwd | column -t -s ':' # Use colon as separator ls -la | column -t # Align output in columns
Perfect for formatting CSV files or making command output more readable.
Practical Examples
Here are some powerful command combinations using these lesser-known tools:
# Monitor Apache processes every 3 seconds with differences highlighted
watch -d -n 3 "pgrep -a apache2"
# Find large files and format output nicely
find /var -size +100M -exec ls -lh {} \; | column -t
# Schedule a system cleanup for tonight
echo "apt-get autoremove -y && apt-get autoclean" | at 11:00 PM
# Backup and compress log files older than 7 days
find /var/log -name "*.log" -mtime +7 | xargs tar -czf old_logs.tar.gz
Conclusion
These 10 lesser-known Linux commands can dramatically improve your command-line productivity. From batch file operations with rename and xargs to system monitoring with watch and process management with pgrep, mastering these tools will make you a more efficient Linux user. Start incorporating them into your daily workflows to unlock Linux's full potential.
