Friday, February 20, 2015

Delete files older than certain period of time in UNIX

It is often required to delete old unnecessary archived files when administrating a UNIX system. So to make this work easier I have written the following command:

find /directory/path  -type f -mtime +1  -print | xargs -I {} rm {}

By executing this command, all files in the specified folder that are older than a day i.e. 24 hours will be deleted

If you want to specify the time in minutes do this

find /directory/path  -type f -mmin +360  -print | xargs -I {} rm {}

Specify your time instead of 360.

You could also write a shell script and schedule it in crontab to run it any time you want to.

CAUTION: slightest error could cause the loss of invaluable data. So do it at your own risk.

Monday, February 16, 2015

File systems usage in UNIX

It is hard to parse the output of the df unix command with the human eye. So I have written a simple solution for it. The following command will fetch you the list of filesystem whose usage is greater than eighty percent in descending order.
df -g | awk '{print $4 "\t" $7}' | sort -nrk 1 | egrep "([89][0-9]|100)%"
Output will be like this:
85% /filesystem1
82% /filesystem2
82% /filesystem3
81% /filesystem4

You can remove the final egrep to view all the file systems. Like this:
df -g | awk '{print $4 "\t" $7}' | sort -nrk 1
Feel free to comment below!

Unlocking user account in AIX

When you have a locked user account but still have root access and the old password you can unlock it by entering the following two commands:
chsec -f /etc/security/lastlog -a "unsuccessful_login_count=0" -s username 
chuser "account_locked=false" username
The first command sets the unsuccessful login count back to zero and the second command unlocks the account. The user can use his account without resetting his/her account.
Obviously the second command by itself wouldn't unlock the account so you would have to enter both the commands.

If you do not have the old password then do this in root:
echo username:password | chpasswd -e
If you feel insecure about giving your password like this then you can give your password in encrypted for :
perl -e'print crypt("password","salt")'; echo -e
echo username:cryptedPass | chpasswd -e
Please feel free to share your comments below

Friday, February 13, 2015

Guide to root your Moto G! Step 3 of 3

This is a important step. You have rooted your device and you have full access to your Moto G! So does your apps. Grant permission to only those apps that you feel right about or atleast Google them before granting full access. Granting root access to malicious apps puts you in danger so think twice before doing it.

Now That we have rooted your Moto G. We can do whatever we decide to do. However, There are three options..

Option 1: Install Xposed Framework

Xposed is a really awesome framework but it is only for stock roms. We can get access to most options and stuff you get by installing a rom. This is for those who feel stock rom is enough!

A few apps come to mind. You can install Greenify, LMT Launcher.

Option 2: Install a ROM

You can really enter into the world of Android and swim in its awesomeness by venturing into the the ROM arena. You have lots of options lots of customizing optiona and a ton of ROMs!
You can start by looking this XDA thread:
XDA Moto G ROMs and Kernels Index

You could also install a custom Kernel if you know what your doing.

I have tested a lot of ROMs. Only few have made a significant impact:
Xperience ROM
Cyanogenmod 11

Xperience rom with Lollipop 5.02 is currently my daily driver right now. If you find a better one say it in the comment below!

Option 3:Unroot

Rooting isn't for everyone. and might feel happier if their device is unrooted and locked.
Unrooting and locking the bootloader is also fun. Expect a Guide to unroot your Moto G in the Future!

I am open to your reviews and your experience doing this Guide. Please share your comments below!!

Guide to root your Moto G! Step 2 of 3

Proceeding with the guide...

Unlocking the boot loader

Power off the Android device.
Now press the power button and the volume down simultaneously for a few seconds
The fastboot screen comes on the phone.
Be careful on what you are doing here. Do nothing for now.
Connect your Moto G to your windows PC/ laptop using the USB cable.
And follow the clearcut instructions given to you by Motorola on unlocking the boot loader from here:
Motorola Unlocking the Bootloader

Your device is now unlocked. There will be a "Bootloader Unlocked" message at the time you power on the device. like this you can ignore it


Now that you have unlocked it we are moving on to the next step.

Flashing the Custom Recovery
#include <std_disclaimer.h>
/*
* Your warranty is now void.
*
* I am not responsible for bricked devices, dead SD cards,
* thermonuclear war, or you getting fired because the alarm app failed. Please
* do some research if you have any concerns about this Guide
* before doing it! YOU are choosing to make these modifications, and if
* you point the finger at me for messing up your device, I will laugh at you.*/
We need to flash the recovery.img that we have previously downloaded.

Before doing please see to that the USB debugging option is enabled in the Developer options Settings. If not enable it.

Power off the Android device.

Now press the power button and the volume down button simultaneously to get into the bootloader.


It must say that your device is unlocked with status code 3.

Connect your device to your computer using the USB cable. In your phone it will say USB connected.

Now that it is connected open up a command prompt in the folder where you have downloaded the recovery image by right clicking while pressing the shift key.
fastboot devices
The above command will list your device. proceed to the next step.

Please rename the downloaded philz recovery image file as recovery.img. Now Enter this command:
fastboot flash recovery recovery.img
It might say partition size mismatch but its ok. Enter the next command.
fastboot reboot
It wil boot normally. Now place the SuperSu.zip file into your device by connecting with computer using USB cable. Place it any folder but remember the path.

Power off the Moto G and boot into the bootloader by pressing the power button and the volume down button simultaneously.
Select the recovery option by pressing the volume down button once and pressing the volume up button

Choose "Install Zip". Then select "Choose zip from /sdcard". Now select the folder in which the SuperSu.zip is present. And select the zip file. Select yes install zip and it will install the zip. When it finishes touch once anywhere and then select "Go Back". then select "Reboot System now".

And you are done!! Your Moto G is now rooted!

Next step is the important step proceed.
Next Step:Step 3 - What to do now?

Guide to root your Moto G! Step 1 of 3

When I rooted my Moto G, It was very hard to find a simpler good tutorial than this. So I am posting here the simple way to do it. I am doing this using a windows laptop.

Windows PC/LAPTOP instructions:
Download the Motorola Device Drivers from here:
Motorola Device Drivers
Install the 15 second ADB Fastboot installer downloading from here:
Follow the instructions properly.
ADB is necessary for backup and restore of data from your phone.
Fastboot is necessary to unlock your boot loader and for flashing the recovery.
Download these too:
latest version of philz recovery and SuperSu from here:

Philz Recovery (download the .img file and rename it to recovery.img after downloading)
SuperSU

Now that the windows is ready, moving onto the Next steps:

Firmware Download:
Not always does rooting your android or flashing a rom go according to plan. You may want to even want to device software to unroot your device. So it is necessary to always have your device's firmware when you do these stuff.
You can download these from here:
Filefactory Folder

for XT1033 you can find firmwares in the following XDA thread
XDA XT1033 firmwares

choose your firmware that fit your device. XT1033 firmware may not work for xt1032 and vice verse so choose the proper firmware. Firmware are While the firmware image is downloading proceed to the next step.

Taking Backup:
It is always good to have a backup. As we are about to unlock the boot loader, all the data on your phone will be wiped and be set back to factory settings.
If you do not want the current data, you can skip to the next step.
Do the following steps to take a backup:

1. Enable USB debugging under developer options in settings.
If you have done this already proceed to Step 2.
If you don't see the developer options in your settings then you have not yet unlocked it yet.
1a.To unlock it go to the About phone in settings and tap the build number 7 times.
It would display you are now a developer.
1b. Then go back and you will now see a developer options entry. Now do the aforementioned first step.

2. Connect your Moto G to your windows PC/ laptop. In notifications it will show "USB debugging connected"

3. Create a new folder on your desktop. Go into the folder and right click while pressing the shift key inside the folder. Choose the 'open command prompt here' . this fires up the command prompt in the current folder.

4. In the command prompt enter this command to check whether your device is connected or not.
adb devices
This will display whether a device is connected or not. Also in your device give access in the prompt that pops up.

5. Now that the device is connected, we can proceed with the backup. Enter the following command
adb backup -apk -shared -all
This prompts a encryption pin for the backup on your phone. It is recommended to enter a PIN and proceed. Although you can proceed without giving a PIN at all.
Please remember or note down the PIN because you will have to enter it again to restore the backup!
This would make a complete backup of your phone with all apps apks and data. It doesn't take a backup of your SMS messages and media. So copy all media from phone to computer through mass storage. Use the SMS backup and restore app to take backup of SMS messages.
This step could take about an hour depending the amount of data you have on your phone.
You will know the backup has ended when command prompt is ready to accept new commands.

Now that you have taken your backup. We can move to the next step to unlock your bootloader and flashing recovery.

Next Step: Step 2 - Unlocking Bootloader And flashing custom recovery