Using LINUX commands in App Inventor. Extension

30.- netstat

netstat, list out all the network (socket) connections.

netstat.

curl opens up possibilities in REST API calls.

2 Likes

31.- ping

ping, to check the network connectivity between host and server/host.

ping -c 3 google.com (sends 3 packets)
ping -c 3 192.168.1.1

32.- printf

printf prints a formatted string to the standard output.

printf “My name is “%s”.\nIt’s a pleasure to meet you.” “John”
printf “%d plus %5f %s %.*f.” 5 5.05 “equals” 3 10.05
printf ‘hello\nworld\n!’
Examples from:

33.- ps ::: pm

ps, list process.

ps --help
ps -A

oooooooooOOOooooooooo

pm, package manager
shell_package

pm list packages
pm list packages -f
pm list packages -s
pm list features
pm list packages --show-versioncode
https://adbshell.com/commands/adb-shell-pm-list-packages

34.- rm ::: rmdir

rm, remove file.
rm -r, recursive, remove directory contents.
rmdir, remove directory.

35.- sed

sed, stream editor.

This is a very simple example, change the word five to FEVER in the file /mnt/sdcard/numeros.txt
uno,one,un
dos,two,deux
tres,three,trois
cuatro,four,quatre
cinco,five,cinq

sed ‘s/five/FEVER/’ /mnt/sdcard/los_numeros.txt

uno,one,un
dos,two,deux
tres,three,trois
cuatro,four,quatre
cinco,FEVER,cinq

sed --help

1 Like

36.- service

service command starts, stops, list services.

service list
service --help

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)