Member-only story

My Top 5 Commands for Hacktoberfest

Useful commands to enhance Bash scripting

Not affiliated with Hacktoberfest

In my opinion, every developer should customize their command line environment to be as efficient as possible! Like other languages, you can use existing libraries and commands to automate frequent tasks. Here are my go to commands that I use as tools within other scripts.

1. The Command Command

This command is super useful for determining when a command exists. The command command is similar to the which command, however, you can ignore the output when a command is not found. Since the path of a command only displays when a particular command exists, the command command is great for if statements in your script.

if ! command -v MyCommand; then
echo "MyCommand could not be found"
exit
fi

2. The xargs Command

This command is a lot like the method map in popular languages like JavaScript, Python, or Ruby. This command allows devs to run another command for each space, tab, newline, or EOF (you can change the delimiter). This is my go to command when parsing lists or csv files.

# get line count for each php filels *.php | xargs wc -l

3. The find Command

--

--

Wade Zimmerman πŸ‘¨πŸ»β€πŸ’»
Wade Zimmerman πŸ‘¨πŸ»β€πŸ’»

Written by Wade Zimmerman πŸ‘¨πŸ»β€πŸ’»

I write to vent my frustrations and don’t think much before posting

No responses yet