Feeds:
Posts
Comments

Archive for January, 2017

Sometimes you need to delete a bunch of files that has a limit number of lines. One option is to see one by one and rm it. But you can make you day more agile using the follow commands together 🙂

find <directory> -type f -exec sh -c '[ $(wc -l < "$1") -lt 20 ] && rm -- "$1"' inline {} \;

Let’s explain what it does. <directory> is the folder where the files you want to delete are. I set 20 lines as minimum, just change it using your criteria.

find -type f, says that is a file we are looking for. -exec sh says we want to execute some command for each entry we find using find <dir> -type f. In our case  we exec a sh -c. The -c options says to sh<ell> that we will run a inline code without open a file with shell commands. The follows commands into ” says we want to count the number of line in entry file $1 and if it is less than 20 we’ll delete it. inline and {} \; are just some find command conventions.

References:

[1] http://stackoverflow.com/questions/935251/linux-delete-files-that-dont-contain-specific-number-of-lines

Read Full Post »

To be free, use Sailfish!

Here I’ll show the step by step in ‘How to get away with android’ and play with an amazing thing called SailfishOS :).

Notice: These steps are explained for only Nexus 7, but it’s important to know that for other hardware you just need the correct software which support it.

Step 1: Downloads and settings

Please download every software and save it in a folder

  1. https://dl.twrp.me/grouper/twrp-2.8.7.0-grouper.img . Don’t be afraid, this will provide you with tools for install requested images into your device (Nexus  7).
  2. Install these tools: android-tools-adb android-tools-fastboot . I’m using a Debian/Ubuntu distro, for it was: sudo apt-get install android-tools-adb android-tools-fastboot.
  3. Get cynogemod image compatible with Nexus 7. https://download.cyanogenmod.org/get/jenkins/42501/cm-10.1.3-grouper.zip
  4. Get Sailfish grouper image: http://jolla.toimii.fi/sailfishos/?file=sailfishos-grouper-release-1.0.8.19-alpha1.zip

Step 2: Hands on, adventure time!

Once you have all tools downloaded it’s time to start the adventure and setting images and do the magic.

  1. With your device (Nexus 7) connect through USB cable in your PC. Run
    1. Enable USB debugging option: settings->developer options->USB debugging. See image bellow (I took from another device, but this option it always in the same place)
  2. Now run:
    1. adb devices (it’ll show the number of your device, if everything was right it’ll be there if not, plug your USB cable again and run adb devices.untitled
    2. If ^ previous step was ok, now run: adb reboot bootloader
    3. fastboot devices: it’ll show an output similar to adb devices
    4. fastboot oem unlock: it’ll unlock your device bootloader
    5. fastboot flash recovery twrp-2.8.7.0-grouper.img : will flash the recovery image for future uses.
    6. Reboot and get into in recovery mode. To do this in Nexus 7 we need to hold/press power button and volume down button at the same time.
    7. Select recovery mode in the bootloader screen
      1. First image is the bootloader menu, in order to select recovery mode, image 2, press volume buttons up or down. Once in recovery mode menu press power button to get into in it. Third image shows TWRP recovery image in action.
    8. Once in recovery mode use adb push to copy cynogenmod and sailfish image to /sdcard/. Before execute the commands bellow, run a: adb devices to see if your device is there.
      1. adb push cm-10.1.3-grouper.zip
      2. adb push sailfishos-grouper-release-1.0.8.19-alpha1.zip
    9. It’s strongly recommend that you backup everything in your device if you follow with these steps.
    10.  If everything goes right you will see something like that in Install menuimg_20170103_233541
    11. Ignore the trash I have at my device and pay atetion only in the entries about the images we pushed up. cm-10.1.3-grouper.zip and sailfishos-grouper-release-1.0.8.19-alpha1.zip
    12. Select cm-grouper image and install it.
    13. Select sailfishos image and install it
    14. If everything was ok, just reboot your device and enjoy sailfishos 🙂

[UPDATED]

References:

[1] https://neklaf.wordpress.com/2016/08/11/installing-cyanogenmod-12-1-on-nexus-7-2012-version-a-k-a-grouper/

[2] https://wiki.merproject.org/wiki/Adaptations/libhybris/Install_SailfishOS_for_grouper

[3] https://drive.google.com/open?id=0B8SJVs6mZyogOFBSUmloOFdiVkU

Read Full Post »

The magic of crontab

Sometimes you need to auto things, task, whatever. As an example I have access to a local network but first to get into it I need to reach the external network. What happens is that the PC I access via ssh sometimes changes its IP, since I don’t have any control to put it fixed I  need some how to know what is the current IP it has.

So, why not to use crontab in a new way and update my current IP :).

That’s all about the follow bash script

#!/bin/bash

# Gets my current ip and send it over ssh to the server that is also the entry point
# for local network
IP=`ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1  -d'/'`
ssh -p 4422 user_name@server_ip "echo '$IP' > current_ip"

One thing to remember is to use ssh-copy-id, this way you don’t need to type passwd ok 😀

Now, the magic with crontab can be resumed by:

47 11 * * * bash /path_to_script_above/update_ip.sh

But what does mean those numbers and *?

* * * * * command to be executed
- - - - -
| | | | |
| | | | ----- Day of week (0 - 7) (Sunday=0 or 7)
| | | ------- Month (1 - 12)
| | --------- Day of month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)

Easy right?
In order to add a new crontab just type: crontab -e, choice your favorite editor and add some line :v

Read Full Post »