Archive for the ‘Linux’ category

Get your user sudoing without logging in again

November 14th, 2012

Let’s say you set up a new server, and you want to give your user sudo access. You follow the directions and use the visudo command, somehow gaining root privileges to do so. Now you want to run some commands with your new sudo privileges, but when you do you get treated to the following:

 USER is not in the sudoers file.  This incident will be reported.

 
So you think, “Oh my goodness! I’m going to be reported!”  See something, say something right?

So then you remember you probably need to reinitiate your session or something to get privilege changes to take effect.  So you try the old trusty “just run bash again,” but that doesn’t work.

So you start to panic or swear, but then remember that you can probably just log out of your session entirely and reconnect to the server.  But what if you have a tmux session going with 7 windows, each with 3-4 panes that you’ve carefully put into place?

There’s a solution:

su - USER

 
That’s a dash, and then of course substitue your user’s actual username in the place of USER.  Granted, in our multiple tmux panes example, that will only refresh the privileges for that one pane you run it in, that may be all that you need.

Do you have any other ways of refreshing the privilege change?

tmux and bash tab completion

August 14th, 2012

In a move of wt[h], somewhere along the Ubuntu 12.04 LTS, tmux, bash development chain someone decided to add this little gem of a key binding:

bind-key -n     Tab clear-history

I found this using tmux list-keys from the command line.  You have to have a running tmux session for that command to give you non-error output. I digress.

SERIOUSLY?!?!?!?!? I mean, the tab key.  You know, the one you hit at least 1 gajillion times per terminal session.  When you’re typing in your editor.  When you’re CDing around the filesystem.  When you’re <insert favorite command-line activity>.  You probably hit Tab without the command modifier in front.

They mapped that to clear the history, shutting down whatever else it may have done.  This one is SO ODD, that I can only imagine there was some really good and crazy reason for it.  I can’t imagine what that is, but perhaps someone could enlighten me.

To overcome this “feature” add the following to your .tmux.conf.  I did.

unbind -n Tab

Ever wonder why grep is taking so long?

July 10th, 2012

This is why I love programming with Unix tools available.  Let’s say you need to grep your code (text files, remember), and it’s taking longer than, say, 1 second.  Perhaps you have a bunch of generated files or something that are hogging all of your disk space.  How do you find out?  A simple one-liner:

du --exclude=.git | sort -n

I love *nix.

du is the tool that reports on file size, and since I use git, I pass it –exclude git so that it doesn’t consider that directory (I already have grep aliased to ignore .git).  Then I pipe that into sort, using -n so that it sorts the sizes numerically, instead of alphanumerically.  The result is that it shows me the big, pointless files it’s grepping through.

And now my search is back to a happy 1 second.

RVM woes on Ubuntu 11.04

May 19th, 2011

Having had an epiphany the other day, I needed this morning to start work on a new prototype.  This post isn’t about that prototype.

It IS about the new setup I was using to do that prototype.  I figured this was a good chance to try out RVM in a Rails project, as well as try out Ubuntu 11.04, as well as install the OS in French.  So, with the new VM up and running, I follow RVM’s installation instructions, anticipation building with each scrolling character.  And then… BAM!

ethan@ubuntu11:~/rvmsource$ bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
Cloning into rvm…
remote: Counting objects: 4765, done.
remote: Compressing objects: 100% (2433/2433), done.
remote: Total 4765 (delta 3086), reused 3183 (delta 1672)
Receiving objects: 100% (4765/4765), 1.57 MiB | 322 KiB/s, done.
Resolving deltas: 100% (3086/3086), done.
WARNING:
Could not source ‘/home/ethan/.rvm/scripts/base’ as file does not exist.
RVM will likely not work as expected.
WARNING:
Could not source ‘/home/ethan/.rvm/scripts/version’ as file does not exist.
RVM will likely not work as expected.
WARNING:
Could not source ‘/home/ethan/.rvm/scripts/selector’ as file does not exist.
RVM will likely not work as expected.
WARNING:
Could not source ‘/home/ethan/.rvm/scripts/cd’ as file does not exist.
RVM will likely not work as expected.
WARNING:
Could not source ‘/home/ethan/.rvm/scripts/cli’ as file does not exist.
RVM will likely not work as expected.
WARNING:
Could not source ‘/home/ethan/.rvm/scripts/override_gem’ as file does not exist.
RVM will likely not work as expected.
cat: /home/ethan/.rvm/VERSION: Aucun fichier ou dossier de ce type

A few Google searches turned up a few people having a similar problem but no solutions.  But whould’ve thunk it that installing the OS in French would actually have some practical value?  Google must’ve seen that and then dumped me on to this forum, wherein one of the posters linked to this post, which basically says to just follow the directions that RVM spit out as part of the big error message.  Who’d've thunk THAT?  I sure didn’t.  I just focused on the error message itself in my searches.

WARNING:  you have a ‘return’ statement in your ~/.bashrc
This could cause some features of RVM to not work.

This means that if you see something like:

‘[ -z "$PS1" ] && return’

then you change this line to:

if [[ -n "$PS1" ]] ; then

# … original content that was below the ‘&& return’ line …

fi # <= be sure to close the if at the end of the .bashrc.

# This is a good place to source rvm v v v
[[ -s "/home/ethan/.rvm/scripts/rvm" ]] && source “/home/ethan/.rvm/scripts/rvm”  # This loads RVM into a shell session.

It looks like RVM tries to run outside of a standard shell session, and the way .bashrc is configured by default on Ubuntu 11.04 prevents that sort of thing.  When you’re done with your edits your .bashrc should look something like this:

# ‘[ -z "$PS1" ] && return’ <—– delete this line.  It isn’t commented out in the original

if [[ -n "$PS1" ]] ; then

# the rest of your old .bashrc contents

fi

[[ -s "/home/ethan/.rvm/scripts/rvm" ]] && source “/home/ethan/.rvm/scripts/rvm”  # This loads RVM into a shell session.

After making that change I re-ran the installation instructions, and PRESTO!  Or maybe I should say, Voilà!  As always, YMMV.  I really don’t think it was the double install that fixed the problem.  And be sure to replace “ethan” with whatever your actual path is.  That happens to be mine, because, well, that’s my name.

Git, GitHub, and Windows

August 4th, 2008

A blog post isn’t quite the format in which to go into the length details of why, so it sufficeth me to say that Git is great source control software. Local commits. 1 command to initialize a repo.  Branching and merging isn’t so ridiculous that you never do it.

GitHub also seems pretty neat, though I confess to be a GitHub newb (or noob– I forget which is derogatory. I don’t mean that one). GitHub allows free hosting of open-source Git repositories. I don’t really plan on making the project I’m working on open source– and for no particular reason– so that’ll get changed when I want to close things down. It does cost money to host closed-source projects. Point being, off-site backup is a Good Thing, a quality especially noticeable when one accidental rm -Rf’s their repository. Oops. Good thing I had basically only clicked New Project in Visual Studio.

So, this post is supposed to matter because you get some useful information and not just some narcissism. If you’re a Windows user at least part of the time, it’s readily apparent that Git wasn’t written for Windows users. Do the author check. It’s slightly confusing to get Git working, and rather than re-invent the wheel– though I’m not afraid of beating dead clichés– checkout the work of some dude named Kyle Cordes.

His post works as advertised. I did skip all the bit about being added to his repository, as I wanted to do my own. Also, I stopped the whole thing at “Approach 1: GUI.” It was pretty easy getting the repo into git-hub by following git-hub’s instructions.

rm -what-is-it-again?

June 6th, 2008

I’ve been mostly a Windows user my whole life up to this point. That was due mostly to fate. My parents had only PCs (unless you count the TI-99/4A), so not being of much economic independence at the age of 5, those are what I used too. I suppose there were computer days at elementary school too, where we used Apple 2es, but all we really learned on those was how to boot up Oregon Trail.

At university I got exposure to Linux. I had grown used to graphical interfaces by that point, so harkening back to command-line days was odd. I never caught Linux myself though, being turned off to the OS because I couldn’t stand that average Linux user that I met. Their arrogance and support for Linux seemed to stem from the simple fact that it isn’t Windows, so it must be better. That’s like saying that puke isn’t feces, so it’s good to eat. Or like saying that voting for Obama is good, because he isn’t Bush.

Anyway, the Linuzealots would extol the command line and how much easier it was to get things done. Maybe they enjoy sifting through man pages. Now don’t get me wrong, I like technical challenges– that’s why I’m a programmer. I don’t like figuring out how to use cryptic and poorly-documented tools though. I like accomplishing things.

If the command line is so great, why is it so hard to remove (or delete if you’re a Windows user) a non-empty directory from the command line? I can NEVER remember the switch for doing so. I just googled it a second ago, and thought I got somewhere, but when I typed -r in (what the result claimed the switch was) it started prompting me on every file. Grrr! So I just typed “open .” and deleted it graphically.

When you consider the time it took to do that and then come rant about it here, well, I just don’t think the command line is all that more efficient/productivity enhancing.

Of course, if I ever get a technical reader who could tell me what the blooming flag is, feel free to post it! That is fact what I was really hoping to do– figure it out and then post it here so I would know where to look the next time.

Edit: I have since found out that it’s rm -Rf that I wanted.