Nexeu
January 23, 2020, 9:43pm
1
I am trying find files in sub dir with certain tags using tag command, and add the period to the beginning. I can't use chflags hidden {} cause it doesn't add period to the beginning of the string for web purpose. So far with my knowledge, I only know mdfind or tag can be used to search files with tags in Mac OS x.
my current closest command is this (doesn't work):
tag -f "Note" . | xargs -0 {} mv {} .{}
Hi,
in order for xargs to use NUL character as separator, the utility before the pipe needs to produce them.
try:
mdfind -0 -onlyin . "Note" | xargs -0 -I {} echo {}
or
tag -0 -f "Note" . | xargs -0 -I {} echo {}
1 Like
Nexeu
January 24, 2020, 1:40am
3
Hi Scrutinizer,
Thanks for the quick response.
for tag command :
tag -0 -f "Note" . | xargs -0 -I {} echo {}
It only echo out a list of files including directories. Something like this /dir/dir/dir/file.ext.
So when I try to do:
tag -0 -f "Note" . | xargs -0 -I {} rename -n 's/^/\./' {}
the out put came out like :
'/dir/dir/dir/file.ext' would be renamed to './dir/dir/dir/file.ext'
but I want the result to be :
'/dir/dir/dir/file.ext' would be renamed to '/dir/dir/dir/.file.ext'
For mdfind, I modified the code to be like this to echo out the list:
mdfind -0 "kMDItemUserTags == 'Note'" | xargs -0 -I {} echo {}
But still no luck of adding '.' to the file only at the beginning.
If you use this:
s/^/\./
Then the .
is added at the beginning of the path.
To add it to the last item in the path, try:
s|.*/|$0/.|
1 Like
Nexeu
January 24, 2020, 2:21am
5
I tired :
tag -0 -f "Note" . | xargs -0 -I {} rename -n 's|.*/|$0/.|' {}
It starts to add the '.' to the file, however it removed out the subdirectory completely like this:
'/dir/dir/dir/dir/file.txt' would be renamed to '/usr/local/bin/rename/.file.ext'
Nexeu
January 24, 2020, 3:28am
7
It works! Thank you so much Scrutinizer!
So the solution is as follows:
tag -0 -f "Note" . | xargs -0 -I {} rename 's|(.*)/|$1/.|' {}
3 Likes