
Fancy Mac OS X command line tricks
A reader writes:
"I figured that this would be right up your alley. If I want to move any document that contains "agreen" to another folder, what commands would I use on the command line?" find . -print | xargs grep -il "agreen"would produce a list of all files from the current point in the file system "down" (e.g., within this subdirectory), so wrap that in a for loop and you have something like: target="~/newdir"You'll want to make sure that 'newdir' exists first, or the 'mv' will successively step on and remove all of your files. Maybe a safer snippet would be: target="~/newdir"There! That should do the trick.
Help others find this article at Del.icio.us, Digg, Netscape, Reddit, and Stumble Upon
Categorized:
Mac OS X Help
(Article 3654)
Tagged: Previous: How do you edit your existing Web pages on a remote server? Next: Changing Link Colors on an HTML page Subscribe!
Never miss another useful Q&A article again! Subscribe to AskDaveTaylor with Google Reader. -print???? Why? It's pointless. Banish it from your mind. How about this? It works fine for reasonable values of x: for x in `find . -exec grep -l agreen {} \;` Commentary: I add a -i option to mv because if there are 5 different files found that all have the same name, you may not want to end up with just the last one. Notice my use of a trailing / on the directory name. If the directory doesn't exist, you just get error(s). Example: To explain the form I am using, putting commands in back ticks makes the shell evaluate that command first and put its output in the command's place. This also means it finds all the filenames THEN acts on them, preventing the situation where the file is found again after being moved. Posted by: Brian Excarnate at February 21, 2007 10:11 PMI have a lot to say, but ...
I do have a comment, now that you mention it!
|
![]()
Search
Find just the answers you seek from among our 1700+ free tech support articles by using our Lijit search engine.
Help!
Subscribe to
Ask Dave Taylor!
Free Updates!
Sign up and get free weekly updates and special offers on books, seminars, workshops and more.
Articles and Reviews
Auctions and Online Shopping Blogs and RSS Feeds Building Web site traffic Business and Management Cell Phones and Mobile Phones CGI Scripts and Web Site Programming Computer and Internet Basics d) None of the Above HTML and CSS Mac OS X Help MySpace, Facebook, Twitter and Social Network Help Pay Per Click (PPC) Search Engine Optimization Shell Script Programming Sony PSP, MP3 Players, Etc. The Writing Business Unix and Linux Help Video Game Tips and Help Windows Help
Recent Entries
Join the List!
Book Links
|