Absoluten Pfad mit dem Befehl "ls" erhalten

Ist es möglich, den absoluten Dateipfad beim Ausführen ls -lauf Android (z. B. über adb shelloder in einer Terminal-App) auszugeben?

Hier ist die Ausgabe, die ich bekomme ls -l /etc/(ich habe Root-Zugriff):

E:\Dropbox\Droid Explorer\src\main\resources\com\droid\explorer\adb>adb shell su root ls -l /etc/
-rw-r--r-- root     root        16656 2009-01-01 03:00 CHANGELOG-CM.txt
-rw-r--r-- root     root         9944 2009-01-01 03:00 CHANGES.txt
-rw-r--r-- root     root       154482 2009-01-01 03:00 NOTICE.html.gz
drwxr-xr-x root     root              2009-01-01 03:00 acdbdata
-rw-r--r-- root     root       598006 2009-01-01 03:00 apns-conf.xml
-rw-r--r-- root     root         5491 2009-01-01 03:00 audio_effects.conf
-rw-r--r-- root     root         6198 2009-01-01 03:00 audio_policy.conf
drwxr-xr-x root     root              2009-01-01 03:00 bash
drwxr-xr-x root     root              2009-01-01 03:00 bluetooth
-rw-r--r-- root     root       101774 2009-01-01 03:00 build-manifest.xml
-rw-r--r-- root     root         1045 2009-01-01 03:00 clatd.conf
drwxr-xr-x root     root              2009-01-01 03:00 dhcpcd
-rw-r--r-- root     root         1362 2009-01-01 03:00 ethertypes
-rw-r--r-- root     root        18300 2009-01-01 03:00 event-log-tags
-rw-r--r-- root     root        14309 2009-01-01 03:00 fallback_fonts.xml

Was ich bekommen möchte, ist der absolute Pfad, z.

E:\Dropbox\Droid Explorer\src\main\resources\com\droid\explorer\adb>adb shell su root ls -l /etc/
-rw-r--r-- root     root        16656 2009-01-01 03:00 /etc/CHANGELOG-CM.txt
-rw-r--r-- root     root         9944 2009-01-01 03:00 /etc/CHANGES.txt
-rw-r--r-- root     root       154482 2009-01-01 03:00 /etc/NOTICE.html.gz
drwxr-xr-x root     root              2009-01-01 03:00 /etc/acdbdata
-rw-r--r-- root     root       598006 2009-01-01 03:00 /etc/apns-conf.xml
-rw-r--r-- root     root         5491 2009-01-01 03:00 /etc/audio_effects.conf
-rw-r--r-- root     root         6198 2009-01-01 03:00 /etc/audio_policy.conf
drwxr-xr-x root     root              2009-01-01 03:00 /etc/bash
drwxr-xr-x root     root              2009-01-01 03:00 /etc/bluetooth
-rw-r--r-- root     root       101774 2009-01-01 03:00 /etc/build-manifest.xml
-rw-r--r-- root     root         1045 2009-01-01 03:00 /etc/clatd.conf
drwxr-xr-x root     root              2009-01-01 03:00 /etc/dhcpcd
-rw-r--r-- root     root         1362 2009-01-01 03:00 /etc/ethertypes
-rw-r--r-- root     root        18300 2009-01-01 03:00 /etc/event-log-tags
-rw-r--r-- root     root        14309 2009-01-01 03:00 /etc/fallback_fonts.xml

Antworten (3)

lslistet standardmäßig alles auf, was über Argument geliefert wird. Von man ls:

-d, --directory Verzeichnisse selbst auflisten, nicht deren Inhalt

-l Verwenden Sie ein langes Listenformat

Sie können also einfach alles in Ihrem Zielverzeichnis angeben und die Option -d.

[adb shell] [su -c] ls -dl /etc/*
^ optional, depending on your shell environment

Was gibt

rwxr--r-- 1 root root 1024 Jun 4 22:32 /etc/hosts
...
(and a lone list)

Da das Android gerootet ist, können Sie einen der folgenden Befehle verwenden:

# DIR durch den Pfad des Verzeichnisses ersetzen; Präfix adb Shell , wo immer es angebracht ist.

su -c 'busybox ls -ld DIR*'  
su -c 'Spielzeugkiste ls -ld DIR*'
su -c 'ls -d DIR*' # Dies funktioniert nicht mit dem langen Listenformat, das über -l verfügbar ist

(Mit freundlicher Genehmigung der Antwort hier von An̲̳̳drew für die Auflistung des Arguments -d ).

Android Marshmallow wird mit Toybox geliefert. Für jede andere Android-Version müssen Sie BusyBox oder Toybox einrichten .

Beispiel:

IMG

Ich vermute also, dass die ADB-Shell ls begrenzt ist. Verdammt, ich hatte gehofft, dies ohne busybox zu tun. Trotzdem danke

Sie können auch eine rekursive Listenfunktion in schreiben sh- diese Funktion kann ohne Root-Berechtigungen in kopiert und eingefügt werden adb shell:

function rcrls() { ls -d $1/* | while read f; do echo "$f"; if [ -d "$f" ]; then rcrls "$f"; fi; done }

Verwenden Sie es dann als:

shell@myphone:/ $ rcrls /

Leider bleibt es nur für die aktuelle adb shellSitzung bestehen, sobald Sie es verlassen haben, müssen Sie es erneut einfügen; oder du kannst es so verwenden:

$ adb shell 'function rcrls() { ls -d $1/* | while read f; do echo "$f"; if [ -d "$f" ]; then rcrls "$f"; fi; done } ; rcrls /' | less

Dann können Sie Dateien sehen, die wie folgt aufgelistet sind:

...
//acct/uid/1000
//acct/uid/1000/cgroup.clone_children
//acct/uid/1000/cgroup.event_control
//acct/uid/1000/cgroup.procs
//acct/uid/1000/cpuacct.stat
//acct/uid/1000/cpuacct.usage
...

Eine Auflistung mit Informationen zu erhalten -l, ist etwas schwierig, da sedan adb shell; Wir können jedoch die String-Variablen-Shell-Erweiterung und das Abschneiden verwenden, um den Basisnamen aus der Auflistung zu entfernen, und dann können wir den vollständigen Pfad anhängen:

function rcrls() { 
  ls -d $1/* | while read f; do 
    if [ -d "$f" ]; then 
       fl="$(ls -ld $f/)"; 
       echo "${fl%\ *}" "$f"; 
       rcrls "$f"; 
    else 
       fl="$(ls -l $f)"; 
       echo "${fl%\ *}" "$f"; 
    fi; 
  done 
} ; 
rcrls /

Oder als Einzeiler:

adb shell 'function rcrls() { ls -d $1/* | while read f; do if [ -d "$f" ]; then fl="$(ls -ld $f/)"; echo "${fl%\ *}" "$f"; rcrls "$f"; else fl="$(ls -l $f)"; echo "${fl%\ *}" "$f"; fi; done } ; rcrls /' | less

... und dann erhalten Sie eine Auflistung als:

drwxr-xr-x root     root              2017-11-15 02:29 //acct
-rw-r--r-- root     root            0 2017-11-15 02:29 //acct/cgroup.clone_children
--w--w--w- root     root            0 2017-11-15 02:29 //acct/cgroup.event_control
-rw-r--r-- root     root            0 2017-11-15 02:29 //acct/cgroup.procs
-r--r--r-- root     root            0 2017-11-15 02:29 //acct/cpuacct.stat
...