Add a new line at the end of each text files tracked by git

One of the most anoying thing I meet when I am coding software, is the « No new line at end of file » warning.

For this, I have written a little script based of my research on google. I want to rewrite all text files tracked by git and ensure that a new line is written at the end of file.


# list all files tracked by git
for file in `git ls-files -c -m`;
  # Test that file does exist
  if [ -f $file ]; then
    # Test that file is not a binary one
    grep -Iq . "$file"
    if [ $? -eq 0 ]; then
      # Add a new line
      sed -i '$a\' $file

You can execute it from a git repository and commit the result.

How to use diff in svn folder

The diff program is used to find differences between files. To know more about diff :

But, if we use diff in svn folder, it can find a difference between files inside .svn. Here is the line of code I’m using :
cd /where/is/my/svn/folder
diff -r -x .svn /folder/source /folder/dest > file

With these parameters, diff doesn’t look into .svn folder.

Temperature Information in Ubuntu Linux

One day I had some troubles with my computer. Sometimes it crashes both spontaneously and sporadically. I thought it was because the CPU’s temperature was to hight. So here is a command line to know more about the CPU’s temperature on linux (I’m using Ubuntu 9.10)

cat /proc/acpi/thermal_zone/*/*

But this line shows me that the temperature of my CPU was completely normal. I think that my computer has some power problems, but impossible to discover the cause of crashes. Fortunately, it seems to work now…

System pause in linux script

Sometimes, you need to make a pause in your Linux script. For instance, you want to see the result of your script when you’re executing it from the window system. In my case, when I want to open an executable script file from gnome, it asks me if I want to open it in a new bash. If I say yes, it executes it and close the window. I don’t have the time to see any output, so I’m writing this at the end :
read a

The system wait for a keyboard input. The input is finish after pressing the « enter » key. Pressing it, the window closes itself (when executing from the window system)

Unix command to delete .svn folders

I have found on the web a useful command to delete .svn folders in your local svn repository. I found it here.

The command line is as follow :

find ./ -name .svn -exec rm -rf {} \;

The command find will search in the ./ directory each element whose -name is .svn. Don’t forget to go into your svn directory with the cd command. After each successful research, the -exec command will execute rm -rf with the path found by find put into the {} brackets. The result is that each .svn folder found is deleted.