All Distros

VIM: Undo and Redo

Undo latest changes:


Redo them:





All Distros, Git

Git: two awesome quick commands

Find branches the commit is on

git branch --contains <commit #>

Sample output:

Screen Shot 2017-10-17 at 10.18.41 PM10-17-17
fetch_weather, implement_axios and master all have the commit # 3dea5b6


Show all branches with unmerged commits to <branch>

git branch -a --no-merged <branch>

Sample output:

Screen Shot 2017-10-17 at 10.22.39 PM10-17-17
remotes/origin/error_handler has not yet been merged into master


Happy git work!


All Distros, Git

Git history (log) of a line

This is the first answer of this question on Stack Overflow, about how to see the history of a line of code on git.

Since git 1.8.4, there is a more direct way to answer your question.

Assuming that line 110 is the line saying var identifier = "SOME_IDENTIFIER";, then do this:

git log -L110,110:/lib/client.js

This will return every commit which touched that line of code.

[Git Documentation (see the “-L” command line paramenter)]



Bash, Fedora/RHEL, Packages, Ubuntu

Fast search your project with ag – the silver searcher

“Ag” is a powerful search tool that can come in handy in many situations. Use it to replace your grep searches.

NOTE: some exploration is still to be made, so if you are a pro, share your knowledge with the peasants 😉

Ubuntu 16:
$ sudo apt install silversearcher-ag

Fedora 26:
$ sudo dnf install the_silver_search


$ ag -h


Recursively search for PATTERN in PATH.
 Like grep or ack, but faster.

 ag -i foo /bar/

If you give it a try, let us know


All Distros, Git

Git: find what commit inserted such file

I was in need of finding the commit that added a specific file in my project and “I got lucky” on Google:

Say we need the commit that introduced foo.js in the project, the command would be:

$ git log --diff-filter=A -- foo.js

And a super nice alias would be:

$ git config --global alias.whatadded 'log --diff-filter=A --'

and to use it:

$ git whatadded filename

That’s it.


All Distros, Distros

Nice examples: Find

This link has a super cool  list of find examples for everyday use. In this post, I collected a few that I found more interesting. I left the example number from the list for my (maybe your) reference.

4. Executing Commands on the Files Found by the Find Command.

In the example below, the find command calculates the md5sum of all the files with the name MyCProgram.c (ignoring case). {} is replaced by the current file name.

# find -iname "MyCProgram.c" -exec md5sum {} \;
d41d8cd98f00b204e9800998ecf8427e  ./mycprogram.c
d41d8cd98f00b204e9800998ecf8427e  ./backup/mycprogram.c
d41d8cd98f00b204e9800998ecf8427e  ./backup/MyCProgram.c
d41d8cd98f00b204e9800998ecf8427e  ./MyCProgram.c

9. Finding the Top 5 Big Files

The following command will display the top 5 largest file in the current directory and its subdirectories. This may take a while to execute depending on the total number of files the command it has to process.

# find . -type f -exec ls -s {} \; | sort -n -r | head -5

11. Find files based on file-type using option -type

Find all directories

# find . -type d

Find only the normal files

# find . -type f


12. Find files by comparing with the modification time of other file.

Show files which are modified after the specified file. The following find command displays all the files that are created/modified after ordinary_file.

# ls -lrt
total 0
-rw-r----- 1 root root 0 2009-02-19 20:27 others_can_also_read
----r----- 1 root root 0 2009-02-19 20:27 others_can_only_read
-rw------- 1 root root 0 2009-02-19 20:29 ordinary_file
-rw-r--r-- 1 root root 0 2009-02-19 20:30 everybody_read
-rwxrwxrwx 1 root root 0 2009-02-19 20:31 all_for_all
---------- 1 root root 0 2009-02-19 20:31 no_for_all

# find -newer ordinary_file


All Distros, Bash

Remove all except specific files

This is one way to remove all files but a few of them you want to keep.

First of all, enable bash’s extended globbing features by running:

$ shopt -s extglob

Then you should be able to perform the following commands, for example:

*** Remove all files but a few in a directory ***

$ rm !(file1|file2|fileN)

For directories:

$ rmdir !(file1|fileN)  <-- if dirs are empty, of course


$ rm -rf !(file1|fileN)