Friday, February 26, 2016

Change resolution and other display settings - Fedora



arandr - GUI app to setup resolution, quite useful for multi monitor settings.

install like # yum install arandr.noarch -y


Tuesday, February 16, 2016

git show commit

// show the first two patches in git branch
git show HEAD -2


// show the top one
git show HEAD
equivalent to
git show HEAD -1

Friday, February 12, 2016

interrupt sleep in a bash script


For testing you have added sleep command in a script.

Now, you want to interrupt the sleep and continue to next statement.

How do you do it?

 Method 1:
If sleep is only done in your script alone, you can do this:
pkill sleep
 
Method 2: (need changes in script) 

--------------------- // this is your script
# write the current session's PID to file
echo $$ >> myscript.pid

# go to sleep for a long time
sleep 1000

---------------------
# pkill -P $(<myscript.pid) sleep 


Ref:
http://askubuntu.com/questions/575704/how-can-i-wake-a-sleeping-bash-script

Sunday, February 7, 2016

syntastic vim plugin



Quite useful that it checks syntax while editing the file.

I can see it in action for both Python and C.


Refer below:
https://github.com/scrooloose/syntastic


Thursday, February 4, 2016

filesystem type of a file



So, you have a file and want to know filesystem it is mounted on
do this:

df -T /path/to/the/file 

# df -T ~/test.c
Filesystem                      Type 1K-blocks    Used Available Use% Mounted on
/dev/mapper/fedora--server-root ext4  27187420 3801608  21981704  15% /



Monday, February 1, 2016

renaming (existing) hardlinks



Lets say,  We have two files testfile123 and testfile456
#touch testfile123
#touch testfile456

#unalias mv
#mv testfile123 testfile456

strace shows this:
access("testfile456", W_OK)             = 0
rename("testfile123", "testfile456")    = 0
------------------------------
Lets say, we have two hard links

#touch testfile
#ln testfile testfile_hlink1
#ln testfile testfile_hlink2

#mv testfile_hlink1 testfile_hlink2

access("test_hlink1", W_OK)             = 0
unlink("test_hlink2")                   = 0
---------------------------------
So, in case of hardlink, rename system call itself is not called at all (as it is the same file and moving contents from one hardlink to another does not make sense).

man 2 rename :
       If  oldpath  and  newpath are existing hard links referring to the same
       file, then rename() does nothing, and returns a success status.

Thanks to Aravinda  for pointing me this.