Skip to content

Instantly share code, notes, and snippets.

@VivienGiraud
Last active December 29, 2018 00:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VivienGiraud/64b421d1883674b25942dad39c284984 to your computer and use it in GitHub Desktop.
Save VivienGiraud/64b421d1883674b25942dad39c284984 to your computer and use it in GitHub Desktop.
Useful cmd

OSX

  • Recursively Remove .DS_Store Files on Mac OS X
    find . -name ‘*.DS_Store’ -type f -delete  
  • Generate random mac address and set it
    sudo ifconfig en0 ether $(perl -e 'for ($i=0;$i<5;$i++){@m[$i]=int(rand(256));} printf "02:%X:%X:%X:%X:%X\n",@m;') && sudo ifconfig en0 down && sudo ifconfig en0 up
  • Get list of huge files
    mdfind 'kMDItemFSSize>=1e8&&kMDItemContentTypeTree!=public.directory' | while IFS= read -r l; do stat -f'%z %N' "$l"; done | sort -rn  

AWS  

S3

  • Sync folder with public read right (perfect for a website)
    aws s3 sync . s3://my-bucket/path --acl public-read
  • Get first 200Mb of a file in a S3 buck
    aws s3api get-object --bucket bucket_name --key file_name_from_bucket.csv file_name_to_your_computer.csv --range bytes=0-200000000

EC2

  • Add 1GB of swap
sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
sudo /sbin/mkswap /var/swap.1
sudo chmod 600 /var/swap.1
sudo /sbin/swapon /var/swap.1

cat '/var/swap.1   swap    swap    defaults        0   0' >> /etc/fstab

Aliases

alias tasks='grep --color --exclude-dir={.git,DerivedData,Pods} -rEI "TODO|FIXME" . 2>/dev/null'

alias hdump='hexdump -v -e '\''"%010_ad |" 16/1 "%_p" "|\n"'\'''  

alias my_ip='wget http://ipinfo.io/ip -qO -'  

CLI

  • Removing duplicates (and sorting it) without touching to CSV header
    awk 'NR<1;!seen[$0]++' file  
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment