Using LINUX commands in App Inventor. Extension

37.- sleep ::: sort

sleep 4

sort, sorts lines of text files. It supports sorting alphabetically, in reverse order, by number, by month and can also remove duplicates.

sort /mnt/sdcard/numeros.txt
sort /mnt/sdcard/numeros.txt > /mnt/scdard/sort_numeros.txt
sort -r /mnt/sdcard/numeros.txt (reverse)
sort -u /mnt/sdcard/numeros.txt (no duplicates)
sort -k 2 -t , /mnt/sdcard/numeros.txt

38.- split

split a file.

We have a file image.png with size 5K

split -b 1K /mnt/sdcard/image.png /mnt/sdcard/image_

return
image_aa (1K)
image_ab (1K)
image_ac (1K)
image_ad (1K)
image_ae (1K)
https://www.linuxtechi.com/split-command-examples-for-linux-unix/

39.- stat

stat, displaying detailed information relating to a file.

stat /mnt/sdcard/imagen.jpg

https://landoflinux.com/linux_stat_command_examples.html

40.- tar

tar, packages files, it can compress and decompress it.
shell_tar

tar -cf /mnt/sdcard/my_files.tar /mnt/sdcard
tar -czf /mnt/sdcard/archivos.tar.gz /mnt/sdcard (compress)
tar -cjf /mnt/sdcard/archivos.tar.bz2 /mnt/sdcard (compress)

untar
tar -xf /mnt/sdcard/archivos.tar -C /mnt/sdcard/bk_dir/
tar -xzf /mnt/sdcard/archivos.tar.gz -C /mnt/sdcard/bk_dir/

https://www.tecmint.com/18-tar-command-examples-in-linux/

1 Like

41.- tee ::: touch

tee, reads the standard input and writes it to both the standard output and one or more files.
ls -ali /mnt/sdcard/ | tee /mnt/sdcard/my_list.txt | cat
teee

touch, change file timestamps or create empty file.

touch /mnt/sdcard/zero.txt
touch -am 2019-12-12T12:12:12 /mnt/sdcard/my_file.txt (user root)
stat /mnt/sdcard/my_file.txt

shell_touch

42.- toybox

toybox is a file that contains most of these LINUX commands.

For example, truncate is a symbolic link to the toybox file, such that when we run truncate we are executing a command that is “inside” toybox.

Using ls -ali /system/bin/ we get this list …


Note that most are symbolic links to toybox.

Toybox’s main goal is to make Android self-hosting by improving Android’s command line utilities so it can build an installable Android Open Source Project image entirely from source under a stock Android system. After a talk at the 2013 Embedded Linux Conference explaining this plan (outline, video), Google merged toybox into AOSP and began shipping toybox in Android Mashmallow. (http://www.landley.net/toybox/about.html)

Help commands toybox: http://www.landley.net/toybox/help.html

http://landley.net/toybox/

oooooooooooooooOOOOOOOOOOOOOOOOooooooooooo

toolbox is similar to toybox, https://elinux.org/Android_toolbox

1 Like

43.- truncate

truncate, used to shrink or extend the size of file.

touch /mnt/sdcard/zero.txt ( 0 bytes)
ls -ali /mnt/sdcard/zero.txt

truncate -s 123K /mnt/sdcard/zero.txt (now 123K)(filled NULNUL)
ls -ali /mnt/sdcard/zero.txt

44.- uptime

uptime, how long your system has been running.

45.- uudecode ::: uuencode

https://lowfatlinux.com/linux-uuencode-uudecode.html

base64 vs uuencode;

46.- wc

wc, count lines, words and characters.

wc /mnt/sdcard/my_file.txt
wc -l /mnt/sdcard/my_file.txt
wc -w /mnt/sdcard/my_file.txt
wc -c /mnt/sdcard/my_file.txt
wc -m /mnt/sdcard/my_file.txt

47.- zcat ::: zip_utils

zcat, like gzip -dc
zip_utils, tool zip.

48.- sh

sh, run script.

Simple example of script:

mkdir /mnt/sdcard/my_directory
DIRE="/mnt/sdcard/my_directory"

date >  $DIRE/date.txt
echo “Hello friend” > $DIRE/friend.txt
ping -c 3 google.com > $DIRE/my_ping.txt &
find /mnt/sdcard/ -name *.jpg > $DIRE/my_list_jpg.txt &
echo "Characters in file friend.txt: " > $DIRE/size_file.txt
wc -c $DIRE/friend.txt  >> $DIRE/size_file.txt

This script creates the directory: my_directory in SdCard and various files within it.

We can run it from the MITCOMPANION or Compiled.

Compiled: the block AssetsToCacheDir copies the file my_script.txt
from the assets to the cache directory of the same application, that is: /data/user/0/appinventor.ai_juan.shell_script/cachemy_script.txt

shell_script.aia (10.3 KB)

49.- awk

awk is a scripting language which is used for processing or analyzing text files .
We are going to do the examples in this tutorial:
https://www.linuxtechi.com/awk-command-tutorial-with-examples/

shell_awk.aia (12.1 KB)

1 Like

If you have sqlite3 in your /system/bin, you can run sqlite commands. Here are a couple of examples:

  1. Return the contents of a database table or view as a csv format text:

sqlite3 -header -csv /storage/emulated/0/< path/to/database > 'SELECT * FROM < table or view >;'

(remove "-header" if you do not want the column headings, replace items in and including <> for your database and table or view)

  1. Export the contents of a table or view to a csv file:

sqlite3 -header -csv /storage/emulated/0/< path/to/database > 'SELECT * from < table or view >;' > /storage/emulated/0/< path/to/filename >.csv

(this method is not provided by the various sqlite extensions, so a shortcut to extracting data)

I tried doing this with bash scripts but they just didn't want to work for some reason

2 Likes

Good One
How can I connect to a Redis server?
Will you please give me a sample string to connect and get the value?

You would need to have redis-tools installed on the device to even try to connect to a redis server using redis-cli and this extension. You cannot, as far as I know, install redis-tools....

1 Like

How can I Install it? Any link or idea?

1 Like

Sir, I already have a Redis server installed and it contains 7 ports. I have used the Cloud DB components and created all my apps. I want t to use the HSET, HGET commands of Redis as we don’t have in the Cloud DB component. So, I thought some how we have an option to release commands with this extension.

As I said....

You might be able to do something with php, sending commands to a server, and then use shell_exec to send redis commnds?