# CLI #IT ## Postgres (into psql) ```sql SET search_path TO myschema; -- "use" for schemas \l -- Display database \c database_name -- Connect to database \dn -- List schemas \dt -- List tables inside public schemas \dt schema1. -- List tables inside particular schemas. For eg: 'schema1'. \q -- exit (ctrl + D also works) ``` ## Reload Python Modules (shell) ```python >>> from importlib import reload reload Module >>> import MyPak >>> reload(MyPak) >>> from MyPak import MyMod ``` ## Docker with Bash ```shell docker-compose run --rm api bash ``` ## Kill last suspended job ```shell jobs -p % # to show pid kill %% # to kill last suspended ``` ## Delete Big Directories ```shell cd yourdirectory perl -e 'for(<*>){((stat)[9]<(unlink))}' ``` or yet ```shell mkdir empty_dir rsync -a --delete empty_dir/ yourdirectory/ ``` ## Sort by First Column (-k) as Number (-g) ```shell ... | sort -k 1 -g ``` ## Columns Missing Activity Monitor (MacOS) ```shell rm ~/Library/Preferences/com.apple.ActivityMonitor.plist ``` ## Merge Enchantment by Alex (for solo branches) ```shell git checkout company_spec git pull --rebase git rebase origin/develop … resolve conflitos … git add … git push --force-with-lease company_spec ``` ## Output Redirection ```shell Redirect stdout to one file and stderr to another file: command > out 2>error Redirect stdout to a file (>out), and then redirect stderr to stdout (2>&1): command >out 2>&1 Redirect both to a file (this isn't supported by all shells, bash and zsh support it, for example, but sh and ksh do not): command &> out ``` ## xargs for each line ```bash pgrep Google | xargs -L 1 echo ">>" ``` ## Drop In Replacement for Guard ```bash SKIP_COV=true filewatcher 'spec/**/*spec.rb' 'spring rspec -f doc $FILENAME' ``` ## Reapply git commits into another branch ``` If your history looks like this: - x - x - x (v2) - x - x - x (v2.1) \ x - x - x (v2-only) - x - x - x (wss) You could use git rebase --onto v2 v2-only wss to move wss directly onto v2: - x - x - x (v2) - x - x - x (v2.1) |\ | x - x - x (v2-only) \ x - x - x (wss) ``` ## List all IP addresses connected to your Server ```shell netstat -tn 2>/dev/null | grep :80 | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr | head ``` ## Packages I removed from xbian 30/07 ```shell upstart xbian-package-config-xbmc xbian-update ``` ## Turn WiFi back on on RPi 3 B+ ```shell sudo iwconfig wlan0 txpower on ``` ## All NAT connections `# netstat-nat` ## IPTables Forward a Port: ```shell iptables -t nat \ -A PREROUTING \ -p tcp \ -d 189.4.10.129 \ --dport 59166 \ -j DNAT \ --to 172.22.1.88:5900 ``` ## Fast Webserver ```shell python -m SimpleHTTPServer ``` ## Speed Test ```shell curl -s https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py | python - ``` ## Monitor RPi CPU ```shell vcgencmd measure_temp && vcgencmd measure_clock arm ``` ## Sometimes I need this ```shell sudo update-rc.d <some service> defaults ``` ## Lists exports of a server ```shell showmount -e <server ip> ```` ## Find process blocking given port (MacOS ≥ El Capitan) ```shell sudo lsof -i tcp:3000 ``` ## Bring Back Subpixel Rendering ```shell defaults write -g CGFontRenderingFontSmoothingDisabled -bool NO ``` ## Stop Gatekeeper on MacOS: ```shell sudo spctl --master-disable ``` ## Directory Tree Find and Replace ```shell find . -type f | xargs sed -i 's/uniqueness: {\(.*\)}/uniqueness: {\1, case_sensitive: true}/g' ```