adb shell command - cd: No such file or directory - android

I use an android 4.0 system on my device, when I use adb shell log in and want to go to the /cache directory with using cd cache, but it just show
/system/bin/sh: cd: /cache - No such file or directory
Why? I really see the cache use ls command, it shows like
lrwxrwxrwx root root 2012-03-12 10:22 cache -> /data/cache"
Cd to other directory is ok. Has anybody can help me?

Instead of
cd /cache
do
cd /data/cache
or
If you type ls and you see cache, you should type cd cache because cd /cache is a directory just under the root /

/cache is a symbolic link to a non-existent directory. cd /cache is the same as cd /data/cache. if /data/cache does not exist (which looks to be your problem) you'd get the "No such..." error.
Additionally, if you do ls -L /cache you'd get the same "No such..." error; that's because the -L option tries to list the target of the link (which does not exist, in this case) instead of the link.
Finally:
ln -s this_directory_almost_certainly_does_not_exist not_sure_if_this_exists
test -f not_sure_if_this_exists || echo 'Nope, it does not exist'

Related

Unzip files in phone from ADB terminal

I am trying to unzip files in my android (11) phone with ADB from the terminal (Ubuntu 20.04). I need to run a script from my Ubuntu laptop to unzip files on my phone.
I have already tried Busybox from this suggestion. With this app, I can unzip files after accessing the shell. I mean -
$ adb shell
a60q:/ $ cd /sdcard/
a60q:/sdcard $ unzip data.zip
Archive: data.zip
inflating: Screenshot from 2020-11-30 16-45-46 (7th copy).png
inflating: Screenshot from 2020-11-30 16-45-46 (10th copy).png
But when I try to use the direct command, it shows an error.
$ adb shell unzip /sdcard/data.zip
unzip: couldn't create file Screenshot from 2020-11-30 16-45-46 (7th copy).png: Read-only file system
Archive: /sdcard/data.zip
Rooting phone isn't an option. My questions are -
What can I do here to unzip from the terminal?
Is there any tool to make compressed zip files (in Android) from the terminal?
In order to successfully invoke the unzip command from the terminal you should explicitly specify the folder where the zip's content will be extracted, for instance:
adb shell unzip /sdcard/data.zip -d /sdcard
By invoking unzip --help you will get more information on the other parameters available as well.

Deleting a folder in a AVD

I try to delete a folder with:
adb shell rmdir -f /storage/sdcard/myfolder
adb shell rmdir -r /storage/sdcard/myfolder
and I get the following error :
rmdir failed for -f, Read-only file system
How can I manage to delete that folder, without using java code. The folder is created by my app, so this is no system folder or the like.
* UPDATE *
deleting a file with
rm path/file works, but rmdir doesn't.

Where does adb shell mkdir create directories

I tried:
$ adb shell
# mkdir data/local/tmp/testjars
# exit
I thought testjars would be created in the current working directory, but nothing appears there. Where is this folder I created (testjars) placed?
It will be created in whatever directory is your current working directory (inside the adb shell, not your host system).
Example:
adb shell # execute shell, the following commands are executed inside it
cd /data/local/tmp # change the current working directory to the temp directory
mkdir data/local/tmp/testjars # create a new directory(ies)
After the execution of the commands above, the path to the testjars directory will be following: /data/local/tmp/data/local/tmp/testjars.
So better do:
adb shell
cd /data/local/tmp # change the current working directory to where you want to create a subdirectory
mkdir testjars
You'll end up with a directory /data/local/tmp/testjars.
Also, if you specify the path without a starting slash /, e.g. mkdir test, it's created in the current working directory. If you specify it with the starting slash, e.g. mkdir /test, it's created in the root directory (if you have rights to do that).

No such file or directory when 'cp' but not with 'ls'

I am trying to copy the shared preferences folder of my app to the /sdcard partition from my PC using the following ADB command:
adb shell su -c "cp
/data/data/com.anrapps.pixelbatterysaver/shared_prefs/
/sdcard/appdata/"
But this returns cp: Skipped dir '/data/data/com.anrapps.pixelbatterysaver/shared_prefs': No such file or directory. However when executing the ls command, it says that folder is present:
adb shell su -c "ls /data/data/com.anrapps.pixelbatterysaver"
cache
code_cache
files
shared_prefs
What is the problem? May be permission related?
If you're trying to copy a whole directory, you need to use cp -r to make it a recursive copy.

How to delete folders in sdcard of file explorer?

I created several folders in the sdcard (Eclipse) by running an Android application in the emulator. Now I want to delete the folders which I have created on the sdcard.
I am able to delete files in the folders but I could not delete the folders in the sdcard.
How can I do this? Is there a way to delete folders?
Using adb command you can delete folders.
click Run - > CMD-> type adb shell --> cd sdcard -> rmdir {dirname}
Note : Make sure your dir should be empty.
For non-empty directory use.
click Run - > CMD-> type adb shell --> cd sdcard -> rm -r {dirname}
Well, answer from Brijesh Thakur is really helpful.
I just tried this and it worked fine for me to some extent. I would like to mention that if your directory contains any files then the rmdir command will not work. You will have to use rm -r command for that.
To make it more easy for beginners I am explaining the process as follows.
First you need to locate your adb folder, mine was at D:\Android SDK\platform-tools>
Now execute adb shell in a command prompt as:
D:\Android SDK\platform-tools>adb shell
A hash (#) symbol or dollar sign ($) will appear, then enter the following command:
# cd sdcard
Now you are in the sdcard of the device. If your folder is a sub folder then further locate its parent folder using the cd command. Finally, use the rm -r command to remove the folder recursively as follows. This will delete all files and directories in the folder.
# rm -r FolderName
Please note that if you want to remove a single file you can use the rm command only and then the file name (with extension probably). And you can also use rmdir command if the directory you trying to delete is empty.
Using adb shell with rm command you can delete(nonempty as well as empty) folders.
click Run -- > CMD--> type adb shell --> cd sdcard --> rm -r {dirname}
We can do it in a single command line as under:
adb shell rm -r sdcard/<dirname>
If you want to delete everything in your android file system, you need to get its storage name from adb!
# adb shell echo $EXTERNAL_STORAGE
It will give you the path where everything is stored!It will print the storage name in command line, for few devices it is /sdcard and for few, it is /storage/emulated/legacy etc
Now you want to delete everything in that, you need
# adb shell rm -r /sdcard/
that /sdcard/ is not same for all devices, it could be /storage/emulated/legacy/ for some devices!
warning-: It will delete every folder in your file manager except "android" folder
now if you want to delete a particular folder in that file manager
# adb shell rm -r /sdcard/FolderName
remount the sdcard with read and write permission:
adb shell mount -o remount,rw /
Go to adb shell:
adb shell
Delete file you want:
rm -r /sdcard/file_name
It will work most better.

Categories

Resources