Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Wade Zimmerman
Wade Zimmerman

Posted on • Originally published atdevmap.org

     

My Top 5 Commands for 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. TheCommand Command

This command is super useful for determining when a command exists. Thecommand command is similar to thewhich 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, thecommand command is great for if statements in your script.

if ! command -v MyCommand; then    echo "MyCommand could not be found"    exitfi
Enter fullscreen modeExit fullscreen mode

2. Thexargs Command

This command is a lot like the methodmap 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
Enter fullscreen modeExit fullscreen mode

3. Thefind Command

This command is likels on steroids. It can list out folder contents but it can also walk a file tree. This is super useful if you want to find a file with a specific name but you don't know where it is. This command could be a whole other article because it has advance querying capabilities.

find $PWD -name "*.php"
Enter fullscreen modeExit fullscreen mode

4. Thecurl Command

This command is all you need for fetching remote data through common protocols like FTP, HTTP/S, LDAP, MQTT, SMB, Telnet, etc. As an average Joe, I tend to use curl for consuming REST APIs. For example, you could get JSON from GitHub's or Reddit's public API.

curl -s https://api.github.com/repos/forem/forem/commits\?per_page\=5
Enter fullscreen modeExit fullscreen mode

5. Thejq Command (Requires Install)

This is a command line utility built specifically for parsing JSON. It can index JSON objects/arrays, and it can also handle advanced queries, optional chaining, conditionals, and more. If you are consuming JSON in your bash scripts, this is a must have.

# get a list of unique commit authors from GitHub repocurl -s "https://api.github.com/repos/forem/forem/commits?per_page=20" \ | jq -r '[.[].commit.author.name] | unique | .[]'
Enter fullscreen modeExit fullscreen mode

6. Bonus: Theman Command

Most well engineered commands have a--help flag but sometimes that flag only shows you which arguments are accepted. If you want to get a full overview of how a command works and sometimes "why it works" you should use theman command. This command will show you a specific manual page for a command. Yes, some commands have multiple pages.

man findman 3 echoman 7 hostname
Enter fullscreen modeExit fullscreen mode

Conclusion / takeaways

Bash scripting can be overwhelming but once you break down your scripts into components which can be handled by other tools, it becomes a very powerful language for getting things done.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Code by day; blog by night
  • Location
    California
  • Education
    Networking/Software
  • Work
    Self Employed
  • Joined

More fromWade Zimmerman

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp