-2
/volume1/Folder/0000/AAA/one
/volume1/Folder/0001/AAA/two
/volume1/Folder/0001/BBB/three
/volume1/Folder/0002/CCC/four
...

I want to get a .txt file, with all not-empty folders directories. But I want this file to write without the /volume1/Folder/, ie, I want to print it like this :

0000/AAA/one
0001/AAA/two
0001/BBB/three
0002/CCC/four
...

This is the code that I'm using, but this is writing the full path (and I know that by adding -printf '%f\n' it writes only the last folder, but I don't want that!)

 find /volume1/Folder/* -mtime -1 -type d -maxdepth 2 -not -empty > /volume1/Folder/NotEmptyFolders.txt

Can someone help me?

blocnt
  • 73
  • 1
  • 8

1 Answers1

0

Try this if you do not want to pipe the output to another command like sed

find /volume1/Folder/* -mtime -1 -type d -maxdepth 2 -not -empty -exec bash -c 'echo ${0#/volume1/Folder/}' {} \; > /volume1/Folder/NotEmptyFolders.txt

But this again creates a new shell (bash -c) and rather you could do | and use other commands like sed/awk to remove /volume1/Folder/

Fazlin
  • 2,285
  • 17
  • 29
  • Cool, it works. The only problem is that it is writing all pathes without making a new line for each one. Do you know how to fix it? – blocnt Jul 01 '16 at 14:02
  • It is prefarable to use sed/awk over find, in this case? – blocnt Jul 01 '16 at 14:03
  • Did you see everything in same line after redirecting the output to file or you assigned everything to variable – Fazlin Jul 01 '16 at 14:05
  • I'm not sure I understand your question. I'm not using a cmd line, I'm using a task scheduler, so I cant check without writing in the output. With the code of the main article it was writing all pathes in different lines, and with yours not, they are all in the same – blocnt Jul 01 '16 at 14:20
  • I have updated my change to redirect the output to the file (similar to your original code).. Check with the update code.. – Fazlin Jul 01 '16 at 14:27
  • and BTW if you are happy with the answer, make this as accepted answer. – Fazlin Jul 01 '16 at 15:07