Skip to content

Instantly share code, notes, and snippets.

@chhantyal
Last active December 26, 2015 20:49
Show Gist options
  • Save chhantyal/7211365 to your computer and use it in GitHub Desktop.
Save chhantyal/7211365 to your computer and use it in GitHub Desktop.
Some useful server commands - Linux, nginx, uwsgi or gunicorn, Postgres and supervisor
# Kernel version and system architecture
uname -a
# Name and version of distribution
head -n1 /etc/issue
# Partitions registered on the system
cat /proc/partitions
# Total RAM seen by the system
grep MemTotal /proc/meminfo
# CPU(s) info
lscpu
# and
grep "model name" /proc/cpuinfo
# Info about disk sda
hdparm -i /dev/sda
find / -type f -iname "filename*"
rsync -avPhzL -e ssh user@host:/var/file_to_sync
# Safely close all connections to database - on db1
SELECT pg_terminate_backend(procpid) FROM pg_stat_activity WHERE datname='dbname';
# Restore dumped data
pg_restore -c -d [database_name] [dumpfile_name].dump
# Supervisor conf dir
/etc/supervisor/conf.d
# heroku config
heroku config -s --app <appname>
## SCP - copy files over ssh
# copy from local machine to remote machine
scp localfile user@host:/path/to/whereyouwant/thefile
# copy from remote machine to local machine
scp user@host:/path/to/remotefile localfile
# pipe dumped plain text db file
cat databases.out | psql [dbname]
# Github change issue to Pull Request
hub pull-request -b UPSTREAM_USERNAME:UPSTREAM_BRANCH -h YOUR_USERNAME:YOUR_BRANCH URL_TO_ISSUE
# Postgres
$ su - postgres
$ createdb mydb
$ psql -s mydb
$ create user someuser password 'somepassword';
$ GRANT ALL PRIVILEGES ON DATABASE mydb TO someuser;
# shortcut to psql with root user
$ sudo -u postgres psql postgres
# history search
$ history |grep 'python'
# Recursively count number of files in a directory
find DIR_NAME -type f | wc -l
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment