Terminal command to arrange all files/folders by name on hard drive Looking to tidy up my iMac.

Like everyone, I have lots of files/folders on my iMac. When they get dragged and dropped, or moved around, they retain their position, and the only way to fix this is to right click on the mouse select 'Clean up By' > 'Name'

I'm wanting to run a script in Terminal (or similar) that will do this to every file/folder on my iMac

E.g.
Directory X contains four files

ABC99, ABC45, ABC32, ABC01

After running the script, the folder should contain the same files but in the correct order

ABC01, ABC32, ABC45, ABC99
Deleting .DS_Store SHOULD reset the appearance of a folder's content. 

BTW, the problem with the other answer could be the handling of special characters, which in my guess is space. 

For example, you have a home directory named "First Last". In find, the result it pipes out would be:

/Users/First Last/.DS_Store


etc. Try,

rm /Users/First Last/.DS_Store


would end in error, because the two properly escaped forms are:

rm  /Users/First\ Last/.DS_Store


or

rm "/Users/First Last/.DS_Store"


The correct way to go about it should be: run

find / -name ".DS_Store"


first to list all .DS_Store files. (Don't mind the Permission Denied.) Then

find / -name ".DS_Store" -delete


to delete all that you saw. Then

find / -name ".DS_Store"


again to confirm.

sudo is excessive. Unless you have used "sudo open -a Finder; killall Finder" before. A user's Finder has not have permission necessary to create .DS_Store files in /Library, /System, etc.