Using LINUX commands in App Inventor. Extension

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

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/

14.- echo

We can use it to write text to a file.

echo “Scooby Doo, Where Are You!” > /mnt/sdcard/my_dog.txt
echo “I’m here!” >> /mnt/sdcard/my_dog.txt

15.- egrep ::: env ::: expand ::: expr ::: ext_logger ::: fallocate ::: false ::: fgrep ::: file ::

egrep, as grep -e (search expression).
env, enviroment variables.
expand, convert tabs into spaces in a file.
fallocate, allocated disk space for a file.
fgrep, as speed grep.
file, information of a file.

16.- find

Search files and directories.
find --help
find /mnt/sdcard/ -name *.txt (Search in all SdCard files *.txt)
find /mnt/sdcard/ -name *.png -o -name *.txt (List of files .png and .txt)
find /system/ -name *.apk (list where is apk files)
find /system/ -name *.apk > /mnt/sdcard/list_my_apk.txt

17.- free

Display the total, free and used amount of physical memory and swap space.

free -h