How to write to a file in the Directory "/sys/....." - android

How can i edit the file in the sys directory using JNI and NDk in android.
Actually i Need to edit these file "/sys/class/gpio/gpio41/value".

By changing the mode you can now edit the file using: chmod 777 /sys/class/gpio/gpio41/value

just a little hint: use chmod 666 ...
You will get read/write permission but you don't need execute permission on
HW-pins.
Regards
Martin

Related

Android : change permission of system files

My phone is rooted and i wrote code in my app to change file permission of system file which is located at /sys/class/leds/lcd-backlight/brightness
Runtime.getRuntime().exec("su");
Runtime.getRuntime().exec("chmod 777 /sys/class/leds/lcd-backlight/brightness");
but this code can't change the file permission of the specified file and i won't got any kind of error or exception
Download the RootTools.jar from this link https://github.com/Stericson/RootTools/releases
Put that .jar file into your project's 'libs' directory
import com.stericson.RootTools.*;
.
.
Command cmd=new Command(0,"chmod 766 /sys/class/leds/lcd-backlight/brightness");
RootShell.getShell(true).add(cmd);
That's not how you execute su-ed commands. Please refer to http://su.chainfire.eu/ for guidance.

Create empty file with android init script

Is it possible to create empty file in android source code with init rc script like we create folder.
mkdir /tmp creates folder but
touch /tmp/test doesn't do anything.
pls help
the 'write' or 'copy' command works.
but please make ensure the commands are added after the filesystems are mounted, for example, at the end of "on post-fs-data"
on post-fs-data
...
write /data/non-empty-file 0
...
copy /dev/null /data/empty-file

My shell-script is not running on android

I am trying to run the following simple shell-script on android:
#!/system/bin/sh
echo "Hello World!"
I named the file "test", and place it in "/system/bin/" .. I change the permission to 755 and the group to shell ..
now when I try to run the script: test, it shows:
sh: test: No such file or directory
I can see the file in there and when I run bash test or sh test it works ..
what is the problem ?
Do not call it “test” because that’s a shell built-in command. Shells will call internal builtins in preference over external utilities.
Rename it to /system/bin/testx and call it as “testx” and see whether that works.
Other common pitfalls on android: 「#!/system/bin/sh」 and most directories are mounted “noexec”. But both of these do not apply to your script if you put it to /system/bin/ anyway.

How can I change the Read/Write Permissions of /mnt/SDcard folder on Kindle Fire?

I am trying to develop Amazon In-app in android. For this i download the sample code for from this site https://developer.amazon.com/sdk/in-app-purchasing/sample-code/button-clicker.html. This article suggests that we have to put a file amazon.sdktester.json in mnt/sdkcard folder of device. For this i read article from this site https://developer.amazon.com/sdk/fire/connect-adb.html#InstallApp and do the same. But when I tried to push file on sdcard, the eclipse gives me following error:
[2012-11-19 13:39:39 - ddms] transfer error: Permission denied
[2012-11-19 13:39:39] Failed to push selection: Permission denied
Is there any way to change the permissions of root folder of Kindle Fire?
Please try to use chmod command in the ADB shell...
Following are some chmod sample:
Add single permission to a file/directory
Changing permission to a single set. + symbol means adding permission.
For example, do the following to give execute permission for the user
irrespective of anything else:
$ chmod u+x filename
Add multiple permission to a file/directory
Use comma to separate the multiple permission sets as shown below.
$ chmod u+r,g+x filename
Remove permission from a file/directory
Following example removes read and write permission for the user.
$ chmod u-rx filename
Change permission for all roles on a file/directory
Following example assigns execute privilege to user, group and others
(basically anybody can execute this file).
$ chmod a+x filename
Make permission for a file same as another file (using reference)
If you want to change a file permission same as another file, use the
reference option as shown below. In this example, file2′s permission
will be set exactly same as file1′s permission.
$ chmod --reference=file1 file2
Apply the permission to all the files under a directory recursively
Use option -R to change the permission recursively as shown below.
$ chmod -R 755 directory-name/
Change execute permission only on the directories (files are not affected)
On a particular directory if you have multiple sub-directories and
files, the following command will assign execute permission only to
all the sub-directories in the current directory (not the files in the
current directory).
$ chmod u+X *

Multiple file rename in Android

I'm trying to write a script using Android's shell to rename all files of a given extension to add the .bak extension, and another to remove it.
This works for adding the .bak extension to all pdf files in the directory
ext=.bak
for f in *.pdf
do
mv $f $f$ext
done
But bash string slicing using ${varname:index:length} doesn't work in the android shell, so I'm at a loss as to how to remove the extension. Does anyone have any ideas?
EDIT: to clarify, I'm trying to find a way to delete the last four characters of a string in android shell. Other solutions that I have not considered which will solve my specific problem are also welcome.
UPDATE:
Based on the given answer, the following code will remove a file extension from any file possessing that extension in a current directory in an unmodified Android shell (where .bak can be replaced with the extension of your choice)
for f in *.bak
do
mv $f ${f%.*}
done
Have you tried removing the substring
fname="test.abc.bak"
mv $fname ${fname%.*}
Thanks
I got some code, but it uses temporary file, just try it and check for your usefulness
ls -l |awk '{print $9}' >/list
cat /list |while read line
do
echo $line >/tempfile
first=`cut -f1 -d'.' /tempfile`
echo $first >>/output.txt
mv $line $first
done

Categories

Resources