Command line use notes
Bash notes
For compatibility, use this as shebang on scripts:
#!/usr/bin/env bash
Temporarily disable the bash history
set +o history
Some useful parameters on scripts
set -e # exit on error
set -u # exit when undeclared variables exist
set -x # trace what gets executed
As a recommendation, use variables like: "${var}" to avoid
problems with the names
Send to background
End commands with & to execute on background
When the command is already running, use ctrl+z to turn
it into zombie (in background but not executing)
With jobs you can print already running processes
With fg you can bring back zombies processes from background
to foreground and they start executing, with bg you can
let zombie processes execute in the background.
Remember you can use
kill -9 PIDto kill a proccess To obtain the PID, useps axUsereniceto adjust priority of processes
for statement
Example of a for statement, this example does something like ls
for i in ./* ; do echo "$i" ; done
Umask
Use umask to temporarily change the default permissions
Owner only read
umask 277
Owner only read and write
umask 177
Find
Find is a very useful command to search files and execute commands on them.
Find all .log files and delete them
find /path/to/search -type f -name "*.log" -exec rm -f {} \;
VIM notes
You can use regex expressions on vim, for example, to delete all comment lines:
:g/^\s*#/d
You can invoke netrw which is kinda file explorer
:Explore - opens netrw in the current window
:Sexplore - opens netrw in a horizontal split
:Vexplore - opens netrw in a vertical split
You can also snigger by typing :Sex to invoke a horizontal split.
How to copy paste on vim
- Position the cursor where you want to begin cutting.
- Press v to select characters, or uppercase V to select whole lines, or Ctrl-v to select rectangular blocks (use Ctrl-q if Ctrl-v is mapped to paste).
- Move the cursor to the end of what you want to cut.
- Press d to cut (or y to copy).
- Move to where you would like to paste.
- Press P to paste before the cursor, or p to paste after.