Create directory and change into it automatically

More quick command line geekery.... Create a command in .bashrc that lets you create directories and change into them immediately:

mkcd () {
  mkdir -p "$*"
  cd "$*"
}


so to use it:

mkcd directory/another/yet_another

Filed under  //   command line   linux   ubuntu  

Change permissions on all directories except SVN with the command line?

OK, a quick one. Want to set permissions on all directories except .svn ones?

So, working from your current directory down, let's say you want to make all directories writeable, and leave the svn ones alone:

find . -type d -not -name ".svn" | xargs chmod 0777

Or, if you need to exclude several directory types, you could arrange it a little bit differently:

find . -type d -print | grep -v '\(\.svn\|modules\)' | xargs chmod 0777

Filed under  //   command line   linux   ubuntu  

Downgrading to PHP 5.2 from PHP 5.3 on Ubuntu 10.04

On the Ubuntu 10.04 Lucid Lynx release, by default PHP 5.3 is installed. Great if you are using it, but it's not for everyone. Definitely not for me being a Drupal developer, as for the moment, it causes problems.

This method worked for me (however I am not responsible if it doesn't for you). All you need to do it put this lot in a shell file and run it. Remember to chmod +x file for it to run.

 

php_packages=`dpkg -l | grep php | awk '{print $2}'`
sudo apt-get remove $php_packages
sed s/lucid/karmic/g /etc/apt/sources.list | sudo tee /etc/apt/sources.list.d/karmic.list
sudo mkdir -p /etc/apt/preferences.d/
for package in $php_packages;
do echo "Package: $package
Pin: release a=karmic
Pin-Priority: 991
" | sudo tee -a /etc/apt/preferences.d/php
done
sudo apt-get update
sudo apt-get install $php_packages
sudo /etc/init.d/apache2 restart

Filed under  //   command line   downgrade   linux   php   ubuntu  

SVN URL shortcuts

Typing repository URL's are not fun in subversion, most of them are really long and if you want to commit multiple files or merge, sometimes you have to type them more than once.


If you run svn info, you will notice the line that begins with URL:

Why don't we grab the contents of this line after the word URL: (so we are grabbing the URL itself), and put it in a shortcut.

so, create an alias in your .bashrc file:

alias sitesvn="svn info | egrep '^URL: (.*)' | sed s/URL\:\ //"

Now you can use a shortcut:

svn ls $(sitesvn)/trunk


Note: this might not work on *all* URL's, depending on how you have the SVN root setup.

Filed under  //   command line   subversion  

Posting to twitter from Ubuntu command line

If you are a real geek like me, you are the type of person that likes to do manually through the terminal rather than a graphical interface. The same goes for Twitter. I've tried loads of different twitter apps, some of them great, but it's fun sometimes posting from the command line.

To set this up on Ubuntu, you will need to create a bash file with a twitter API command in:

sudo gedit /usr/bin/twitter

Now enter this into the open 'twitter' file:

curl --basic --user "yourusername:yourpasswd" --data-ascii "status=`echo $@|tr ' ' '+'`" "http://twitter.com/statuses/update.json" -o /dev/null
echo SENT!

(make sure to replace your username and yourpassword with your account username and password!)

Save this file. Now we need to set permissions on the file we just created so we can run it:

chmod +x /usr/bin/twitter

And that's it. Now all you need to do, is actually post to Twitter. This is how:

twitter "this is my new post message!"

It will appear in Twitter as "from API", instead of "from Tweetdeck" or "from Echofon" or however else the tweets are posted.

IF you get a message saying that curl is not installed when you try and post a tweet, then run this to install curl:

sudo apt-get install curl

Filed under  //   command line   twitter   ubuntu