Using LINUX commands in App Inventor. Extension

Hello friends,
with this extension we are going to use some LINUX commands.
com.KIO4_Terminal.aix

  • With this block we can copy files from the assets to SdCard. This block only works with the compiled app (Build). It needs AskForPermission = WRITE_EXTERNAL_STORAGE
    extension_terminal3
    shell_permiss
    oooooooooooooooOOOOOOOOOOOOOoooooooooooooo

  • With this block we can copy files from the assets to the internal cache directory of the same application. We will get the address of the accessible file. This block only works with the compiled app (Build).
    Example of return: /data/user/0/appinventor.ai_minombre.mi_aplicacion/cache/logo1.png
    extension_terminal4
    shell_permiss
    oooooooooooooooOOOOOOOOOOOOOoooooooooooooo

0.- On my mobile I have this list of commands:
listado
ls /system/bin/

acpi ::: am ::: app_process ::: app_process32 ::: app_process64 ::: applypatch ::: appops ::: appwidget ::: awk ::: base64 ::: basename ::: bcc ::: blockdev ::: bmgr ::: bu ::: bugreport ::: bugreportz ::: bunzip2 ::: bzcat ::: bzip2 ::: cal ::: cat ::: chcon ::: chgrp ::: chmod ::: chown ::: chroot ::: chrt ::: cksum ::: clear ::: cmd ::: cmp ::: comm ::: content ::: copy_bugreport_file.sh ::: cp ::: cpio ::: crash_dump32 ::: crash_dump64 ::: curl ::: cut ::: dalvikvm ::: dalvikvm32 ::: dalvikvm64 ::: date ::: dd ::: debuggerd ::: dex2oat ::: dexdiag ::: dexdump ::: dexlist ::: df ::: diff ::: dirname ::: dmesg ::: dos2unix ::: dpm ::: du ::: dumpsys ::: echo ::: egrep ::: env ::: expand ::: expr ::: ext_logger ::: fallocate ::: false ::: fgrep ::: file ::: find ::: flock ::: fmt ::: free ::: getenforce ::: getevent ::: getprop ::: grep ::: groups ::: gunzip ::: gzip ::: head ::: hid ::: host_manager_11ad ::: hostname ::: hw ::: hwclock ::: id ::: ifconfig ::: ime ::: inotifyd ::: input ::: insmod ::: ionice ::: iorenice ::: ip ::: ip-wrapper-1.0 ::: ip6tables ::: ip6tables-restore ::: ip6tables-save ::: ip6tables-wrapper-1.0 ::: iptables ::: iptables-restore ::: iptables-save ::: iptables-wrapper-1.0 ::: iw ::: keystore_cli_v2 ::: kill ::: killall ::: ld.mc ::: linker ::: linker64 ::: linker_asan ::: linker_asan64 ::: ln ::: load_policy ::: locksettings ::: log ::: logcat ::: logname ::: logwrapper ::: losetup ::: ls ::: lshal ::: lsmod ::: lsof ::: lspci ::: lsusb ::: md5sum ::: media ::: microcom ::: mitop ::: mkdir ::: mkfifo ::: mkfs.ext2 ::: mkfs.ext3 ::: mkfs.ext4 ::: mknod ::: mkswap ::: mktemp ::: modinfo ::: modprobe ::: monkey ::: more ::: mount ::: mountpoint ::: move_time_data.sh ::: move_wifi_data.sh ::: mv ::: ndc ::: ndc-wrapper-1.0 ::: netstat ::: newfs_msdos ::: nice ::: nl ::: nohup ::: oatdump ::: od ::: paste ::: patch ::: patchoat ::: pgrep ::: pidof ::: ping ::: ping6 ::: pkill ::: pm ::: pmap ::: ppd ::: printenv ::: printf ::: ps ::: pwd ::: readlink ::: realpath ::: reboot ::: renice ::: requestsync ::: resize2fs ::: restorecon ::: rm ::: rmdir ::: rmmod ::: run-as ::: runcon ::: schedtest ::: screencap ::: screenrecord ::: secdiscard ::: secilc ::: sed ::: sendevent ::: sensorservice ::: seq ::: service ::: setenforce ::: setprop ::: setsid ::: settings ::: sh ::: sha1sum ::: sha224sum ::: sha256sum ::: sha384sum ::: sha512sum ::: sleep ::: sm ::: sort ::: split ::: start ::: stat ::: stop ::: strings ::: stty ::: svc ::: swapoff ::: swapon ::: sync ::: sysctl ::: tac ::: tail ::: tar ::: taskset ::: tc ::: tc-wrapper-1.0 ::: tee ::: telecom ::: time ::: timeout ::: tinycap ::: tinymix ::: tinypcminfo ::: tinyplay ::: toolbox ::: top ::: touch ::: toybox ::: tr ::: true ::: truncate ::: tty ::: uiautomator ::: ulimit ::: umount ::: uname ::: uniq ::: unix2dos ::: uptime ::: usleep ::: uudecode ::: uuencode ::: vmstat ::: vr ::: wc ::: which ::: whoami ::: wigig_logcollector ::: wigig_remoteserver ::: wigig_wiburn ::: wm ::: xargs ::: xxd ::: yes ::: zcat ::: zip_utils

14 Likes

1.- base64 encode/decode.


base64 /mnt/sdcard/AppInventor/assets/logo1.png > /mnt/sdcard/logo1.txt
base64 -d /mnt/sdcard/logo1.txt > /mnt/sdcard/logo2.png
base64 /mnt/sdcard/AppInventor/assets/logo1.png

https://linuxhint.com/bash_base64_encode_decode/

shell_base64.aia (9.9 KB)

3 Likes

2.- basename.

basename /mnt/sdcard/AppInventor/assets/logo1.png

return
logo1.png

2 Likes

3.- bunzip2 ::: bzcat ::: bzip2

zip/unzip files

2 Likes

4.- cal
calendar.
cal --help
cal 5 2020


shell_cal

1 Like

5.- cat
Create single or multiple files, view contain of file, concatenate files.
https://www.tecmint.com/13-basic-cat-command-examples-in-linux/

cat --help
cat > /mnt/sdcard/new_file
cat /mnt/sdcard/read_this.txt
cat /proc/cpuinfo
cat /proc/meminfo

1 Like

Very nice indeed :slight_smile:

thumbsup2

1 Like

6.- cksum
This command computes a Cyclic Redundancy Check (CRC) checksum of the input file.

cksum --help
cksum /mnt/sdcard/AppInventor/assets/numeros.txt

return
2727242570 159 /mnt/sdcard/AppInventor/assets/numeros.txt

1 Like

A couple of possibly useful links:

7.- cp
Copy files from SOURCE to DEST.
cp --help
cp -v /mnt/sdcard/AppInventor/assets/numeros.txt /mnt/sdcard/numers.txt

1 Like

8.- curl

This is a great command to work with the Internet, you will be able to download files, upload them as an FTP client, read Query HTTP Headers, POST sending,…

…but with this 7.58 (Android) version, only these protocols work: file https http

curl --version
curl --help
curl -I https://community.appinventor.mit.edu/
curl -o /mnt/sdcard/my_logo.png http://domain.com/image.png

Read this:
https://www.tecmint.com/linux-curl-command-examples/

5 Likes

9.- cut

Interesting command to get parts of a file.

We have the file numbers.txt with words in Spanish, English and French. We are interested in obtaining the numbers in English.
We cut by the delimiter “,” and take field 2

cut --help
cut -d “,” -f 2 /mnt/sdcard/AppInventor/assets/numeros.txt




shell_cut.aia (10.0 KB)

1 Like

10.- date

date --help
date
date ‘+Today is %Y-%m-%d Hour is: %H-%M-%S’
date >> /mnt/sdcard/animales.txt Change file to actual date.
date -r /mnt/sdcard/animales.txt +%Y%m%d%H%M%S.%N
To change the date you need to be root.

1 Like

Then there are the two mighty rabbit holes of bash: awk & sed :wink:

11.- dd

With this command you can copy files:
dd if=/mnt/sdcard/numeros.txt of=/mnt/sdcard/The_numbers.txt

With dd command you can build an image of SdCard, but CAUTION with this command.

1 Like

I would suggest to users that they stick with cp (copy) and mv (move).

Also be wary of commands rm & rmdir (you may need to be rooted to wipe your whole device, but better safe than sorry) - only use these if you really know what you are doing.

12.- dirname

Show directory portion of path

dirname /mnt/sdcard/AppInventor/assets/numeros.txt

return
/mnt/sdcard/AppInventor/assets

Does the extension have access to files in assets (once compiled) ?

I think not. I think it would be interesting to add to this extension, a block to extract the asset file and copy it to the SdCard.

1 Like

That is exactly what I was thinking about. This is really good :slight_smile:

1 Like