Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

README.md

[toc]

About

Collection of various bash commands.

Bash

  • Kill/stop all process with particular port
    kill $(ps aux | grep 8888 | awk '{print $2}')
    
  • Kill/stop all processes star were started by the VS Code via Remote-SSH:
    ps -ef | grep ".vscode-server" | awk '{print $2}' | xargs kill
    

Ubuntu: various bash commands

  • Show linenumners in nano

    nano -l <file>
  • Determine number of cores + CPUs

    lscpu | grep -E '^Thread|^Core|^Socket|^CPU\('
    
    echo "Cores = $(( $(lscpu | awk '/^Socket\(s\)/{ print $2 }') * $(lscpu | awk '/^Core\(s\) per socket/{ print $4 }') ))"
    
  • List directory as tree (required: apt-get install tree)

    tree .
    tree -a .
    
  • Flush disk cache

    sync; echo 3 > /proc/sys/vm/drop_caches
  • Shows lines of an output file with grep

    grep -n <pattern> <file>
    cat -n <file> | grep <pattern>

Ubuntu: Configure locale

  • To change locale do the following
    sudo locale-gen en_US.utf8
    sudo update-locale LANG=en_US.utf8
    

Ubuntu: disk space problem (e.g., LTS 18.04)

  • Determine the space available on the disks (df)

    sudo df -h
    
  • Determine the space available on the disks (du)

    • Size on disk (all folders, sorted high -> low)
      sudo du -hsc .* * | sort -rh
      
    • Size on disk
      sudo du -hsc *
      
    • Real size of files
      sudo du -hbc *
      
    • Size of a single folder
      sudo du -sh /var
      
    • Sort output
      sudo du -h | sort -rh
      
  • Information about disks

    sudo lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL
    
  • Remove some staff

    sudo apt clean # remove cache
    

Ubuntu: Relevant articles

Configure alias for bash

  • How to configure alias-es (add the lines to the end of the file)
    nano ~/.bashrc
  • Configure ls
    alias ls='ls --time-style=long-iso --color=tty -Altrh'
  • Color the grep-match for easy reading.
    alias grep='grep -inE --color=auto'
  • Show linenumners in nano
    alias nano='nano -l'

bash history

  • Execute a command without keeping it in history
    <your_secret_command>; history -d $((HISTCMD-1))
    
  • Execute a command without keeping it in history (can start your session with)
    export HISTFILE=/dev/null ;history -d $(history 1)
    
  • Add timestamp to bash commands (check by calling history)
    echo 'export HISTTIMEFORMAT="%F %T "' >> ~/.bashrc
    
  • Relevant articles
    • Execute a command without keeping it in history

Troubleshoot network connection

  • Use tcpdump utility to monitor desired ports
    sudo tcpdump port 443 and '(tcp-syn|tcp-ack)!=0'
  • Active TCP connections
    netstat -plunt
    
  • Display all active Internet connections
    netstat -natp
    
  • Find out processes that uses paricular port
    netstat -nlp | grep ':80'
    

zsh

zsh - issues

Fix issues with keys by editing nano ~/.zshrc text bindkey "^[[H" beginning-of-line bindkey "^[[F" end-of-line

fish

Linux Utils

Configurations

Useful cli utils