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
Related
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.
I'm not an expert of linux/unix shell commands.
Sorry for being so specific, but I would like to ask:
Suppose I have a folder and I need to check that it's empty of "simple" files (all files excluding folders/directories), and also ignore a specific folder inside it. How do I do that?
Do note that I intend to run the command on Android (without using the API, because I intend to use it for checking out the info of protected folders), so it might have less commands than the normal shell of linux/unix .
If needed, I can run multiple shell commands, and check the output of each of them before going to the next command.
This may help you
find /path/to/dirs/* -type d -empty \( ! -iname "DIR TO IGNORE" \)
Please check out the below examples, this will list all empty folders within /home/test - excluding the ruby folder
[user#server:/home/test]# mkdir shell bash php ruby perl
[user#server:/home/test]# touch shell/testing.sh
[user#server:/home/test]# find /home/test/* -type d -empty \( ! -iname "ruby" \)
/home/test/bash
/home/test/perl
/home/test/php
OK, I've handled it by checking for each of the files recursively, and ignored those that are in the path i wanted to ignore using Java.
The terminal command is:
find /PATH/TO/FOLDER/* -type f
If anyone else can also make it skip a specific folder, that would be nice.
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
When I pull some file from phone using adb pull, I got error like:cannot create 'some file': No such file or directory
The detail is: I create a file named "a.txt", under folder /mnt/sdcard/DCIM/100ANDRO/vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv, the "v....v" is a folder I create under /mnt/sdcard/dcim/100ANDRO/, then I open command terminal and switch to C:/ and run the command : C:\aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa>adb pull /mnt/sdcard/DCIM/100ANDRO/vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv folderfolderfolderfolderfolderfolderfolderfolderfolderfolderfolderfolderfolderfolderfolderfolderfolderfolderfolderfolder
here: a..........a is a folder I create in C:\ disk, the v....v is the folder I create under /mnt/sdcard/dcim/100ANDRO/, the "folder...folder...folder" is the target folder I want to create.
The result is:pull: building file list...
pull: /mnt/sdcard/DCIM/100ANDRO/vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv/a.txt -> folderfolderfolderfolderfolderfolderfolderfolderfolderfolderfolderfolderfolderfolderfolderfolderfolderfolderfolderfolder/a.txt
cannot create 'folderfolderfolderfolderfolderfolderfolderfolderfolderfolderfolderfolderfolderfolderf
olderfolderfolderfolderfolderfolder\a.txt': No such file or directory
but if the target folder length is shorter, the command will success!
C:\aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaa>adb pull /mnt/sdcard/DCIM/100ANDRO/vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv folderfolderfolderfolderfolderfo
lderfolderfolderfolderfolderfolderfolderfolderfolderfolderfolderfolderfolderfolderfold
pull: building file list...
pull: /mnt/sdcard/DCIM/100ANDRO/vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv/a.txt -> folderfolderfolderfolderfolderfolderfolderfolderfolder
folderfolderfolderfolderfolderfolderfolderfolderfolderfolderfold/a.txt
1 file pulled. 0 files skipped.
0 KB/s (12 bytes in 0.070s)
Why this happen? Is it a defect for adb.exe ? please help, really appreciated for that.
See the link below:
http://msdn.microsoft.com/en-us/library/aa365247.aspx
In the Windows API (with some exceptions discussed in the following paragraphs), the maximum length for a path is MAX_PATH, which is defined as 260 characters.
Are your paths crossing 260/?
I was running into this issue with cmd.exe + 260 character group policy editor/registry fix + reboot. Once I switched to powershell I was able to adb pull my files from my phone. If that doesn't work, try git bash.
Hi I need to copy/move the contents of data/tombstones to sdcard/tombstones
I'm using the command below:
mv data/tombstones /sdcard/tombstones
"failed on 'tombstones' - Cross-device link"
but I'm getting above error.
You have a SANE VERSION of the mv command
paraphrasing a few bits from lbcoder from xda and darkxuser from androidforums
"failed on 'tombstones' - Cross-device link"
It means that you can't create a hard link on one device (filesystem) that refers to a file on a different filesystem.
This is an age-old unix thing. You can NOT move a file across a filesystem using most implementations of mv. mv is not made to copy data from device to device, it simply changes a file's location within a partition. Since /data and /sdcard are different partitions, it's failing.
Consider yourself fortunate that you have a SANE VERSION of the mv command that doesn't try anyway -- some old versions will actually TRY to do this, which will result in a hard link that points to NOTHING, and the original data being INACCESSIBLE.
The mv command does NOT MOVE THE DATA!!! It moves the HARDLINK TO
THE DATA.
If you want to move the file to a different filesystem, you need to use the "cp" command. Copy the file to create a SECOND COPY of it on a different filesystem, and then DELETE the OLD one with the "rm" command.
A simple move command:
#!/bin/bash
dd if="$1" of="$2"
rm -f "$1"
You will note that the "cp" command returns true or false depending on the successful completion of the copy, therefore the original will only be removed IF the file copied successfully.
OR
#!/bin/bash
cat data/tombstones > sdcard/tombstones
rm data/tombstones
These script can be copied into some place referenced by the PATH variable and set executable.
Different Interface
If you need a different interface from adb you may move files using the FileExplorer in DDMS View.
Side note:
You can move a file into a folder when:
You're root;
It is your app directory;
You've used chmod from adb or elsewhere to change permissions
Basically you don't have permission to access /data/tombstones in a production version .
It seems we have to 'root' the device first.
But I failed to root my Samsung S4 which is using Android 4.3