Featured

About this blog

tuxThis blog was created with the idea of collecting and linking information about Linux, Git, how to set things up, how to tweak the system here and there, in different architectures, in different distributions and different releases.

All the information presented here is available to public knowledge and can be found with one, two, or a few more Google searches if you persist. All of them were used at least once on productive activities.

Please share your experience and share your comments.

Advertisements

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)]

 

Cheers!

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

Usage:

$ ag -h

Usage: ag [FILE-TYPE] [OPTIONS] PATTERN [PATH]

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

Example:
 ag -i foo /bar/

If you give it a try, let us know

Cheers!

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.

Reference: https://stackoverflow.com/questions/11533199/find-commit-where-file-was-added

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
.
./everybody_read
./all_for_all
./no_for_all

Reference: http://www.thegeekstuff.com/2009/03/15-practical-linux-find-command-examples/

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

or

$ rm -rf !(file1|fileN)

Examples:

rm_but_a_few

 

Solve VirtualBox Guest Additions Autorun issue on Fedora 26 and Debian 9

Install VirtualBox Guest Additions on Fedora 26

NOTE: If your user does not have root rights, add it to the root group (probably ‘wheel’).

$ dnf update kernel*

$ sudo reboot

After it boots up again, the guest additions should be up and running, and you should be able to see your desktop on full screen.

Install VirtualBox Guest Additions on Debian Stretch (9)

Insert the VBoxGuestAdditions CD image from the ‘Devices’ menu. (I had a lot of mount issues with this). It should automatically mount and automatically run.

If it does not autorun, you have to manually run the VBoxLinuxAdditions.run script. First solve any root permissions you may have (adding $USER to the visudo file should solve it: insert a line right after ‘root’ with your user name). Then go to /media/cdrom0 or wherever your VBoxGuestAddition.iso is mounted and issue:

# bash VBoxLinuxAdditions.run

It should run seamlessly if everything is OK.

You are welcome to share your comments.

Cheers

Hide .gitignore files in Atom Tree view

I have been using Atom as my coding editor for almost a year now. As a Python developer, the *.pyc files often bugged me whenever I ran my code.

Adding those files in the .gitgnore file did not prevent them to show up in the tree view and hiding them from the Atom menus was not as much intuitive as I would guess at first, so I had to dig a little further.

To hide all files included in the .gitignore file:

atom_hide_3
Image1: find the ‘tree-view’ package and press Settings to enter the preferences of the package.
atom_hide_1
Image2: Scroll down to see the preference options.
atom_hide_2
Image3: Check the “Hide VCS ignored files” checkbox.

You may now see your tree view free of unwanted files.

I hope it helps.

Cheers!