Skip to content

Instantly share code, notes, and snippets.

@mapkyca
Last active December 14, 2015 18:38
Show Gist options
  • Save mapkyca/5130330 to your computer and use it in GitHub Desktop.
Save mapkyca/5130330 to your computer and use it in GitHub Desktop.
Useful commands, so I don't have to keep looking

Useful shell commands

Shell

  • Find which directories are the disk hogs

    du --max-depth=1 -h | sort -h

  • Copy a mysql database from one server to another via ssh

    mysqldump -u root -pPASSWORD --all-databases | ssh USER@NEW.HOST.COM 'cat - | mysql -u root -pPASSWORD'

    Note, you must restart the target mysql server afterwards, and if you do you may get the error "ERROR 1045 (28000): Access denied for user 'debian-sys-maint'@'localhost'" (on debian at least).

    Fix this by executing the command:

    GRANT ALL PRIVILEGES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY 'THE PASSWORD' WITH GRANT OPTION;

    Where 'THE PASSWORD' is the password found in /etc/mysql/debian.cnf

  • Message users on a remote server

    echo "message" | ssh user@host wall

    or

    echo "message" | ssh user@host sudo wall

    to send something as the admin.

Mail servers

  • How many messages are there in the queue?

exim -bpc

  • Test routing to an address (useful for problem diagnosis)

exim -bt alias@example.com

  • Restarting a mail queue and attempt redelivery

exim -q -v

  • Thaw all messages

exim -bp | grep -i frozen | awk '{print $3}' | while read LINE; do exim -Mt $LINE; done

Ubuntu EC2 Instances

  • Rsync files to server as root user

rsync -Pavz -e "ssh -i KEYPAIR.pem" --rsync-path "sudo rsync" LOCALFILES ubuntu@HOSTNAME:REMOTEDIR/

Squid

  • Remove a URL from cache / force refresh

    squidclient -m PURGE http://url

Elgg

  • Find all translation content containing a string (in this case "Friend")

    find . -name en.php | xargs -i{} cat {} | egrep "=.["|'][f|F]riend*"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment