Skip to content

Instantly share code, notes, and snippets.

@logicalgroove
Last active September 2, 2020 15:19
Show Gist options
  • Save logicalgroove/9376847 to your computer and use it in GitHub Desktop.
Save logicalgroove/9376847 to your computer and use it in GitHub Desktop.
Useful commands

Vim

Remove ^M

%s/\r//g

Remove unwanted whitespaces

:%s/\s\+$//

Aligning text (using Tabular.vim)

:%sTab /,\zs

Replace tabs with spaces

:retab

Copy/paste vim text through screen windows

^a > esc > space > select text > esc
^a > ]

Bash

Search and replace text

find /path/to/start/from/ -type f | xargs perl -pi -e 's/expression1/expression2/g'

Remove matching lines

find /path/to/start/from -type f -exec sed -i '/expression/d' {} \;

Find and open 3 to 7 search results files in vim

vim -o `find ./app/views/ -name expression | sed -n '3,7p'`

Find files and open them in vim

vim -o `grep -ril expression .`

Exclude files from search by file type

grep -rn word --exclude=\*.{log,swp} folder

Zip folder

zip -r compressed_filename.zip foldername

Recursively change permissions of files to 644

sudo find /path/to/someDirectory -type f -print0 | xargs -0 sudo chmod 644 - 

Recursively change permissions of folders to 755

sudo find /path/to/someDirectory -type d -print0 | xargs -0 sudo chmod 755 - 

Find all folders, including subdirectories

find /mount/point -type d | wc -l

Find all folders, not including subdirectories.

find /mount/point -maxdepth 1 -type d | wc -l

AWS

Move files in s3

aws s3 mv s3://springbig-papertrail/ s3://springbig-papertrail/papertrail/logs/dt=2019-06-14/ --recursive --exclude "*" --include "2019-06-14-*"

GIT

Remove a commit in between

4466 commit - is the commit that needs to be deleted

- switch into that branch
- squash the commits after 4466 commit (interactive rebase)
- create a new branch "repair"
- switch to that branch
- git reset --hard to the commit before 4466 commit
- git cherry-pick the commit that you squashed after 4466 commit in the original branch
- git commit
- checkout to the original branch
- git reset --hard to the commit before 4466 commit
- git merge "repair"

Order branches by last commit date (human readable date):

git for-each-ref --sort='-authordate:iso8601' --format=' %(authordate:relative)%09%(refname:short)' refs/heads
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment