Using LINUX commands in App Inventor. Extension

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.ezproxy.canberra.edu.au/
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

13.- df ::: du

df, information of device name, total blocks, total disk space, used disk space, available disk space and mount points on a file system.

df -h
shell_df


du, check the information, size of files and directories.

du --help
du - h /mnt/sdcard/AppInventor/assets/logo1.png
du -h /mnt/sdcard/AppInventor/assets/
du -a /mnt/sdcard/AppInventor/assets/