Skip to content

Bash Scripting

Generate a Password

tr -cd '[:alnum:]' < /dev/urandom | fold -w31 | head -n1

export PASSWORD=`tr -cd '[:alnum:]' < /dev/urandom | fold -w31 | head -n1`
echo $PASSWORD > code-server-pass.txt

How to append to path

PATH=$PATH:/home/$USER/.local/bin

https://unix.stackexchange.com/questions/26047/how-to-correctly-add-a-path-to-path

Use Input Output Redirection

  • Less can be used to view files similar to cat
  • > can output a text into a file
  • >> if exists append to a file
  • < is like accepting input
  • 2> and 2>> if error output that as well
  • 2>&1 Output working command to terminal
  • One can output to dev/null for death of the output
  • chmod u+x Use this cause it limits use to a specified user
  • head see first 10 lines of a file
  • tail last 10 lines of a file

TODO

Use Input Output Redirection 

permissions - How to insert text into a root-owned file using sudo? - Unix & Linux Stack Exchange

https://superuser.com/questions/67765/sudo-with-password-in-one-command-line

bash - How to redirect the output of the time command to a file in Linux? - Stack Overflow

shell - How to check if a file contains a specific string using Bash - Stack Overflow

bash - How to measure time of program execution and store that inside a variable - Unix & Linux Stack Exchange