Re: How to remove all .DS_Store files using Terminal?



In article <140420062300433698%NoMailAccepted@xxxxxxxxxxx>,
Mark Conrad <NoMailAccepted@xxxxxxxxxxx> wrote:

In article <nospam.News.Bob-533D6D.21124314042006@xxxxxxxxxxxxxxxx>,
Bob Harris <nospam.News.Bob@xxxxxxxxxxxxxxxxxxxxxx> wrote:

In my Pismo with OS 10.4.6 there are 25,725 directories (folders), so
that means there are roughly the same number of .DS_Store files, one in
each directory.

My iBook only has 1389 .DS_Store files out of 109239 directories
(1.27 percent)

Most of the directories on the system are System, Library, caches,
etc... where either the Finder does not see, or you as a user do
not navigate to with the Finder. Hence no .DS_Store files

Thanks for straightening me out on that.

This is why these NGs are so great, any mis-conceptions get cleared up
by others who know more about the subject.


By the way, I found out how many .DS_Store files I had by using

locate .DS_Store | wc

Great tip, I will add that to my limited Unix arsenal, thanks.



of course I also have root run the nightly
/usr/libexec/locate.updatedb
job that updates the locate database, but that is a totally
different subject.

Sounds useful, but I thought that OS X had some mechanism that
periodically updated the 'locate' database?

Of course, if the auto' update feature does not work often enough, it
could be a bit useless whenever a 'locate' search was done.



Being the newest Intel based Macs no longer run Classic, it now appears
there is no reason to hang onto those .DS_Store files, so I would not
be surprised to see Apple abandon all those many thousands of .DS_Store
files, one .DS_Store file per directory, in future versions of their OS
- - - and replace them with some centralized method of doing the minor
things that are now being done by thousands of scattered .DS_Store
files.

I disagree. Mac OS 9 (and earlier) never used .DS_Store files, so
they are a MacOSX invention (or maybe a NeXT invention, but
definitely not Classic or Mac OS 9 or earlier).

Hokay, that's what I get for listening to gossip on the net.<g>



Whenever you delete a .DS_Store file, all the above things return to
default values, i.e. the icons jump to default locations in a window,
the window size itself jumps to a default size, and Spotlight
"comments" revert to blank (no comments).

Also, _no_ "new" .DS_Store file gets created, not even if you
restart your Mac.

Not even creating a new file will cause a new .DS_Store file to be
created, provided you do not move any icons in the window, or rezize
the window.

However, _if_ you move any icons, or change the window size, or
"automatically" re-arrange all the icons in the window, _then_ a
.DS_Store file gets created again.

So you just proved my point. There are not 1000's of .DS_Store
files on the file system. Just a thousand or so. Or just over 1%
of the directories contain .DS_Store files.

On my system all the .DS_Store files take up a total of 13MB. I
have more than that tied up in some graphics files or a long .mp3
music file. And since I have a 100GB disk (93 real GB), that is
0.01% of my disk storage). And if you disk is as small as 6GB
then this would be only 0.2%. This is noise and not a major
concern for me or most people.

I found out how much space my .DS_Store files were using via:
sudo find / -name ".DS_Store" -print0 |\
xargs -0 ls -s |\
awk '{size += $1} END{print size}'

Thanks very much for all that info', especially the last part about
finding how much disk space is being used for all the DS files.

I have a book about Terminal scripting on order, hope I can understand
the Unix stuff therein, when it arrives:
Mastering Unix Shell Scripting
by author Randal K. Michael

UNIX scripting is very powerful and flexible. A lot of its power
comes from piping the output of one command into another. For
example the following was one of the first UNIX spell checkers:

tr -C 'a-zA-Z' '\n' <file_to_spell_check |\
sort |\
uniq |\
comm -23 - /usr/share/dict/words

Each program was small (the most complex was most likely the sort
utility). And none of the programs in and of themselves have
anything to do with spelling or word processing per say. But line
them up in a pipeline and you have a rude and crude spell checker.
And in its day it was a very useful spell checker.

When I first saw this script, I was in totally amazed! I fell in
love with UNIX scripting then and there.

Now some comments about my little script. 'find' is extremely
useful, and I find that 'xargs' enhances 'find' a lot. And
knowing about find's -print0 and xargs' -0 options can be most
handly.

'find' has a lot of options. But for the most part, I've mostly
used the -name, the -type, and -xdev, options. I've used some
others, but less frequently than the above. And a lot of my
'find' usage is NOT for the entire disk. Generally it is just a
local directory or directory sub-tree. One useful trick to know
about 'find' is that many numeric arguments allow a leading + or -
to indicate greater than or less than the specified value. For
example:

find / -xdev -size +20480

will find all the files on your boot disk which are greater than
10MB (20480 * 512 == 10MB).

Enough about 'find'. In my "find / -name .DS_Store" example, I
had xargs run the "ls -s" command for each file found. "ls -s"
give the storage allocated to each file in 1K units. It looks like

16 .DS_Store

So this .DS_Store is 16K in size.

The output from the xargs and all the "ls -s" commands is piped
into an awk script.

Awk is a powerful small text manipulation language that looks a
lot like C, so C programmers like myself like. It is not as
powerful as Perl, or Python, Ruby, but I learned awk in '85 and at
that time there was no competition. It is also perfectly suitable
for this task.

awk '{size += $1} END{print size}'

Unrolling this a little bit

awk '
{ size += $1 }
END {
print size
}'

The script commands are located between the '...'

Awk executes the script for each line read.

The END statement only does something when the end-of-file is
detected (in our case when 'find' stops, it closes its side of the
pipe, which sends end-of-file to xargs; xargs then closes its end
of the pipe to awk, which sends end-of-file to awk).

Getting a little more general about awk. Each awk statement is of
the form

conditional expression { actions }

The conditional expression can be a search string as in /abc/ or a
regular expression (UNIX loves regular expressions), such as
/[a-zA-Z0-9]/. It can be something like $1 == "abc" or $3 < 27,
and it can be multiple exprssions. $2 > 6 && $3 != "Fred", etc...

If the conditional expression results in TRUE, then the Action is
performed.

If there is no conditional expression, then the action phase is
always performed.

The Action can look like a C program, with 'if' statments, print,
variable assignments, math, for loops, except that awk has much
better string handling than C.

If there is no action specified, then "print $0" is preformed. $0
is the entire input line. $1 is the first white space separated
word, $2 is the 2nd word, $3 is the third, etc...

So what my little script did, was to take all of the "16
..DS_Store", "24 .DS_Store", "4 .DS_Store", etc... input lines, and
add up the size fields, then as its last task before exiting,
print the total.

The following is a well written into to awk. You will still want
to read the man page. I think with this into, and the man page
you can write some very useful awk scripts:

Matching Patterns and Processing Information with awk
<http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/V51A_HTML/AR
H9WATE/WKXXXXXX.HTM>

I find your posting style very refreshing, because most Unix pros here
merely give vague broad hints on Unixy stuff, then expect me to do
_all_ the hard work of digging out the essential details.

You manage to work those details directly into your posts, which has
the benefit of actually showing us non-Unix types that Unix is good for
the practical everyday operation of a Mac.

If you every decide to write a Unix book, let me know so I can be the
first one standing in line for the book.

Anything written by Brian W. Kernighan. He is clear, brief, and
he includes short, clean and powerful examples, which actually
work in all his writings. I may not have read everything he has
written, but I do have most of the computer books he has published.

Time to go to lunch :-)

Bob Harris

About deleting .DS_Store files
*********************
But if you want to delete them, have fun.

Naw, as I stated near the start of this thread, my interest in the DS
files is just a matter of curiousity.
.



Relevant Pages

  • Re: How to rewrite with awk?
    ... > I'm unfamiliar with tools such as sed & awk. ... Extract the string that matches a RE. ... This script will not only expand all the lines that say "include ... file) and not resetting ARGV(the tmp file), it then lets awk do any ...
    (comp.unix.shell)
  • parsing multi-line print blocks
    ... The script below will parse an awk script and turn statements like this: ... It's part of a shell script designed to pre-process awk scripts so you can specify pre-formatted multi-line print statements in your awk scripts for generating code from templates. ... the tool attempts to detect and remove all common leading tabs so you can write your pre-formatted block indented with tabs so it looks good in your script without those tabs appearing in the output. ... # required because command-line awk scripts cannot contain single quote ...
    (comp.lang.awk)
  • Re: awk here documents
    ... script called from shell to produce some pre-formatted blocks of code ... awk variable: ... or awk quotes with shell quotes ...
    (comp.unix.shell)
  • Re: for loop (?)
    ... you should use awk variables in awk scripts instead ... >>of shell variables to avoid problems when those shell variables include ... I doubt if I've ever written a shell script that's robust ... > extra effort to make the script robust against weird inputs. ...
    (comp.unix.shell)
  • Re: How can I omit the filename I have to scan, which stays always the same.
    ... AWK-Script but a shell script. ... I suppose you could say that with the shebang, it is an AWK ... No, of course not, because bar.awk is not an awk script, it's a UNIX script. ... If I'm wrong and ALL OSes are required by some standard to know what a shebang is AND to understand "/"-delimited directory paths like UNIX does then please do let me know. ...
    (comp.lang.awk)