Coder Social home page Coder Social logo

cheatsheet.sh's Introduction

A bunch of useful bash commands.

Cheat sheet

Profile with perf.

perf record -g ./a.out
perf report -g graph,0.5,caller

List installed paquets.

dpkg --get-selections > .paquets

Add user to group sudo.

usermod -a -G sudo <user>

find

Larger than 1MB.

find . -type f -size +1M

At most 5 days old (modification time).

find . -type f -newermt '-5 days'

Replace tabs by spaces in a project.

mkdir tmp
find . -name "*.cpp" -type f -exec bash -c 'expand -t 4 "$0" > tmp/expanded && mv tmp/expanded "$0"' {} \;
rm -R tmp

Count lines of sources files in project.

find src -name *.[hc]pp -print0 | xargs -0 wc -l

Find instances of "foo" in a project and print the filename/line numbers.

find src -name *.[hc]pp -exec grep -H -n "foo" {} \;

Replace "foo" by "bar" in a project. Pro tip: sed accepts any delimiter character.

find src -name *.[hc]pp -exec sed -i "s#foo#bar#g" {} \;

Set good default permissions after transfer through non-Unix filesystem.

find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;

Compress PDF files larger than 1MB.

find . -type f -name "*.pdf" -size +1M -exec xz --verbose {} \;

Sum sizes of all PDF files.

# "tr" merges delimiters together.
# The 5th column contains the file size.
# "paste -d+" concatenates lines with a "+" delimiter.
# "bc" calculates the input.
find . -type f -name "*.pdf" -exec ls -l {} \; | tr -s ' ' | cut -d' ' -f 5 | paste -sd+ | bc

git

Squash all git commits.

git reset $(git commit-tree HEAD^{tree} -m "Initial commit")

Diff directories.

git diff --no-index foo/ bar/

Sync with upstream repo.

git remote -v
git remote add <remote-name> <url>
git fetch <remote-name>
git rebase <remote-name>/master
git push
git branch -d fix-***

Create pull request.

git checkout -b fix-***
git commit ...
git push --set-upstream origin fix-***

Fetch branch from contributor.

git remote add <remote-name> <url>
git remote add -t <branch> <remote-name>/<branch>
git checkout <branch>
# Alternatively
git checkout --track <remote-name>/<branch>

Make a local branch track a remote branch.

git branch --track <branch> <remote-name>/<branch>

Prune branches that have been removed remotely.

git fetch --prune

Clone with submodules.

git clone --recurse-submodules https://github.com/USERNAME/REPOSITORY

Sync submodules to fetched version on main repo.

git fetch
git rebase
git submodule status
git submodule update

Add tags.

git tag -a <tag> <commit>
git push --follow-tags

Configuration

Don't save my password thanks.

git config --global --add credential.helper ""

Set editor properly for commit messages.

git config --global core.editor $(which vim)

Manually edit config.

git config --global --edit

Useful aliases (see https://stackoverflow.com/questions/1057564/pretty-git-branch-graphs).

alias.lg=log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all

Setup SSH authentication.

git remote set-url --push origin [email protected]:USERNAME/REPOSITORY.git

apt

Get rid of The following packages have been kept back.

apt-get --with-new-pkgs upgrade

cheatsheet.sh's People

Contributors

gendx avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.