[Linux command] Empty all files in a folder

This command in one line allows to empty all the files (readable of cours) in a folder


find . -type f -exec sh -c '>{}' \;



[Git] Git diff without comparaison file mode

Issue when execute git diff command on a file and got :

diff --git a/your_file b/your_file
old mode 100644
new mode 100755

If you see this, it is because the permissions of your_file has changed.
For information, the unix file permission mode(644=rw_r__r__ which means read and write for user, only read for group and only read for others, the same for 755=rwxrw_rw_, x for executable).

To disable the comparaison of file mode, the command to execute :

git config core.filemode false

[Linux command] Tar – Extract only the contents of an archived directory


As said the subject, we want to extract only the contents of a tar file to a specific folder.

I have my tar : myTarFolder.tar, my destination folder : destFolder

The structure of my tar file :

Image 10

If we use only the tar command, we will get :

tar -xf myTarFolder.tar -C destFolder 

Image 11

If we want to get something like this :

The option that we have to use is :

  1. –strip-components=NUMBER : strip NUMBER leading components from file names on extraction

An example of the command :

tar -xf myTarFolder.tar --strip-components=1 -C destFolder

The result :

Image 12

[ubuntu] WARNING gnome-keyring in lubuntu

If you have met the same problem, this maybe help.

Background :

I installed phpunit in my ubuntu 12.04(the os is lubuntu), the installation passed quite well, but when I launch the command in termianl, I got always this warning :

$ phpunit --version
WARNING: gnome-keyring:: couldn't connect to: /tmp/keyring-xAGrk8/pkcs11: No such file or directory
PHPUnit 4.4.5 by Sebastian Bergmann.

Continue reading

[Linux Commands] show file/directory/partition size

# show the partitions sizes 
# (Filesystem, Size, Used, Avail, Use%, Mounted on)
df -h

# show directory size
du -s -h /your_dir_name/

# show file size
du -s -h your_file_name

Tips :

  • -h is for humain, that you could easily understand the size in
    kilobyte, megabyte or gigabyte
  • -s is for summary, instead of listing all files, it will display
    only the total.
  • [LINUX] ls Command: Sort Files

    Linux commands are marvellous !

    We can use LS to sort files by name, by size or others methods that you could imagine.

    For example,

    Suppose you have a list of files in a folder :

    – cuibo1
    – 1111
    – 2222
    – 3333
    – cuibo2
    – cuibo333

    And you want all the files in order which begins with cuibo, what you can do is : ls -h | grep “cuibo”

    C’est tout !

    Here is a blog which talks about sort files by size : http://www.cyberciti.biz/faq/linux-ls-command-sort-by-file-size/