Skip to content

Instantly share code, notes, and snippets.

@radum
Last active February 14, 2018 20:22
Show Gist options
  • Select an option

  • Save radum/116ab9a72e21333e9ceb5515565ee13a to your computer and use it in GitHub Desktop.

Select an option

Save radum/116ab9a72e21333e9ceb5515565ee13a to your computer and use it in GitHub Desktop.
Useful CLI stuff
# Windows copy with permissions
# https://www.maketecheasier.com/12-things-you-must-do-when-running-a-solid-state-drive-in-windows-7/
Robocopy.exe H:\Internet M:\Internet /MIR /copyall /dcopy:T /W:30
# Change how many max files the system can use
# https://superuser.com/questions/827984/open-files-limit-does-not-work-as-before-in-osx-yosemite
# https://blogs.progarya.dk/blog/how-to-persist-ulimit-settings-in-osx/
sudo sysctl -w kern.maxfiles=65000
sysctl kern.maxfiles
# Mac get rid of the error about app is not safe
xattr -cr {path to file}
# Find all folder with X name and copy and rename it
find . -type d -name '*dacia_v2*' | while read f; do cp -R "$f" "${f/dacia_v2/dacia_v3}"; done
# Docker pull all images
docker images |grep -v REPOSITORY|awk '{print $1}'|xargs -L1 docker pull
# Docker remove all dangling images
docker system prune
# Show the history of a file in git
gitk [filename and path]
# or to follow filename past renames
gitk --follow [filename]
# This will show the entire history of the file (including history beyond renames and with diffs for each change).
git log --follow -p -- [filenam and path]
# Search all ".js" files for "debounce"
# Spits out file path, line number, and snippet where string appears
find . -name "*.[js]" -exec grep -in -H "debounce" {} \;
# Replace all leading spaces with tabs
find . -name "*.scss" | while read line; do expand -t 4 $line > $line.new; mv $line.new $line; done
# Add EFO new line to all files
find . -name "*.scss" -exec sed -i '' -e '$a\' {} \;
# Check which files were modified by a command
# Where <command> is what you want to execute.
D="$(date "+%F %T.%N")"; sleep 0.5; <command>; find . -newermt "$D"
# How to Search and Replace a String in All the File Names?
for file in `ls *oldname*`; do mv $file $(echo $file| sed -e "s/oldname/newname/g"); done
# Copy all dacia folders with contents in a new folder and rename to dacia2
find . -type d -name 'dacia' -exec ditto -v -V {} ../tmp/{}2 \;
# How to List Brew Dependencies
brew list | while read cask; do echo -n $fg[blue] $cask $fg[white]; brew deps $cask | awk '{printf(" %s ", $0)}'; echo ""; done
# Efficient Image Resizing With ImageMagick
# smartresize inputfile.png 300 outputdir/
# https://www.smashingmagazine.com/2015/06/efficient-image-resizing-with-imagemagick/
smartresize() {
mogrify -path $3 -filter Triangle -define filter:support=2 -thumbnail $2 -unsharp 0.25x0.08+8.3+0.045 -dither None -posterize 136 -quality 82 -define jpeg:fancy-upsampling=off -define png:compression-filter=5 -define png:compression-level=9 -define png:compression-strategy=1 -define png:exclude-chunk=all -interlace none -colorspace sRGB $1
}
# --------------------------------------------------
# RVM clean house
# Do not be surprised if one day you'll see something like this:
# $ du -hs ~/.rvm
# 1.2G /home/vagrant/.rvm
# To solve the problem run rvm cleanup all. It will remove stale source folders / archives and other miscellaneous data associated with rvm.
rvm cleanup all
# To cleanup outdated gems run rvm gemset empty [gemset]. It will remove all the gems, so you will need to run bundle install after that.
rvm gemset list
rvm gemset empty default
# Run rvm gemset globalcache enable. It will enable global gem cachedir, which will be used to store gems (we do not want to store the same gem for each Ruby version, obviously)
rvm gemset globalcache enable
# --------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment