I am building a JAVA app that saves the output of bash commands into a list.
@root ~/a $ zipinfo -1 data.zip
a.txt
b.txt
test/
test/c.txt
root@ ~/a $ find .
.
./test
./test/c.txt
./b.txt
./data.zip
./a.txt
The idea is to compare files and directories from the zip to what is on the disk and remove any differences from the disk. In this example test/c.txt
should only be removed.
As you can see the format is different. Which command do I need to have the same style as zipinfo -1
?
I tried commands like:
ls -R
ls -LR | grep ""
find . -exec ls -dl \{\} \; | awk '{print $9}'
One way to remove the .
prefix is to use sed
. For example:
find . ! -name . | sed -e 's|^\./||'
The ! -name .
removes the .
entry from the list. The sed
part removes the ./
from the beginning of each line.
It should give you pretty much the same format as your zipinfo
, though perhaps not the same order.
Note: the above suggestion is compatible with both Linux and other unix versions such as MacOS X. On Linux specifically you can achieve the same result with:
find . ! -name . -printf "%P\n"
The -printf
predicate is specific to the Linux findutils, and the %P
format prints each found file, removing the search directory from its beginning.