Hacker News new | past | comments | ask | show | jobs | submit login
Better adb shell (github.com/matan-h)
100 points by matan-h 5 months ago | hide | past | favorite | 45 comments



Since adb rarely comes up on Hacker News, I got only one shot to ask how other Android uses deal with the problem of freeing up disk space without rooting the device or doing a factory reset? The number of apps is not the problem. Some apps or the OS must be filling directories with inaccessible temporary files or perhaps the OS is keeping all its old updates somewhere? On a 32M device 15 megs is lost over the course of a year. All the obvious user space tooling cannot clear or access it.


I gave into temptation and bought a device I can't root. Two years on, I'm resolved to never make that mistake again.


It's not physically possible to buy a device you can't root. You can however buy a device that is not easy to root.


You are aware Samsung encrypts the bootloader of their American devices, yes? If you have a way to decrypt Android 12+ Samsung bootloaders I know two separate people running unlock businesses who would love to pay you a lot of money.


I wouldn't tell you because I know people that pay more than your unlock businesses.


Always see the main folder Android inside /storage/emulated/0

Apps like Instagram or WhatsApp or even Podcast apps DUMP everything there. Many dont clear even if one uninstalls.


Each app also has its own private storage space as well at /data/data/<package name>/ which the end user cannot access even through adb. It's owned by the Unix user representing that app and has 700 perms so the `shell` user can't access it. While you can't access the directory directly, you can clear it in Settings -> Apps -> <app> -> Storage.


aka /sdcard on most phones


Maybe two options...

For any unprivileged user, find the bundled apps that are unused, uninstall updates, clear their storage, then disable them.

There is also a more thorough debloat method that does not require root. It seems to be in a state of flux as it is rewritten in Rust.

https://gitlab.com/W1nst0n/universal-android-debloater/-/blo...


Can adb show true android disk space usage without a rooted device? Either the Android system or some app is consuming half of my storage but I have no idea what or where it is. The missing storage doesn't even show up in the disk usage view and total app storage used is tiny by comparison.


I am on the latest LineageOS, and "df -h" does give me a lot of information, along with a reasonable figure for the device size under /storage/emulated.

I am using a ConnectBot local session to see this.

When I run this as root, the output of df is different, but it is not immediately obvious why.

If you can see the subdirectories, "du -sm *" will recurse and report usage by directory.


I was able to remove YouTube thanks to Canta + Shizuku. Unfortunately, the latest android OTA upgrade breaks canta. But I'm already free of YouTube and enjoying NewPipe \o/


In startup.sh, here are a few things to think about.

Instead of setting RED/GREEN/BLUE, you could do this:

  N=$(printf \\033)
  N="$N[" x=30

  for a in Bl R G Y B M C W  # Black Red Green Yellow Blue Magenta Cyan White
  do eval $a='$N'"'"$((     x))"m'" \
         b$a='$N'"'"$((60 + x))"m'" \
      ${a}bg='$N'"'"$((10 + x))"m'" \
     b${a}bg='$N'"'"$((70 + x))"m'" # bX=bright Xbg=background bXbg=brgt bgnd
     x=$(( x + 1 ))
  done                       # https://en.wikipedia.org/wiki/ANSI_escape_code
Unless you have "set -e" this:

  if [ ! "$HOSTNAME" ]; then
    HOSTNAME="$(hostname -s)"
  fi
Is more succinctly expressed as this:

  [ -z "$HOSTNAME" ] && HOSTNAME="$(hostname -s)"


Apart from the length, what advantages does `[-z $VAR ] && VAR=x` over `if [ ! $VAR ]; then VAR=x fi` ?

Btw, The color script is cool. This makes ANSI sensible.


I don't think there are any functional or performance differences between these forms:

  [ -n "$var" ] || var=X
  [ -z "$var" ] && var=X
  if [ ! "$var" ]; then var=X; fi
It's a question of [your] style and taste, I think.

There are a lot more ANSI sequences that I could work into that block, but it is quite thorough for the space it occupies.

BONUS:

Here is my script to extract all of the stored WiFi networks and passwords when run as root:

  #!/bin/sh

  find /data \
      -name WifiConfigStore.xml \
      -print0 |
  xargs -0 awk '

    /"SSID/ { s = 1 }
    /PreShared/ { p = 1 }

    s || p {
      gsub(/[<][^>]+[>]/, "")
      sub(/^[&]quot;/, "")
      sub(/[&]quot;$/, "")
      gsub(/[&]quot;/, "\"")
      gsub(/[&]amp;/, "\\&")
      gsub(/[&]lt;/, "<")
      gsub(/[&]gt;/, ">")
    }

    s { s = 0; printf "%-32.32s ", $0 }
    p { p = 0; print }

  ' | sort -f


If -e is set you can use || and invert the condition.


Still trying to find a functional tool that makes it easy to take full backups and restore them to android devices since adb deprecated the "backup" command


I don't think such a thing exists right now. I've been looking for it.

The best normie backup tool is probably Neo Backup on F-Droid, and it's buggy and lacks some important features. Titanium is dead. I've not been satisfied with any of the various closed-source paid apps on the Play Store.

Any true backup is going to require rooting your phone. It's not in google's interest to allow you, the user, to access core operating system files and configuration on their device.

If you don't 0wn it, you don't own it.

Here's what I do.

I install Magisk and the MagiskSSH module. This gives me a root ssh shell and I can rsync any file on the device, selinux context and all.

The system requires some excludes for remounted/mirrored directories, and then there's other things like cache directories that I don't need to backup, so I use a rsync filter file. rsync's --link-dest makes backups very very fast and reduces disk usage. I should really do this on a filesystem that does block-level de-duplication, but I don't really need to because it's efficient enough already. Each app has to be paused/frozen during the backup to ensure data integrity.

Restoring requires a bunch of hacky scripts. It's not pretty, but it works.

I have to send over the apk file and use Android's native "pm install" to install it from /data/local/tmp. There's some cases where this doesn't work and I have to install the app manually from the store or wherever (APEX and other mutli-apk crap).

Then my script freezes/disables the app, wipes the local data, copies the backup data, fixes the ownership, unfreezes the app, and it mostly usually sometimes works.

Figuring out all the commands to do this, like getting the AIDs of apps, is some dark art shit. I've been doing this since the very beginning on a G1.

Maybe some day I'll put my scripts out there and it will inspire someone to pick it up and make them easier to use, but it's never going to be a real solution.

Someone just needs to make a real backup app for Android.


Titanium Backup has been working fine for me to backup and restore various apps. Are there features missing or problems with TB's implementation on modern Android versions?


There are very well-known problems with Titanium Backup not being able to backup/restore newer APEX and multi-part APK types. It can also cause system configuration corruption/resets on certain special/meta backup items. Google for more info.

It may not even run on some Android 13 and later devices due to a common error of not being able to detect root status.

Google for more info.


if you use an AOSP based ROM, give Seedvault another look since they merged device2device-transfer in the beginning of the year https://github.com/seedvault-app/seedvault/pull/562


Seedvault is not a good backup solution. The devs who promote it don't have a lot of credibility. It basically doesn't work half the time and they know it, but pretend it's great to pad their resumes.


did you base your impression for 'half the time' on a version that can't skip the allowBackup=False app manifests via d2d ?


Even the core LineageOS and Graphine devs spend time disparaging it on reddit and twitter with comments like "It's not a very good app." and "Unfortunately Seedvault is still unreliable." Those are direct quotes.

I think it was back on LineageOS 16 that it was actually broken for the entire release. It wasn't even possible to do a basic backup at all.

Google for "site:reddit.com does seedvault even work" for dozens and dozens of examples.


why pad my opinions with outdated quotes if I can have first-hand experience? it's a good tip I gave on recent developments and your objections aren't convincing. Latest Lineage/Graphene both include in their forked seedvault repos a current enough version to check out d2d-transfer, give it another try.


This is similar, but actually gives you additional tools and a statically compiled bash: https://github.com/wowsignal-io/android-tools


Seems to be tailored specifically for Apple Silicon Macs, considering that it attempts to spin up an AArch64 Docker container to compile some of its tools.


"rmtree" and "untar" look too much like:

  #define BEGIN {
When on Unix, do as Unixers do.


Given that unzip and unxz exist, untar isn't that unreasonable.


Of note of course is termux, which is a proper terminal, complete with a custom apt repo.

For cases where an adb shell is needed (modify external storage, slightly more permissions if not rooted) it's approximately possible to just copy necessary executables and .so files from termux to /data/local/tmp/ for adb (with some LD_LIBRARY_PATH & co setup), allowing running bash, htop, etc.


I use this to copy programs from termux.

in termux (you need lld [pkg i lld]):

   mkdir /sdcard/.adb
   cp `which bash` /sdcard/.adb
   cp $(ldd `which bash`|cut -d ">" -f2) /sdcard/.adb
in adb shell:

   cd /data/local/tmp
   cp /sdcard/.adb/bash
   cp /sdcard/.adb/*.so
   LD_LIBRARY_PATH=.
   ./bash


> one alias to fix the typo sl => ls.

I'm wondering what others think about such feature (in general, not just in this specific case).

On one hand, it won't negatively affect my personal usage in anyway, probably even beneficial; On the other hand, the "purist in me" feels very uncomfortable with this kind of features (probably to the detriment of myself).

Again, this is not a complainant at all. Just find it interesting.


Or, just install sl!

https://www.cyberciti.biz/tips/displays-animations-when-acci...

Personally I have sl aliased to sl=sl && ls to make sure I break the habit of ever typing sl.

(Though also usually I'm typing ll which I have aliased to an ls with list mode and many details)


I have a magic enter plugin that just runs 'll' when I input no command and press enter, I haven't typed ll in months!


It's not for me. I can see the appeal of these shortcuts, but I can see it being a wtf down the road once I've forgotten that I have them in place.

Also with something like auto-correct, you have a visual affordance that alerts you to the change (with the option to override), which just happened when I misspelled 'forgotten' above. The shell doesn't have that so something just happens without any actual correction or indication the user may have made an error. Although I am not a 'fish' user, this is something that I think it does well.


As an aside, mksh hasn't been updated since 2020.

This is not as bad as ksh93, but it is starting to look more like abandonware, implying that oksh is healthier.

http://www.mirbsd.org/mksh.htm


No new release doesn't mean abandonware though, upstream last commit was 2 weeks ago.


I feel as though I am a dying breed, as nothing about this seems "better" than the default. The PS1 is enriched with information, sure, but I find it very distracting. I much prefer $ or #.


Do you never look at your scrollback, or a command+result pasted into a text file? I find it useful to include the context of working directory and timestamp, adjacent to the command.


I ended up just resorting in bash with an exec bash inside my mkshrc iirc.

I switched to nushell a couple of months back and I haven't got the opportunity to rock it on android, really curious how it does.

It is supposed to support android as well if I'm not mistaken.


I've tried it. nushell works for me only with the "-c" option, otherwise I get "Error: I/O error: Function not implemented (os error 38)". Probably the prompt function



  $ adb hell
  adb: unknown command hell


From one of the SO comments: https://android-review.googlesource.com/c/platform/system/co...

It was removed :(

Kinda funny that the commit message doesn't say anything like "remove hell mode", it's integrated into another unrelated patch


adb lolcat and adb longcat are also neat ones




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: