Determining what versions of WordPress you are hosting
August 10, 2010
If you host lots of different sites for people, one of the things you might want to know is what versions of WordPress each site is running.
WordPress stores the version number in a variable named $wp_version which is set in the file version.php.
With that information in hand, you can write a bash command that you run from your /home directory to display all of the WordPress versions you have on your server:
find . -name version.php -type f|xargs grep ^\$wp_version
This is one of the aliases I have in my .bashrc file.
Three helpful additions to your .bashrc
June 21, 2010
I just made a change to my .bashrc file and I thought I would share the tip. All of this is pretty basic stuff, but if you don’t customize your linux logins, this would be a good place to start.
For Microsoft people who don’t know, .bashrc is in some ways like a combined config.sys and autoexec.bat file. If you don’t know what an autoexec.bat file is, you totally missed the 80s dudes…
In a *nix environment, the rc at the end of a file name typically means that it is a “run control” file. Run Control files execute when a program starts. In this case, the program is bash – the command line interpreter/shell. Other programs look for rc files too. Because of this, you could have bunches of them in your home directory. The . at the front of the file name indicates that they are hidden from a normal directory listing. This way they don’t clutter up your home.
I have lots of neat things in my .bashrc file that add functionality to my default CLI. I’ll be sharing just three of those with you now.
The first is an alias: ebrc. When I type ebrc and press enter, I’m taken immediately into an editor with my .bashrc file open. You can think of an alias as a single line shortcut. It looks like this:
alias ebrc='vi ~/.bashrc'
As you can see, it just says “when I type ‘ebrc’, treat it like I really typed ‘vi ~/.bashrc’”.
The second thing I used tonight was the alias brc:
alias brc='. ~/.bashrc'
That executes the .bashrc file again, so that all of the changes I’d just made are loaded.
You might ask “Can’t you just type all that out? You’re not saving much time.” Go ahead.. ask. I’ll wait…
OK. The answer is Yes. So, it is important that you don’t go overboard on this stuff. If you use aliases too much, you’ll lose your familiarity with *nix and the skills to do your work on any other server. So proceed with caution. This stuff can be addictive and detrimental to your guru health.
Now with those two helper aliases in hand, I added the function I really wanted to include: ‘upskel’. It takes a task I might otherwise put off and allows it to be completed in 7 keypresses. This is the perfect use case for a .bashrc function.
‘upskel’ takes the latest version of WordPress and places it into the cpanel skeleton directory that is used as the base for every new account created on my hosting service eHermits, Inc.. So, every time an update comes out for WordPress, I can spend 5 seconds to grab the latest and all new accounts I create will be safe and updated.
Unlike an alias, this is done through a function call. Functions allow the use of multiple lines and variables. Here is the call I just added:
function upskel() { cd /root/cpanel3-skel rm -R public_html rm latest.zip* wget http://wordpress.org/latest.zip unzip latest.zip mv wordpress public_html }
Technically I probably could have done that as an alias but a function is much easier to read with multiple lines involved.
As a bonus, here is a function that takes a variable:
function ewpc() { cd /home/$1*/ pwd sudo vi ./public_html/wp-config.php }
Can you tell me what it does?
Using find to copy specific files on linux
June 2, 2010
I was faced with a weird copy command I wanted to do today; so I thought I would share.
How do you copy files in a directory tree to another directory?
I wanted to copy all of the mp3 files in a directory tree over to one specific target directory.
Initially I thought the command
cp -r *.mp3 /target/directory/
would work, but even though it specifies the –recursive option, it does not iterate the subdirectory looking for the mp3 files.
So I resorted to my every faithful companion: find -exec. It seems like this is one of the most useful tools in linux. In this case, here is the command line I used:
find . -type f -name ‘*.mp3′ -exec cp {} /targetdirectory/ \;
How to: Find files edited in the last day
February 15, 2010
The process is straight forwarded. There are several methods:
find . -mtime -1 \! -type d -exec ls -l {} \;
Or more simply
find . -type f -mtime -1
In my case, I wanted to do more. First since I was searching an SVN repository, I wasted to exclude all of the extra files that are touched by SVN. Additionally, the goal was to show which files contained a print_r function.
Here’s what I came up with:
find . -path '*/.svn/*' -prune -o -type f -mtime -1 \
-exec echo '{}' \; -exec grep print_r {} \;
Hope that helps!
Getting the error ‘cannot move – to a subdirectory of itself’?
August 19, 2009
This error message always bothered me because it makes no sense when I get it.
Here’s my scenario… I have a directory that is used as the base for all new accounts I sell on my servers. The path is; /root/cpanel3-skel. I always put WordPress in that directory and I want to keep the latest version of WP in that directory
[root@wiredtree ~]# rm -r wordpress latest.*
rm: cannot remove `wordpress’: No such file or directory
rm: cannot remove `latest.*’: No such file or directory
[root@wiredtree ~]# wget -q http://wordpress.org/latest.zip
[root@wiredtree ~]# unzip -q latest.zip
[root@wiredtree ~]# mv -f wordpress/* /root/cpanel3-skel/public_html/
mv: cannot move `wordpress/wp-admin’ to a subdirectory of itself, `/root/cpanel3-skel/public_html/wp-admin’
mv: cannot move `wordpress/wp-content’ to a subdirectory of itself, `/root/cpanel3-skel/public_html/wp-content’
mv: cannot move `wordpress/wp-includes’ to a subdirectory of itself, `/root/cpanel3-skel/public_html/wp-includes’
WHAAAAT? Obviously it is not a subdirectory of itself…
Something strange is going on… We get a little more information if we try to do a move from one device to another. Take a look at this error message:
[root@wiredtree tmp]# mv -f wordpress/* /root/cpanel3-skel/public_html/
mv: inter-device move failed: `wordpress/wp-admin’ to `/root/cpanel3-skel/public_html/wp-admin’; unable to remove target: Is a directory
mv: inter-device move failed: `wordpress/wp-content’ to `/root/cpanel3-skel/public_html/wp-content’; unable to remove target: Is a directory
mv: inter-device move failed: `wordpress/wp-includes’ to `/root/cpanel3-skel/public_html/wp-includes’; unable to remove target: Is a directory
This reveals the true source of the error message. In “mv –help”, the explanation of “-f” is too simplified and says only:
-f, –force do not prompt before overwriting
In “cp –h” we closer,but not exact, explanation of the real process, and one that better matches the inter-device error message:
-f, –force if an existing destination file cannot be opened, remove it and try again
The final bit of information is in an Ubunto bug 71174 “Misleading error message with mv and existing directories” where they change the error message to be “mv: cannot move `a’ to `b/a’: Directory not empty”.
So there you have it. You get that error message because the -f command tries first to remove the directory and can’t because it contains one or more files. You don’t get this message if the subdirectories are empty. The remove works fine on an empty directory but fails if there are files. The Linux core can’t correctly handle this exception and throws up what is probably the last error message in a switch/case statement “cannot move – to a subdirectory of itself”.
So what do you do about it? Well you can either empty the destination directory first, or you can copy the files and then delete the source directory. I chose the latter option and run this from the root folder:
rm -r wordpress latest.*
wget -q http://wordpress.org/latest.zip
unzip -q latest.zip
cp -rf wordpress/* cpanel3-skel/public_html/
rm -r wordpress latest.*
Cool? Hope that helps someone…
On Image Use and Death of the Mouse Plus 70
March 1, 2008
I was involved in an email discussion this morning and once again I realized that I’ve transferred my creative energies from writing new and interesting blog articles over to email discussions and forum posts. So I’m sharing this with you and will hit post instead of send. (Oh and btw make sure to save as a draft in Windows Live Writer before pasting from an HTML email. Some formatting causes WLW to go into an infinite loop. As a result you have to rewrite your brilliant and concisely worded opening paragraphs again. And they are just never as good the second or third time through and your daughter will get upset because you told her you would do her swimming lesson at 11am and that is already well passed.)
At b5media, Inc. we no longer allow the use of copyrighted images unless the blogger has obtained permission from the copyright owner or a representative thereof. The use of copyright images is not something that most Bloggers bother to think about. If you see a neat wilderness photo you want to share, you post it. If you see a picture of an actor doing something… unusual, you might just toss it up on your blog. If you write an article about Steve Jobs or Bill Gates, of course you’ll want a head shot above their name. If an image is used on another website, it is considered polite to copy the image locally to your account so that you are not stealing bandwidth. Most people certainly want to respect the rights of a photographer and want photographers to be paid, but those thoughts usually don’t enter our mindset.
Well for a blogging network of well over 300 blogs, image concerns are amplified. Respecting creative rights and intellectual property is extremely important to us. Heck, we make our living from IP too. OK and yes, admittedly the $20K fine for each image in violation of the law could add up to a sum that would leave anyone weak at the knees. So, liability is of course a concern. If b5 takes a hit, that could affect the livelihood of hundreds of Bloggers. So this is matter we take very seriously. We have to.
There’s been some discussion by our Bloggers and Channel Editors this morning on the subject of image use and here is my contribution:
COMMON SENSE DISCAIMER: Everything in this email/post is only the personal opinion of a geek and is not said in my capacity as a b5media employee. It may or may not be the opinion of the powers that be in b5media, inc. Therefore, nothing in this email has any relation to b5media, Inc. policies. Anything that you believe says or implies otherwise should be ignored.
âcreator’s date of death plus 70 yearsâ
BTW you can thank Disney for that stupid law. It irks me because it means that rare recordings of things like the Danny Kaye performances I like cannot legally be shared and so they become rarer and rarer parts of collections and eventually parts of our culture are lost. Why should a 65 year old scratchy recording of someone reading a story about an inchworm be unsharable? Itâs all so that we donât send around copies of a horrible black and white cartoon of a poorly drawn mouse driving a steam boat and so that stores on the beachfront in Miami can’t airbrush said mouse onto a shirt (or wait does that happen already?). The law in Austrailia is a generous 50 years and the US is trying to push the Ozz to move to 70 years as well. We have made other countries do this already. And 70 is just a âMagic Numberâ anyway and one should always avoid âMagic Numbersâ. (A principle I was taught early on in my coding carreer.)
Yes this is a hot-button issue for me J
Links:
An interesting article on the 2002 case that extended this law.
WikiPediaâs discussion on the various âfree licenseâ differences out there. It will be helpful for those put their own pictures on the various hosting services out there.
The relevant part is here:
For image creators:
If you are the creator of an image, you can choose any acceptable free license. You can multi-license your image under different licenses, if you prefer. The license must not prevent commercial reuse or derivative works.
GNU Free Documentation License – GFDL-self – Written by the Free Software Foundation. People are required to attribute the work to you, and if they make changes or incorporate your work in their work, they are required to share their changes or work under the same license.
Creative Commons: Attribution-ShareAlike – cc-by-sa-3.0|Attribution details – This is one of several CC licenses. This version permits free use, including commercial use; requires that you be attributed as the creator; and requires that any derivative creator or redistributor of your work use the same license. The desired attribution text should be included as a parameter in the template.
Creative Commons: Attribution – cc-by-3.0|Attribution details – Similar to the above, but does not require that derivative works use the same license.
Free Art license – FAL – A copyleft license for artwork; modification and commercial use are allowed, provided derivative works carry the same license.
Attribution – Attribution – The copyright holder allows anyone to use it for any purpose, provided that the copyright holder is properly attributed.
Copyrighted Free Use – CopyrightedFreeUse-Link|[http://www.yourwebsite.com/ Your website] – Same as above, but attribution is not required. However, as a courtesy, you would appreciate a link back to Your website.
Public domain – PD-self – The creator permanently relinquishes all rights to the work.
NOTE (TO B5 READERS): b5media does not fall into the same business category as Wikipedia. Should you see âfair useâ stuff on various Wikipedia pages, just be aware that various points may directly contradict our policy. I personally wouldnât try to argue using Wikipediaâs âfair useâ policy after violating b5mediaâs image use policies. That’s why I didn’t like to their policy. ânuff said.
Also the Electronic Frontier Foundation (EFF) http://www.eff.org/ always has interesting reads (like this http://w2.eff.org/bloggers/ ) and advocate changing the laws rather than breaking them. I donât always agree with what I read there, but it is always interesting.
You learn something new every day: 404.html file size issues?
February 21, 2008
I found this in a friend’s 404.html file:
< !--
- Unfortunately, Microsoft has added a clever new
- "feature" to Internet Explorer. If the text of
- an error's message is "too small", specifically
- less than 512 bytes, Internet Explorer returns
- its own error message. You can turn that off,
- but it's pretty tricky to find switch called
- "smart error messages". That means, of course,
- that short error messages are censored by default.
- IIS always returns error messages that are long
- enough to make Internet Explorer happy. The
- workaround is pretty simple: pad the error
- message with a big comment like this to push it
- over the five hundred and twelve bytes minimum.
- Of course, that's exactly what you're reading
- right now.
-->
Does anyone know if that is still the case? I haven’t come across this before, but it is sure worth knowing about even if it is ie6 specific…
Eliminating duplicate WordPress content in Google
November 7, 2007
If you are at WordCamp 2007, one of the best sessions was Google’s own Matt Cutts discussion on optimizing your WordPress blog. You can see the whole presentation over on John Pozadzides site’s One Man’s Blog. Here is the link. You can see in Matt’s Whitehat SEO tips for bloggers slide show that one of the things that WordPress “suffers from” is that you can reach the same data from multiple sources.
You can get to the same article by browsing by category, by day, month, year etc. etc. etc. Each time Google sees the same data repeated on your site again, it hurts your site a little bit more.
This bit of code will help fix it. It goes into the header part of your blog and will tell Google that it should ignore all of the pages that are not the orginal source of the article.
Here you go:
[php]
if (is_home() || is_single())
{
echo ““;
}
else
{
echo ““;
}
[/php]
TheCodeCave.com is back
October 1, 2007
Hi all!
Remember me?
I’m the guy that pretty much disappeared off the face of the earth back in May! I have been THOROUGHLY enjoying my new job at b5media. And there’s been soooooo much to do at b5 that I’ve not been taking the time I should have been taking to visit with you guys. When I started at b5 the posted blog count was 185 or something like that. The count is currently 260 blogs. Yes, we’ve added 75 new blogs in the last four months. And there are a good many more blogs on their way.
As a result of five months of fun and mayhem (Heck, I’ve even been out to WordCamp and had supper with Matt Mullenweg and the whole automattic gang). I’ve got loads of tips to share with you, things I’ve learned to do better. What enables me to do that is that we’ve just hired a great new employee, Corey Shaffer. He was my student for the 2007 Google Summer of Code project. He’s been a tremendous help at b5 and has helped tip the balance between the day to day tasks of mananging a existing network of 22 dozen blogs and the need for forward progress.
So, now I feel that I can responsibly take some time to get back into the WordPress world on my own again too. Oh I’ve still been out helping other with their blogs. I helped my sister with a site for the family of my Brother in Law’s army unit: The 298 Sandbandits. I also helped a friend get his own blog running: Iggy the Biker. But I haven’t done much for just me.
Well in October, that’s gonna change. I’m starting the month by falling back to my old tried and true and I’m posting a Delphi program I wrote tonight. It’s a really simple program that I’m going to find incredibly useful.
All it does is reverse the slashes of what is in the clip board. How is that useful? Well, in my setup I work in a Telnet (SSH) window half the time and half the time I use SFTPDrive to map the b5media resources to my local drives. Well when I am in telnet my paths might look like this: /var/www/blogname/.htaccess. But if I want open up that .htaccess file in Notepad++, I have to change the path to look like y:\var\www\blogname\.htaccess. Now I have a simple way to do that. In fact I just used it to convert the slashes. I’ve got a shortcut to that program on an auto-hide taskbar on the left side of my screen. So I just click it and boom the slashes are reversed (again) like this: /var/www/blogname/.htaccess. That is sooo awesome.
And it was sooo simple. I’ve been wanting to write this for ages. I actually did write it in Delphi 5 but it didn’t work under Vista (which came on my laptop). I’ve now rewritten it using CodeGear RAD Studio 2007 (which is simply awesome). And it works great!
Here’s the code & exe in a zip: http://www.thecodecave.com/downloads/delphi/SlashFix.zip
program SlashFix;
[delphi]
uses
Forms, Clipbrd, SysUtils;
{$R *.res}
var
S: String;
begin
Application.Initialize;
Application.Title := ‘Slash Fix from TheCodeCave.com’;
Application.Run;
S := Clipboard.AsText;
if (pos(‘/’, S) > 0)
then S := stringreplace(S, ‘/’, ‘\’, [rfReplaceAll])
else S := stringreplace(S, ‘\’, ‘/’, [rfReplaceAll]);
Clipboard.AsText := S;
end.
[/delphi]
Here’s the exe only: http://www.thecodecave.com/downloads/delphi/SlashFix.exe
Of course the version I use is tweaked a bit to work specifically with my common tasks at b5 and will be growing even more. I’m sure you can thing of ways to automate the tasks you do everyday in the same way.
Any way, more tomorrow. There’s another b5 blog that is launching tomorrow, and I’ve got to tweak somethinb befor it launches. Here you can check it out: http://www.LadiesCourt.com/ which is all about Women’s basketball. I just wish that the Cleveland Rockers were still around to be featured on it. My kids went to a number of cleveland Rockers games and we have still have some logo material around.
Microsoft: I just stepped into what?
July 6, 2007
Microsoft scrambles quickly backwards away from a GPLv3 and checks its loafers to see exactly what it just put its $500 loafers into… Â Still “As always, Microsoft remains committed to working with the open source software community”.
Microsoft Statement About GPLv3
A Microsoft statement about GPLv3.
Published: July 5, 2007
Microsoft is not a party to the GPLv3 license and none of its actions are to be misinterpreted as accepting status as a contracting party of GPLv3 or assuming any legal obligations under such license.
While there have been some claims that Microsoftâs distribution of certificates for Novell support services, under our interoperability collaboration with Novell, constitutes acceptance of the GPLv3 license, we do not believe that such claims have a valid legal basis under contract, intellectual property, or any other law. In fact, we do not believe that Microsoft needs a license under GPL to carry out any aspect of its collaboration with Novell, including its distribution of support certificates, even if Novell chooses to distribute GPLv3 code in the future. Furthermore, Microsoft does not grant any implied or express patent rights under or as a result of GPLv3, and GPLv3 licensors have no authority to represent or bind Microsoft in any way.
At this point in time, in order to avoid any doubt or legal debate on this issue, Microsoft has decided that the Novell support certificates that we distribute to customers will not entitle the recipient to receive from Novell, or any other party, any subscription for support and updates relating to any code licensed under GPLv3. We will closely study the situation and decide whether to expand the scope of the certificates in the future.
As always, Microsoft remains committed to working with the open source software community to help improve interoperability for customers working in mixed source environments and deliver IP assurance. Our partnerships with Novell and other Linux platform and desktop providers remain strong and the IP bridge we built with them, embodied in our collaboration agreements, remains intact. In particular, our technical and business collaboration with Novell continues to move full steam ahead, including our joint development work on virtualization, standards-based systems management, identity interoperability and document format translators. In addition, the patent covenants offered by Microsoft and Novell to each otherâs customers are unchanged, and will continue to apply in the same way they did previously.