Managing files in Android terminal - android

Using a terminal emulator in my android phone I accidentally copied /proc directory into another user directory. Now I want to delete the copy but I don't have the permissions to do so. I tried to change ownership and permissions to 777 but with no success. I am using Oneplus 2 and termux application. Any suggestions?
Edit:
The original /proc directory :
dr-xr-xr-x 459 root root 0 Jan 1 1970 proc/
it was copied to /.../line/proc:
Line:
drwxrwxrwx 4 u0_a45 u0_a45 4096 Oct 17 12:23 line/
Line/proc:
dr-xr-xr-x 52 u0_a45 u0_a45 4096 Jan 1 1970
proc/
The new proc directories are not removable:
rm -rf line/proc
rm: can't remove 'line/proc/12159/task/12247': Permission denied
...

Related

Android Shell root rm folder failed

I created a folder hdr in /sdcard/DCIM/Camera/ by linux c function: mkdir(), but when I set permission, I used '777' but not '0777' uncarefully, and the folder permission like this:
xxx:/sdcard/DCIM/Camera # ll
total 6
drwxrws--T 5 u0_a217 media_rw 3452 2022-03-01 09:26 hdrd
...
xxx:/sdcard/DCIM/Camera/hdrd # ll
total 9
drwxrws--T 2 u0_a217 media_rw 3452 2022-02-25 10:13 20220225_101334_1645755214821
...
xxx:/sdcard/DCIM/Camera/hdrd/20220225_101334_1645755214821 # ll
total 1952
-rw-rw---- 1 u0_a217 media_rw 460800 2022-02-25 10:13 IMG_20220225_101334_1645755214821_0_640x480_p_640x480_SRC.NV12
then , I wanna delete this hdrd folder so I used rm -r hdrd, there is an error:
xxx:/sdcard/DCIM/Camera # rm -r hdrd/
rm: IMG_20220225_101334_1645755214821_0_640x480_p_640x480_SRC.NV12: Math result not representable
...
I don't know why delete failed, I was in root state.
PS: I use lsattr fuction, but not succeed:
xxx:/sdcard/DCIM/Camera # lsattr hdrd
lsattr: reading flags 'hdrd/20220225_101334_1645755214821': Function not implemented

How to pull via adb the latest screenshot from an Android device?

Is there a method to pull via ADB the latest screenshot from my device ?
-rw-rw---- 1 root sdcard_rw 137047 2017-11-04 14:02 Screenshot_20171104-140236.png
-rw-rw---- 1 root sdcard_rw 67459 2017-11-04 14:05 Screenshot_20171104-140533.png
-rw-rw---- 1 root sdcard_rw 33939 2017-11-04 14:05 Screenshot_20171104-140557.png
-rw-rw---- 1 root sdcard_rw 329546 2017-11-06 11:12 Screenshot_20171106-111218.png
-rw-rw---- 1 root sdcard_rw 437013 2017-11-13 17:57 Screenshot_20171113-175727.png
-rw-rw---- 1 root sdcard_rw 1200088 2017-11-19 13:44 Screenshot_20171119-134405.png
-rw-rw---- 1 root sdcard_rw 146758 2017-12-12 20:19 Screenshot_20171212-201936.png
-rw-rw---- 1 root sdcard_rw 128158 2017-12-18 11:11 Screenshot_20171218-111151.png
How to pull the latest screenshot ?
-rw-rw---- 1 root sdcard_rw 128158 2017-12-18 11:11 Screenshot_20171218-111151.png
Currently i'm pulling all the files using :
adb pull /mnt/sdcard/Screenshots c:\screenshots
Then organize them by date in Windows Explorer
Edit1 I can get the latest file using :
adb shell stat -c %y /mnt/sdcard/Screenshots
ADB doesn't support flags, so you'll have to pull all the files(names), then do some logic to find the most recent file, then pull that.
It's possible using a script, more info in this related question.
I'd suggest capturing the output of the adb command that gets ya the latest file and redirecting that to an adb command that does the pulling.
Based off a somewhat related answer for saving the output of a command to a variable...
FOR /F "tokens=* USEBACKQ" %%F IN (`command`) DO (
SET var=%%F
)
... replace command with the command's output to be captured, then...
adb pull %var% c:\screenshots
... or...
adb pull /mnt/sdcard/Screenshots/%var% c:\screenshots
... should do kinda what ya want.

Android Nougat ProcessBuilder ignores PATH env variable - bug/issue?

I'm having android app that extracts some native executable on first run and uses it to do some work. It worked before Nougat and stopped working. After few days or investigation i've found that PATH environment variable is accepted but not taken into account! I'm, trying out if it's a feature or a bug.
First, let's see what we have and if we're able to do the same from cmd.
I've replaced actual android app package with 'my.app.package' and not related output with '...' for SO.
ZTE_BLADE_V0800:/ $ run-as my.app.package
ZTE_BLADE_V0800:/data/data/my.app.package $ whoami
u0_a129
ZTE_BLADE_V0800:/data/data/my.app.package $ ls -l
total 56
drwxrwx--x 2 u0_a129 u0_a129 4096 2017-03-14 16:15 app_build
drwxrwx--x 2 u0_a129 u0_a129 4096 2017-03-15 13:15 app_buildSources
drwxrwx--x 2 u0_a129 u0_a129 4096 2017-03-14 16:15 app_downloads
-rw------- 1 u0_a129 u0_a129 35 2017-03-14 16:16 app_repository
drwxrwx--x 14 u0_a129 u0_a129 4096 2017-03-14 16:16 app_sdk
drwxrwx--x 3 u0_a129 u0_a129 4096 2017-03-14 16:15 app_temp
drwxrwx--x 2 u0_a129 u0_a129 4096 2017-03-14 16:15 cache
lrwxrwxrwx 1 root root 54 2017-03-15 13:15 lib -> /data/app/my.app.package-2/lib/arm
ZTE_BLADE_V0800:/data/data/my.app.package $ ls -l ./app_sdk/
total 96
...
drwx------ 4 u0_a129 u0_a129 4096 2017-03-14 16:16 cppcheck#1.64#1
...
ZTE_BLADE_V0800:/data/data/my.app.package $ ls -l ./app_sdk/cppcheck\#1.64\#1/
total 16
...
drwx------ 3 u0_a129 u0_a129 4096 2017-03-14 16:16 bin
-rw------- 1 u0_a129 u0_a129 0 2017-03-14 16:16 init.done
ZTE_BLADE_V0800:/data/data/my.app.package $ ls -l ./app_sdk/cppcheck\#1.64\#1/bin
total 6960
drwx------ 2 u0_a129 u0_a129 4096 2017-03-14 16:16 cfg
-rwxr-xr-x 1 u0_a129 u0_a129 2345332 2017-03-14 16:16 cppcheck
-rwxr-xr-x 1 u0_a129 u0_a129 1211424 2017-03-14 16:16 libgnustl_shared.so
ZTE_BLADE_V0800:/data/data/my.app.package $ export PATH=$PATH:./app_sdk/cppcheck#1.64#1/bin
ZTE_BLADE_V0800:/data/data/my.app.package $ export LD_LIBRARY_PATH=./app_sdk/cppcheck#1.64#1/bin
ZTE_BLADE_V0800:/data/data/my.app.package $ cppcheck --version
Cppcheck 1.65 dev
ZTE_BLADE_V0800:/data/data/my.app.package $
Now let's try to do the same in Runtime:
ProcessBuilder processBuilder = new ProcessBuilder();
String path =
System.getenv("PATH") +
":./app_sdk/cppcheck#1.64#1/bin";
processBuilder.command(new String[] {
// "sh", "-c", "echo $PATH", // (1) working
// "sh", "-c", "echo $LD_LIBRARY_PATH", // (2) working
"./app_sdk/cppcheck#1.64#1/bin/cppcheck", "--version" // (3) working
// "cppcheck", "--version" // (4) NOT working even with PATH env variable passed
});
processBuilder.directory(new File("/data/data/my.app.package/"));
Map<String, String> env = processBuilder.environment();
env.put("PATH", path);
env.put("LD_LIBRARY_PATH", "./app_sdk/cppcheck#1.64#1/bin");
process = processBuilder.start();
and i get IOException thrown:
Cause: error=13, Permission denied
Cannot run program "cppcheck" (in directory
"/data/data/my.app.package"): error=13
Let's see if PATH is passed correctly.
Uncomment comment (1) and comment the other command lines, confirm it's set:
/sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin:./app_sdk/cppcheck#1.64#1/bin
Let's see if LD_LIBRARY_PATH is passed correctly.
Uncomment comment (2) and comment the other command lines, confirm it's set:
./app_sdk/cppcheck#1.64#1/bin
Now let's see if i'm able to run the tool passing full path.
Uncomment comment (3) and comment the other command lines, see it's working now:
Cppcheck 1.65 dev
Wow, even with PATH passed i have to pass full path for the executable. If i use short tool name, i'm getting Permission denied error.
Is it Nougat (since i'm having it starting Nougat only) feature or issue or i missed anything?
I know Nougat introduced more strict security policies but i see no reason for this in my case to stop working as all the files are in app sandbox (internal directory in my app directory).
PS. I can't just replace all short executable names in command-lines as executable can run another executable too using short executable name, so i need to get PATH variable taken into account eventually.
I did not get any response from Google (they are working on it starting Jan 25) so i had to workaround it passing full executable path like in comment (3).

Moved mp3 files from internal to external storage. Files are not recognized anymore

To clear up some disk space I moved my mp3 collection from internal to external storage. My device is rooted and I was su at the time.
The files can be seen (and played) from the File Manager, but none of my music players see them.
What looked interesting was the file permissions after moving. Here's a file still on internal storage that wasn't moved.
root#kltetmo:/data/media/0/Download/mp3 # ll
-rw-rw-r-- 1 1023 1023 6730901 Aug 25 16:03 fatamix_upd_start_20160824(2).mp3
root#kltetmo:/data/media/0/Download/mp3 #
And here are a couple files that were moved to external storage:
root#kltetmo:/storage/sdcard1/Music/Bat for Lashes/Fur and Gold # ll
-rwxrwx--- 1 root 1028 5887321 Jul 16 2015 01 - Horse And I.mp3
-rwxrwx--- 1 root 1028 5894753 Jul 16 2015 04 - What's A Girl To Do_.mp3
Moving them to external storage appears to have changed permissions. Unfortunately, chmod is not affecting the actual file permissions:
root#kltetmo:/storage/sdcard1/Music/Bat for Lashes/Fur and Gold # ll
-rwxrwx--- 1 root 1028 5887321 Jul 16 2015 01 - Horse And I.mp3
-rwxrwx--- 1 root 1028 5894753 Jul 16 2015 04 - What's A Girl To Do_.mp3
root#kltetmo:/storage/sdcard1/Music/Bat for Lashes/Fur and Gold # chmod 664 01\ -\ Horse\ And\ I.mp3
root#kltetmo:/storage/sdcard1/Music/Bat for Lashes/Fur and Gold # ll
-rwxrwx--- 1 root 1028 5887321 Jul 16 2015 01 - Horse And I.mp3
-rwxrwx--- 1 root 1028 5894753 Jul 16 2015 04 - What's A Girl To Do_.mp3
I tried moving the file back to internal storage to change permissions there. This worked until I moved the file back to external storage.. moving it definitely changed permissions to 770.
root#kltetmo:/data/media/0/Music # ll
-rwxrwx--- 1 root 1028 5887321 Nov 14 18:18 batforlashes.mp3
root#kltetmo:/data/media/0/Music # chmod 644 batforlashes.mp3
root#kltetmo:/data/media/0/Music # ll
-rw-r--r-- 1 root 1028 5887321 Nov 14 18:18 batforlashes.mp3
root#kltetmo:/data/media/0/Music # mv batforlashes.mp3 /storage/sd
sdcard0/ sdcard1/
forlashes.mp3 /storage/sdcard1/Music/Bat\ for\ Lashes/Fur\ and\ Gold/ <
root#kltetmo:/data/media/0/Music # ll
root#kltetmo:/data/media/0/Music # ll /storage/sdcard1/Music/Bat\ for\ Lashes/Fur\ and\ Gold/
-rwxrwx--- 1 root 1028 5887321 Jul 16 2015 01 - Horse And I.mp3
-rwxrwx--- 1 root 1028 5894753 Jul 16 2015 04 - What's A Girl To Do_.mp3
-rwxrwx--- 1 root 1028 5887321 Nov 14 18:18 batforlashes.mp3
root#kltetmo:/data/media/0/Music #
What do I need to do to reset permissions so these files can be seen and played from my default music app?
Android media player apps do not scan the file system to get the list of available media files - they get the list from an internal database. You need to send the ACTION_MEDIA_SCANNER_SCAN_FILE intent to force rescan of the folder where the files were moved to for them to become visible to the player apps.

Unable to see the source tree through Finder while doing repo sync in OSX

I am downloading the android source as per the instructions mentioned in source.android.com. I have made a different case sensitive file system and have made a directory in it and doing a repo sync. I can see through terminal ls -la
the following files
Aruns-MacBook-Pro:ANDROID_DIR ArunAbraham$ ls -la
total 0
drwxr-xr-x 3 ArunAbraham staff 102 May 14 17:26 .
drwxr-xr-x 5 ArunAbraham staff 340 May 14 17:23 ..
drwxr-xr-x 6 ArunAbraham staff 238 May 14 17:27 .repo
But i can't see the same through the Finder. Is this how it is supposed to behave ?
Could someone explain me this behavior ? Or have i done something wrong ?
Finder treats files starting with a . as hidden files. ls does as well but the -a option you gave overrides it.
Here's a tip to show all hidden files in the Finder, but you will see everything, not just theones you want. Short version:
defaults write com.apple.Finder AppleShowAllFiles YES

Categories

Resources