Karan's Programming Notes
Get number of cores using bash
Initializing search
    mr-karan/notes
    mr-karan/notes
    • Home
      • CLI
      • EC2 Metadata inside Docker
      • EC2 Pricing
      • View the volume ID in Instance
      • FAQ
      • Snippets
      • Vault
      • Query Snippets
      • Securing server with RBAC
      • CLI
      • Custom DNS Server
      • Custom subnet
      • CI
      • Decode JSON with proper types
      • Inspect HTTP Headers
      • Profile Golang Applications
      • Update Golang Version
      • CLI
      • Debug CNI Issues
      • Control Brightness
      • Create a MacOS like screenshot effect
      • Filesystem
      • Git
      • JournalD
      • Networking
      • SystemD
      • cURL
      • Ps
      • Rsync
      • Sed
      • Add Table of Images in Markdown
      • Connect to Pritunl with a custom DNS server
      • CLI
      • Editor setup
      • Single Node Setup
      • Generate Million Rows
      • Reset WAL Log
      • Transform requests to cURL
      • UTC to Local Time
      • Generate Random String
      • Get filename using bash
      • Get number of cores using bash
      • Line count for each file
      • Most used shell commands
      • Run a command as a different user
      • Safe Template
      • View a CSV file in Terminal
      • Snippets
      • Snippets

    Get number of cores using bash

    nproc is part of coreutils package that gives the number of cores available in an easy to consume way (no more grepping and parsing ).

    I wanted this to set VECTOR_THREADS variable for vector CLI to 1/2 of what is available on system.

    #!/bin/bash
    
    set -e
    
    cores=`nproc --all`
    cap=2
    VECTOR_THREADS=$((cores / cap))
    
    vector --config /etc/vector
    
    Previous Get filename using bash
    Next Line count for each file
    Made with ❤️ by Karan.
    Made with Material for MkDocs