Skip to content

Instantly share code, notes, and snippets.

@zsim0n
Last active August 29, 2015 14:04
Show Gist options
  • Save zsim0n/dcfa7d87f202a910e639 to your computer and use it in GitHub Desktop.
Save zsim0n/dcfa7d87f202a910e639 to your computer and use it in GitHub Desktop.
Usefull shell commands
#!/bin/bash -eux
# Get an admin login link
drush uli
# Set the password for any user
drush upwd admin --password="newpassword"
#!/bin/bash -eux
# Block traffic on port 25 (SMTP)
iptables -A OUTPUT -p tcp --dport 25 -j REJECT
iptables-save
# Allow traffic on port 25 (SMTP)
iptables -D OUTPUT -p tcp --dport 25 -j REJECT
iptables-save
# Parse .my.cnf for saved password
grep password ~/.my.cnf | awk -F ' *= *' '{ if ($1 ~ /^\[/) section=$1; else if ($1 !~ /^$/) print $2}'
# Add something to path
export PATH=path/to/something:$PATH
# Mount home via sshfs
sshfs user@server:/~ /path/to/local
# Mac
sshfs user@server:/~ /Volumes/folder
# Use identity file
sudo sshfs -o IdentityFile=~/.ssh/id_rsa [email protected]:/ /mnt/droplet
#Umount
sudo umount /mnt/droplet
# Generate ssh key https://help.github.com/articles/generating-ssh-keys
ssh-keygen -t rsa -C "[email protected]"
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa
pbcopy < ~/.ssh/id_rsa.pub
# Test ssh key
ssh -T [email protected]
# Transfer public key to a server
scp ~/.ssh/id_rsa.pub user@server:.ssh/id_rsa.name.pub
ssh user@server
cd ~/.ssh
cat id_rsa.name.pub >> authorized_keys
cd ~/.ssh
chmod u+w authorized_keys
chmod go-w authorized_keys
cd
chmod u+w .ssh
chmod go-w .ssh
chmod go-w .
# List Content of .tar .tar.gz .tar.bz2 http://www.cyberciti.biz/faq/list-the-contents-of-a-tar-or-targz-file/
tar -tvf file.tar
tar -ztvf file.tar.gz
tar -jtvf file.tar.bz2
# List Uniq directory names for .tar
tar -tvf file.tar | grep "^d" | awk '{ print $6}' | sort | uniq
#PHP lint
find ./foo ./bar \( -name "*.php" -or -name "*.phtml" \) -print0 | xargs -0 -n 1 php -l
find -name "*.php" -print0 | xargs -0 -n 1 php -l
#remote execution ssh mysqldump
ssh user@host remoteserver "mysqldump -mysqldumpoptions database | gzip -3 -c" > /localpath/localfile.sql.gz
#!/bin/bash
for branch in `git branch -a | grep remotes | grep -v HEAD | grep -v master `; do
git branch --track ${branch#remotes/origin/} $branch
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment