Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Monday, May 22, 2017

Get USB devices' vendor ID and product ID on Linux, using lsusb command

To get the vendor ID/product ID of attached USB devices in Linux, you can use the command lsusb.

This video show how to, tested on Ubuntu 17.05 over Windows 10/Oracle VirtualBox 5.1




reference: Ubuntu Manual - lsusb



Tuesday, March 31, 2015

Run Linux command on Android

Android system have to Terminal application in default. This example provide user to run Linux command using ProcessBuilder, and display the result. But most Linux command not support in Android.

(If you want try the APK only, scroll down to the bottom.)


package com.example.androidrunlinuxcmd;

import java.io.IOException;
import java.io.InputStream;

import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;


public class MainActivity extends ActionBarActivity {
 
 EditText cmdBox;
 Button btnRun;
 TextView textResult;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        cmdBox = (EditText)findViewById(R.id.cmdbox);
     btnRun = (Button)findViewById(R.id.run);
     textResult = (TextView)findViewById(R.id.result);
     textResult.setTypeface(Typeface.MONOSPACE);
        
  btnRun.setOnClickListener(new OnClickListener(){

   @Override
   public void onClick(View v) {
    //Split String from EditText to String Array
    String[] cmd = cmdBox.getText().toString().split("\\s+"); 
    try {
     String cmdResult = runLinuxCmd(cmd);
     textResult.setTextColor(Color.WHITE);
     textResult.setText(cmdResult);
    } catch (IOException e) {
     e.printStackTrace();
     textResult.setTextColor(Color.RED);
     textResult.setText("Something Wrong!\n"
      + e.getMessage());
    }
   }});
    }

    //Run a Linux command and return result
 private String runLinuxCmd(String[] command) throws IOException {

    StringBuilder cmdReturn = new StringBuilder();

    ProcessBuilder processBuilder = new ProcessBuilder(command);
     Process process = processBuilder.start();

     InputStream inputStream = process.getInputStream();
     int c;

     while ((c = inputStream.read()) != -1) {
      cmdReturn.append((char) c);
     }

     return cmdReturn.toString();
   }
}


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:orientation="vertical"
    tools:context="com.example.androidrunlinuxcmd.MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:autoLink="web"
        android:text="http://android-er.blogspot.com/"
        android:textStyle="bold" />

    <EditText
        android:id="@+id/cmdbox"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:singleLine="true" />

    <Button
        android:id="@+id/run"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Run Linux Command" />

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#A0A0A0" >

        <TextView
            android:id="@+id/result"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="10dp" />
    </ScrollView>

</LinearLayout>


download filesDownload the files.

Download and Try the APK.

Friday, January 23, 2015

Setup JAVA_HOME and path to JDK on Linux


Setup JAVA_HOME and path to JDK on Linux (Ubuntu in this example), edit the file .bashrc
$ nano .bashrc

Add the line:
export JAVA_HOME=<path to jdk>
export PATH=$JAVA_HOME/bin:$PATH

Where <path to jdk> is the path to the installed JDK.


Save it and exit.

To reload .bashrc without log-out and log-in, enter the command:
$ source ~/.bashrc


Friday, August 15, 2014

Install VirtualBox 4.3 on Ubuntu 14.04 from repository source

This post show how to install VirtualBox 4.3 on Ubuntu 14.04, from repository.




The list of repository sources can be found at https://www.virtualbox.org/wiki/Linux_Downloads. For 14.04 ("Trusty Tahr"), it is "deb http://download.virtualbox.org/virtualbox/debian trusty contrib".



Run the command to add apt repository to your sources list:
$ sudo add-apt-repository "deb http://download.virtualbox.org/virtualbox/debian trusty contrib"

Before update apt source list, you have to add Oracle public key. Download the Oracle public key for apt-secure (oracle_vbox.asc) from the same page. It should be like this.

Then run the command:
sudo apt-key add oracle_vbox.asc

Update apt-get and install VirtualBox 4.3:
$ sudo apt-get update
$ sudo apt-get install virtualbox-4.3


Sunday, July 20, 2014

Install Cinnamon on Ubuntu 14.04

Against Unity, Cinnamon can seem fairly performance orientated.



To install Cinnamon on Ubuntu 14.04, enter the commands in Terminal:

$ sudo add-apt-repository ppa:lestcape/cinnamon
$ sudo apt-get update
$ sudo apt-get install cinnamon




reference: OMG!Ubuntu! - How to Install Cinnamon from a PPA on Ubuntu 14.04


Note for using RecordMyDesktop on Cinnamon:

By default, the bottom bar will disappear when running RecordMyDesktop to record your screen activity. To fix it, run with Extra Options of --no-frame.

- Click Advanced button.


- Select Misc tab.
- Enter "--no-frame" in Extra Options box.


Install gnome-session-flashback

To install gnome-session-flashback, to make your Ubuntu run on classic desktop, enter the command in Terminal:

$ sudo apt-get install gnome-session-flashback


After installed, logout your session. You can get more options of GNOME Flashback (Compiz) and GNOME Flashback (Metacity) in login. Select GNOME Flashback (Metacity) for best performance.

Thursday, April 17, 2014

What's New in Ubuntu 14.04 LTS

Released on April 17, 2014, Ubuntu 14.04 is the latest Long Term Support release of the world's most popular open-source operating system.

See What's New in Ubuntu 14.04 LTS