0

I'm using Bash on Ubuntu on Windows to run linux commands on my windows system. It seems to work just like Ubuntu so for all intents and purposes I'm on ubuntu here I guess.

I'm trying to use strings to dump all the strings across a bunch of files in a directory/its subdirectories to a single file.

I'm using this thread as a guide

Only problem is my results will typically generate outputs that are tens of gigabytes in size (before I kill the program) that seem to come from infinite loops of copying the same files over and over again.

This is what I've tried:

> strings -e S ./* > all.bin.jp.txt 
> strings -e S ./** > all.bin.jp.txt
> find . -type f -exec strings -e S {} \; >> all.jp.txt 
> find ./* -type f -exec strings -e S {} \; >> all.jp.txt 
> find . -type f -exec strings -e S {} \; > all.jp.txt 
> for file in ./*; do strings -e S "$file" >> all.bin.txt; done 
> for file in ./**; do strings -e S "$file" >> all.bin.txt; done 
> for file in ./*/*; do strings -e S "$file" >> all.bin.txt; done

I don't remember which command did it but I think the last one actually finished and gave me a file that was a few gigabytes, even though it opened easily in Notepad++. But I noticed that like 70% of that file was the same line repeated over and over again.

I've run these commands INSIDE the directory I want to get all the files, and all the files from the subdirectories, from. E.g.,

Parent Directory
--Directory of Interest
---file1
---file2
---subdirectory1
------fileA1
------fileA2
---subdirectory2
------fileB1

So from Parent Directory I type cd Directory of Interest, and then I run the command, and I want everything from file1, file2, fileA1, fileA2, and fileB1 to be dumped to a single file also inside Directory of Interest, at the same level as file1 and file2.

I'm also confused about what level to execute the command at. I don't actually care where I execute the command or if the file gets placed e.g. directly inside Parent Directory - this is just what I've tried. I don't usually have trouble running strings on all files in the current directory, using commands like the below inside the directory with all the files of interest but this subdirectories thing has me stumped.

strings -e S . > all.bin.jp.txt
strings -e S *.bin > all.bin.jp.txt

Please help me! I remember this used to work when I tried it before, but I don't remember the exact command I used. I've tried it on a couple different directories with the same types of files I've used this command on before, but it won't work for any of them, so I don't know what's wrong.

3

The find command works fine, you only need to exclude all.jp.txt from the list of files to be found or redirect the output to a different directory, i.e. not . or one of its sub-directories. Otherwise strings also runs on all.jp.txt and grows and grows.

find . -type f ! -path ./all.jp.txt -exec strings -e S {} \; > all.jp.txt

or

find . -type f -exec strings -e S {} \; > /some/other/dir/all.jp.txt
  • Thank you!!!! It seems to work up to a certain level of depth. Do you know what maxdepth is by default? I just put -maxdepth 5 – weirdalsuperfan May 10 '20 at 20:09
  • There is no limit if you don't specify -maxdepth, it descends all sub-directories from the starting point. – Freddy May 10 '20 at 20:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.