I have following command to get file date with time
adb shell ls -l /sdcard/sample.txt
Result of this command :
-rwxrwxr-x system sdcard_rw 676 2013-09-24 11:23 sample.txt
Now, I want 2013-09-24 11:23 time with seconds as well. like 2013-09-24 11:23:11
How I will get file modification date including seconds.
Thanks.. :)
If you have a stat command:
stat -c %y /sdcard/sample.txt
Seconds since Epoch
stat -c %Y /sdcard/sample.txt
By tweaking the code posted, I was able to get it worked using this command :
adb -d shell ls -l time-style="+%Y-%m-%d %H:%M:%S" path_to_file_in_device
The output is :
-rw-rw-r-- root sdcard_rw 22357385 2013-09-25 22:42 launcher.apk
ls -l --time-style="+%Y-%m-%d %H:%M:%S" /sdcard/sample.txt
Related
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.
I'm writing a shell script in Android.
I need to determine the name of the owner of an app's data directory, assign it to a variable and change the owner of another directory (which happens to be a sub-directory of the first directory) to the owner of the first directory using a variable.
#assign the owner of the com.netflix.mediaclient to $user variable
user=`su -c "ls -l /data/data | grep com.netflix.mediaclient | cut -f2 -d' '"`
#change the owner of the shared_prefs directory to the value in $user variable
su -c 'busybox chown -R '$user:$user' /data/data/com.netflix.mediaclient/shared_prefs'
This and many other variations of the syntax of the second line does not work.
#using double quotes
su -c 'busybox chown -R "$user:$user" /data/data/com.netflix.mediaclient/shared_prefs'
#using no quotes
su -c 'busybox chown -R $user:$user /data/data/com.netflix.mediaclient/shared_prefs'
Use stat to find the owner and put $user:$user inside double quotes
user="$( busybox stat -c '%U' /data/data/com.netflix.mediaclient )"
busybox chown -R "$user:$user" /data/data/com.netflix.mediaclient/shared_prefs
Why '$user:$user' will not work?
Anything put inside the singles quotes are taken literally by bash and variable expansion will not occur.
So I'm developing an android app. It uses IR blaster to send signals to TVs and other stuff. It worked fine on CyanogenMod 11(Android 4.4.4) but after updating to CyanogenMod 12(Android 5.0) it stopped working. App is assessing these files: /dev/ttyHSL2 and /sys/devices/platform/ir_remote_control/enable . Normally their permissions are ok, but after updating they are "ok" but not ok :/ :
05-09 23:44:02.980 28282-28340/com.sssemil.ir E/libsonyir﹕ IRpowerOn : Error opaning power node /sys/devices/platform/ir_remote_control/enable error : Permission denied
05-09 23:44:03.981 28282-28340/com.sssemil.ir I/libsonyir﹕ IRserialOpen : CALLED
05-09 23:44:03.991 28282-28340/com.sssemil.ir E/libsonyir﹕ IRserialOpen : Error opaning serial device /dev/ttyHSL2 error : Permission denied
So I've tried to fix them:
su -c "chmod 222 /sys/devices/platform/ir_remote_control/enable"
su -c "chmod 666 /dev/ttyHSL2"
Still same errors. Then I've tried this:
su -c "chmod 777 /sys/devices/platform/ir_remote_control/enable"
su -c "chmod 777 /dev/ttyHSL2"
Still nothing... I've checked permissions and they were ok:
shell#odin:/ $ su -c "ls -l /dev/ttyHSL2"
crwxrwxrwx system system 244, 2 2015-05-09 22:27 ttyHSL2
shell#odin:/ $ ls -l /sys/devices/platform/ir_remote_control/enable
-rwxrwxrwx system system 4096 2015-05-09 22:27 enable
So if there are any ideas please help me. My app is open source so here is source code if you need it https://github.com/sssemil/android_packages_apps_IRRemote .
Thanks.
So, to fix it type: su -c "setenforce 0"
Can anyone tell how can I get the PID from the output of PS command in Android shell.
For example from the output:
u0_a51 20240 38 132944 22300 ffffffff 40037ebc S com.example.poc_service
pid value 20240 is to be got. I tried
ps -ef | grep com.example.poc_service
but to no avail. Also pgrep is not being recognized.
If you have shell access in Android you can also use pidof:
# pidof com.example.poc_service
20240
However, be careful as there may be multiple processes matching...
Its pretty nasty but it works:
for pid in `ls /proc`; do
cmd=`cat $pid/cmdline 2> /dev/null`;
if [ "X$cmd" == "Xcom.example.poc_service" ]; then
echo $pid;
fi
done
or as one line:
for pid in `ls /proc`; do cmd=`cat $pid/cmdline 2> /dev/null`; if [ "X$cmd" == "X/system/bin/mm-qcamera-daemon" ]; then echo $pid; fi done
Neither grep, egrep, fgrep, rgrep is available in Android.
If you are working on Unix, Linux, Mac or Cygwin, you can pipe the output of adb shell command to get the result you want.
$ adb shell ps |grep settings
system 23846 71 111996 22676 ffffffff 00000000 S com.android.settings
$ adb shell ps |grep settings |awk '{print $2}'
23846
So I am currently connected to my android phone using adb shell. When I do "stat file"
I get this message:
stat: not found
Do I need to install this script or what? Im on a 2.3.4 Gingerbread.
stat does not come with Android/AOSP.
If you run ls /system/bin you will get a list a lot shorter than what you are probably used to being able to do in most *NIX environments:
ATFWD-daemon
abcc
adb
am
app_process
applypatch
atrace
bdAddrLoader
bmgr
bootanimation
bridgemgrd
btnvtool
bu
bugreport
cat
chcon
chmod
chown
clatd
clear
cmp
conn_init
content
cp
dalvikvm
date
dd
debuggerd
dexopt
df
dhcpcd
diag_klog
diag_mdlog
dmesg
dnsmasq
drmserver
ds_fmc_appd
du
dumpstate
dumpsys
e2fsck
efsks
fsck_msdos
getenforce
getevent
getprop
getsebool
grep
gzip
hci_qcomm_init
hd
hostapd
id
ifconfig
iftop
ime
input
insmod
installd
ioctl
ionice
ip
ip6tables
iptables
keystore
kill
ks
linker
ln
load_policy
log
logcat
logwrapper
ls
lsmod
lsof
make_ext4fs
md5
mdnsd
media
mediaserver
mkdir
mksh
mm-qcamera-daemon
monkey
mount
mpdecision
mtpd
mv
nandread
ndc
netcfg
netd
netmgrd
netstat
newfs_msdos
nl_listener
notify
ping
pm
port-bridge
pppd
printenv
ps
qcks
qmuxd
qseecomd
racoon
radish
reboot
renice
requestsync
restorecon
rild
rm
rmdir
rmmod
rmt_storage
route
run-as
runcon
schedtest
schedtop
screencap
screenshot
sdcard
sendevent
sensors.qcom
sensorservice
service
servicemanager
setconsole
setenforce
setprop
setsebool
settings
sh
sleep
smd
start
stop
surfaceflinger
svc
sync
system_server
tc
thermald
toolbox
top
touch
uiautomator
umount
uptime
usbhub
usbhub_init
v4l2-qcamera-app
vdc
vmstat
vold
watchprops
wipe
wm
wpa_supplicant
No stat, as you can see. If you have root privileges, a simple solution is to install something like BusyBox which adds some such bread-and-butter scripted functions as stat to your environment:
[
[[
acpid
addgroup
adduser
adjtimex
ar
arp
arping
ash
awk
basename
beep
blkid
brctl
bunzip2
bzcat
bzip2
cal
cat
catv
chat
chattr
chgrp
chmod
chown
chpasswd
chpst
chroot
chrt
chvt
cksum
clear
cmp
comm
cp
cpio
crond
crontab
cryptpw
cut
date
dc
dd
deallocvt
delgroup
deluser
depmod
devmem
df
dhcprelay
diff
dirname
dmesg
dnsd
dnsdomainname
dos2unix
dpkg
du
dumpkmap
dumpleases
echo
ed
egrep
eject
env
envdir
envuidgid
expand
expr
fakeidentd
false
fbset
fbsplash
fdflush
fdformat
fdisk
fgrep
find
findfs
flash_lock
flash_unlock
fold
free
freeramdisk
fsck
fsck.minix
fsync
ftpd
ftpget
ftpput
fuser
getopt
getty
grep
gunzip
gzip
hd
hdparm
head
hexdump
hostid
hostname
httpd
hush
hwclock
id
ifconfig
ifdown
ifenslave
ifplugd
ifup
inetd
init
inotifyd
insmod
install
ionice
ip
ipaddr
ipcalc
ipcrm
ipcs
iplink
iproute
iprule
iptunnel
kbd_mode
kill
killall
killall5
klogd
last
length
less
linux32
linux64
linuxrc
ln
loadfont
loadkmap
logger
login
logname
logread
losetup
lpd
lpq
lpr
ls
lsattr
lsmod
lzmacat
lzop
lzopcat
makemime
man
md5sum
mdev
mesg
microcom
mkdir
mkdosfs
mkfifo
mkfs.minix
mkfs.vfat
mknod
mkpasswd
mkswap
mktemp
modprobe
more
mount
mountpoint
mt
mv
nameif
nc
netstat
nice
nmeter
nohup
nslookup
od
openvt
passwd
patch
pgrep
pidof
ping
ping6
pipe_progress
pivot_root
pkill
popmaildir
printenv
printf
ps
pscan
pwd
raidautorun
rdate
rdev
readlink
readprofile
realpath
reformime
renice
reset
resize
rm
rmdir
rmmod
route
rpm
rpm2cpio
rtcwake
run-parts
runlevel
runsv
runsvdir
rx
script
scriptreplay
sed
sendmail
seq
setarch
setconsole
setfont
setkeycodes
setlogcons
setsid
setuidgid
sh
sha1sum
sha256sum
sha512sum
showkey
slattach
sleep
softlimit
sort
split
start-stop-daemon
stat
strings
stty
su
sulogin
sum
sv
svlogd
swapoff
swapon
switch_root
sync
sysctl
syslogd
tac
tail
tar
taskset
tcpsvd
tee
telnet
telnetd
test
tftp
tftpd
time
timeout
top
touch
tr
traceroute
true
tty
ttysize
udhcpc
udhcpd
udpsvd
umount
uname
uncompress
unexpand
uniq
unix2dos
unlzma
unlzop
unzip
uptime
usleep
uudecode
uuencode
vconfig
vi
vlock
volname
watch
watchdog
wc
wget
which
who
whoami
xargs
yes
zcat
zcip
Great stuff - you won't need any computer but your phone, anymore!
the stat command is not available on the device. There is a very limited set of commands available. They are listed here:
http://developer.android.com/guide/developing/tools/adb.html
What are you trying to do?