Categories
General

Android ADB commands

Android ADB Commands can be a mysterious bunch, but they have saved me from some disasters and made my life easier overall so I figured I would write a small post today and list some useful commands, hopefully you may use in your android endeavors. First you need to have the actual binaries that let you use these commands. you can get minimal adb fastboot tools from this XDA topic (windows), or get the full android studio from here.

adb devicesShows a list of devices currently attached. example :

List of devices attached
FA43KWM04187 device

adb rebootReboots a device currently attached.
adb reboot recoveryReboots a device currently attached into recovery mode. This is usually a very minimal recovery mode for most OEM devices. You can install custom recoveries like TWRP or CWM etc that come with extra features.
adb reboot downloadReboots the connected device into download mode. This is different for most manufacturers. Download mode is for flashing radio firmware/ROM upgrade through official means.
adb reboot bootloaderReboots a device into Bootloader.The bootloader configures the device to an initial known state and has a means to select where to start executing the kernel. Bootloaders are written by hardware vendors and are specialized for the hardware they run on. In Android the bootloader typically starts either android OS itself or a Recovery. Android bootloaders often have a basic interactive mode that can be triggered by holding the “volume down” button while the bootloader is executing.
adb reboot fastbootReboot a connected device into Fastboot mode.
In Android, fastboot is a special diagnostic tool / state that you can boot your Android device into. While in fastboot, you can modify the file system partitions directly. It is an alternative to the recovery mode for doing installations and updates.
adb install camera.apkADB install let’s you install APK files directly to your phone. To use this command type adb install application, as shown in the commands part and hit enter key and it will start installing the app on your phone. e.g
adb install C:/Users/sumguy/camera.apk.
If process succeeds it will show you “Success” in the command window. If you have already installed an app, and you just want to update it then you need to add the -r switch
adb install -r C:/Users/sumguy/camera.apk
adb uninstallUninstalls and application from your device. The easiest way to find a package name is, install Package Name Viewer from the play store and find the name of the package under the App Name. If process succeeds it will show you “Success” in the command window.
adb uninstall com.android.Camera
adb uninstall -K com.android.CameraUninstall an app but keeps it’s data and cache directories. If process succeeds it will show you “Success” in the command window.
adb pushthe adb push commands let’s you transfer any files to your phone from your PC. You simply need to provide the path of file on your PC and path where to place this file on your phone.
adb push file/path/on/connected/comp \path\on\phone
adb pullSimilar to the adb push command. Using adb pull, you can simply pull any files from your phone.
adb pull \path\on\phone file/path/on/connected/comp
adb shellstarts the background terminal.

that’s all the Android ADB Commands i can think of. Am I missing something? let me know in the comments!

Categories
General

Remove spaces from file names via bash

if you need a simple way to remove spaces from file names and replace with an underscore or a hyphen or whatever else here is a bash one liner. You can also do this via python or perl or most likely via php (why? o.0) but since bash / zsh is here and readily available for me I choose to use bash / zsh.

Remove spaces and replace with underscore:

find /tmp/ -depth -name "* *" -execdir rename 's/ /_/g' "{}" \;

remove spaces and replace with hyphen :

find /tmp/ -depth -name "* *" -execdir rename 's/ /-/g' "{}" \;

Remove spaces completely:

find /tmp/ -depth -name "* *" -execdir rename 's/ //g' "{}" \;

Be careful with he above as it will remove all spaces from file and directory names.

hope this helps. if you have a better way of doing it comment and let me know 🙂

Categories
Linux shell tuts

Find out whats taking up all the hdd space

[et_pb_section admin_label=”Section” fullwidth=”on” specialty=”off”][et_pb_fullwidth_post_title admin_label=”Fullwidth Post Title” title=”on” meta=”on” author=”off” date=”on” categories=”on” comments=”off” featured_image=”on” featured_placement=”background” parallax_effect=”off” parallax_method=”on” text_orientation=”center” text_color=”dark” text_background=”on” text_bg_color=”rgba(255,255,255,0.9)” module_bg_color=”rgba(255,255,255,0)” title_all_caps=”off” use_border_color=”off” border_color=”#ffffff” border_style=”solid”]

[/et_pb_fullwidth_post_title][/et_pb_section][et_pb_section admin_label=”section”][et_pb_row admin_label=”row”][et_pb_column type=”4_4″][et_pb_text admin_label=”Text” background_layout=”light” text_orientation=”left” use_border_color=”off” border_color=”#ffffff” border_style=”solid”]

Running out of hdd space is pretty annoying. So if you are running out of space and need to find out whats taking up all that space type the following command to find out more :

du -h  |grep '[0-9]G'

 

[/et_pb_text][/et_pb_column][/et_pb_row][et_pb_row admin_label=”row”][et_pb_column type=”4_4″][et_pb_text admin_label=”bottom above footer” background_layout=”light” text_orientation=”left” use_border_color=”off” border_color=”#ffffff” border_style=”solid”]

[/et_pb_text][et_pb_divider admin_label=”Divider” color=”#ffffff” show_divider=”off” divider_style=”solid” divider_position=”top” hide_on_mobile=”on”]

[/et_pb_divider][et_pb_text admin_label=”Text” background_layout=”light” text_orientation=”left” use_border_color=”off” border_color=”#ffffff” border_style=”solid”]

[/et_pb_text][/et_pb_column][/et_pb_row][/et_pb_section]

Categories
Linux shell

Start Xvfb on boot on Centos Linux

XVFB

Xvfb or X virtual framebuffer

X virtual framebuffer is a display server using the X11 protocol. In contrast to other display servers, it performs all graphical operations in memory without showing any screen output. which makes it ideal for some surprising uses. e.g.

Xvfb :1 &
xv -display :1 &
import -display :1 -window root image.png

(above snippet via Wikipedia)

I had to run xvfb automatically on boot on a centos system, here’s the init script I used to carry out the task. add the following as a script to /etc/init.d , chmod +x the script then chkconfig xvfb on

* Note: see the :11 in the middle of the script? change that to another number to change the display port.

   #!/bin/bash
   # chkconfig: 345 95 50
   # description: Starts xvfb on display 11
   # why 11? dunno I just work here. :( -FB
   # 9/30/13 r1 - initial addition -FB

   if [ -z "$1" ]; then
   echo "`basename $0` {start|stop}"
       exit
   fi

   case "$1" in
   start)
       /usr/bin/Xvfb :11 &
   ;;

   stop)
       killall Xvfb
   ;;
   esac

[/et_pb_text][/et_pb_column][/et_pb_row][et_pb_row admin_label=”row”][et_pb_column type=”4_4″][et_pb_text admin_label=”bottom above footer” background_layout=”light” text_orientation=”left” use_border_color=”off” border_color=”#ffffff” border_style=”solid”]

[/et_pb_text][et_pb_divider admin_label=”Divider” color=”#ffffff” show_divider=”off” divider_style=”solid” divider_position=”top” hide_on_mobile=”on”] [/et_pb_divider][et_pb_text admin_label=”Text” background_layout=”light” text_orientation=”left” use_border_color=”off” border_color=”#ffffff” border_style=”solid”]

[/et_pb_text][/et_pb_column][/et_pb_row][/et_pb_section]

Categories
Linux shell

Bash for loops sequential counting

 

Bash for loops are very useful in everyday life. I am going to post some simple examples where I combine bash for loops with other simple techniques like bash stepping etc.

Want to count from 1 – 100 and list each number sequentially?

for i in {1..100}; do   echo $i; done

Same as above but add a timestamp?

for i in {1..100}; do   echo $(date +"%D %I:%M:%S") - $i; done

Again same as above but now we step every 3 numbers instead of every 1

for i in {1..3..100}; do   echo $(date +"%D %I:%M:%S") - $i; done

 

now for something slightly harder, we add each successful result to the next number after it.

for i in {1..100}; do s=$((s+i)); done; echo $(date +"%D %I:%M:%S") - Total - $s

How about if we echo every resultant number before the total?

for i in {1..100}; do s=$((s+i)); echo $(date +"%D %I:%M:%S") - $s; done; echo $(date +"%D %I:%M:%S") - Total - $s

 

Categories
Linux

dpkg-divert local redirection of bins in Ubuntu

[et_pb_section admin_label=”Section” fullwidth=”on” specialty=”off”][et_pb_fullwidth_post_title admin_label=”Fullwidth Post Title” title=”on” meta=”on” author=”off” date=”on” categories=”on” comments=”off” featured_image=”on” featured_placement=”background” parallax_effect=”off” parallax_method=”on” text_orientation=”center” text_color=”dark” text_background=”on” text_bg_color=”rgba(255,255,255,0.9)” module_bg_color=”rgba(255,255,255,0)” title_all_caps=”off” use_border_color=”off” border_color=”#ffffff” border_style=”solid”]

[/et_pb_fullwidth_post_title][/et_pb_section][et_pb_section admin_label=”section”][et_pb_row admin_label=”row”][et_pb_column type=”4_4″][et_pb_text admin_label=”Text” background_layout=”light” text_orientation=”left” use_border_color=”off” border_color=”#ffffff” border_style=”solid”]

It seems sometimes you get a new package from somewhere and its just an update for an older package but from a different author, or a slightly different functioning bin. The dpkg-divert command allows you to replace a binary installed upon the system, and have this replacement persist even if you upgrade packages. One common reason to do this is if you’re using a mailserver such as qmail, and you wish to replace the file /usr/lib/sendmail with the version from that package. In this case making a diversion is a good solution. Well you can locally divert how you refer to the bin and make dpkg aware of this via the following command :

dpkg-divert --local --divert /usr/bin/sumguy --rename --add /usr/bin/sumguy-longer-name-newer-package

In this case our package provides sumguy-longer-name-newer-package  as the binary and hence the command, but thats a LOT to type 🙁 we just want to call it by its simpler name of
so we use the above divert command and voila! we are good to go.