Skip to content

Instantly share code, notes, and snippets.

@alexandervantrijffel
Last active July 4, 2018 16:07
Show Gist options
  • Save alexandervantrijffel/3ba5288420c4d65d5605985835270455 to your computer and use it in GitHub Desktop.
Save alexandervantrijffel/3ba5288420c4d65d5605985835270455 to your computer and use it in GitHub Desktop.
grep -r -i --include \*.cs OpenXml .
copy all files including hidden
rsync -avzP source/* source/.* destination
# list all enabled systemd services
systemctl list-unit-files | grep enabled
# edit systemd service, for instance docker:
systemctl edit --full docker.service
# turn off global menu with ALT key with ccsm
# https://askubuntu.com/questions/455519/how-to-stop-alt-from-triggering-global-menu
# update mlocate database
updatedb
locate sites-enabled
history | grep "rsync"
# move, copy multiple files
mv -t DESTINATION file1 file2
cp -t DESTINATION file1 file2
# clear history
history -cw && exit
# mount smb share in files => click other locations and connect to server with format smb://192.168.1.81/var/
# the share is mounted in /run/user/1000/gvfs/smb-share:server=192.168.1.81,share=var/
# curl a script and execute it through a pipe
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
# don't fail script on failing command
#!/bin/bash
docker stop mycontainer || true
# show group memberships of current user
id -nG
# re login as current user
su - ${USER}
# only ask once for passphrase of rsa keys after reboot
# Add this to your ~/.bashrc:
if [ ! -S ~/.ssh/ssh_auth_sock ]; then
eval `ssh-agent`
ln -sf "$SSH_AUTH_SOCK" ~/.ssh/ssh_auth_sock
fi
export SSH_AUTH_SOCK=~/.ssh/ssh_auth_sock
ssh-add -l > /dev/null || ssh-add
# fail2ban unban ip
fail2ban-client set sshd unbanip <my-ip>
# search for apt package containing a file
apt-file update
apt-file search nslookup
# virtual box change uuid of hard disk
VBoxManage internalcommands sethduuid "/home/user/VirtualBox VMs/drupal/drupal.vhd"
# install docker
curl get.docker.com | bash
# grep on multiple keywords
find . | grep -E 'this|that'
# skip permission denied
find . ! -readable -prune -o -print
# replace a character in file, replace é with é in all files that contain é
find . -name '*é*' -execdir bash -c 'cp $1 "${1//é/é}"' _ {} \;
find . -name '*ë*' -execdir bash -c 'cp $1 ${1//ë/ë}' _ {} \;
# show system log since boot
journalctl -b --no-pager | less
# show system log since specific time
journalctl -b --since "2017-04-23 11:00" -no-pager | less
# more journalctl commands https://www.digitalocean.com/community/tutorials/how-to-use-journalctl-to-view-and-manipulate-systemd-logs
# if no more log records are written to for instance /var/log/mail.log, try restarting rsyslog
# list open log files:
ps axu
lsof -p 17970 |grep log
# mastering bash - shortcuts for less, command line, fg, bg, xclip, pushd, popd
https://www.blockloop.io/mastering-bash-and-terminal
# edit crontab of current user
EDITOR="nano" crontab -e
# environment variabelen toevoegen aan /etc/environment
# list TCP connections and open ports with process name
sudo netstat -peanut
# list all autostart services :
service --status-all
# service toevoegen met supervisor:
https://elithrar.github.io/article/running-go-applications-in-the-background/
als supervisor niet start, foutmelding zien met:
supervisord -c /etc/supervisor/supervisord.conf
let op! # als comment werkt niet goed in supervisor.conf file
# met APP_SETTINGS kun je een app setting t
#service supervisor startoevoegen waarmee je naar een config bestand kunt wijzen
update-rc.d supervisor defaults
update-rc.d supervisor enable
#supervisorctl status
#reload of conf.d supervisor scripts
#supervisorctl reread
#supervisorctl update
SHIFT + pageup = scroll omhoog in terminal
history
!<numberofcommandtoexecute>
weer ophalen
curl wttr.in/rotterdam
zoek naar bestanden met extensie (case insensitive) en sorteer op grootte
find / -iname \*.zip -type f -exec ls -sh {} \; | sort -n
zoek naar bestanden en sluit permission denied uit
find / ! -readable -prune -iname myfiles
zoek grote bestanden
find -size +100M
toon foldergroottes
du -sh ./*
ga naar andere shell
exec /bin/sh
when creating a new user, copy /home/root/.bashrc to the new user directory to get the aliases etc from root
# send zipped file to server
cat ./FILE | bzip2 | pv | ssh USER@FQDN 'bunzip2 > /home/USER/FILE'
# upload to server
scp my_local_file user@serveraddress:/file/path/on/server
# an entire folder recursively
scp -pr path/to/my_local_dir user@serveraddress:/file/path/on/server
# with rsync, including zipped data transfer
rsync -zri src USER@SERVER:/home/USER/path
# copy only new files
rsync -hvrPt ./* USER@HOST:/REMOTE/PATH
# copy all hidden files
rsync -avzP ~/.[^.]* /mnt/test
# copy files with excludes
rsync -av --progress /media/lex/Data3/DownloadUbuntuChrome/var/www/comiam-najafabad/wordpress/current/ ./html/ --exclude wp-content/themes/iamreservations --exclude wp-content/themes/maxv2 --exclude wp-content/uploads/
# merge two directories
rsync -ia src/ dest/
# active firewall rules
ufw status
# deny access to ssh
ufw deny from x.x.x.x to any port 22
# allow subnet acces to port
ufw allow from 192.168.1.0/24 to any port 3306
# generate rsa key
ssh-keygen -t rsa -b 4096 -C "[email protected]"
# start ssh-agent
eval "$(ssh-agent -s)"
# add key to rsa agent
ssh-add ~/.ssh/id_rsa
# change password of keypair:
ssh-keygen -p -f ~/.ssh/id_rsa
dir for applications:
/opt/myapp
/usr (is unix system resources)
additions to unix system resources can go to
/usr/local
# repeat last commmand and add sudo
sudo !!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment