Archive for the 'Linux' Category
Let’s say you have a really large text file. By large, I mean it has a lot of lines of text in the file. I frequently work with files that have millions or billions of lines of text in them. If I try to open the file in a text editor, it usually takes a [...] Read more »
October 11th, 2011 | Posted in Linux | No Comments
I’m working on a bash script that I want to insert some text into a file. So I’m using the echo command to do this, like so:
echo “hello, world” > myfile.txt
This works just great. Now I want to insert a special character into the file. So I need to do two things: 1) escape special [...] Read more »
August 4th, 2011 | Posted in Linux | No Comments
It’s not too hard to generate a random number at the command line in Linux. You can use $RANDOM. But if you want to generate a random string, it is a bit more obscure. The best solution I found (after searching for longer than expected) was the following:
openssl rand -base64 30
This technique uses the openssl [...] Read more »
July 18th, 2011 | Posted in Linux | No Comments
Let’s say you have a bash variable:
x=abc123def
And you want to get everything in the substring that comes before “def.” You can use awk to do this, but it’s a bit “awk”ward (though very flexible and powerful in general). An easy solution is to do the following:
y=${x%def*}
echo $y # Should print "abc123"
This approach should work on [...] Read more »
June 29th, 2011 | Posted in Linux | No Comments
Say you have a variable in a bash script that looks like this:
x="abc_123_def"
Now say you want to split this variable into an array. The character you will use to split it is the underscore (_). So you want to end up with an array of three objects: abc, 123, and def. Then you want to [...] Read more »
June 28th, 2011 | Posted in Linux | 1 Comment
Let’s say you have a script that creates a directory as a preliminary step to some type of task that you are performing. If the directory doesn’t exist, you want the script to create the directory. You don’t want to have to modify the script after the directory has been created. If the directory already [...] Read more »
February 11th, 2011 | Posted in Linux | No Comments
There’s a nice way of setting up a UNIX-based server so you can log in without a password. This technique uses public/private key encryption. You set it up one time on your client machine and one time on each server you want to connect to. Then you can SSH into the server without using a [...] Read more »
December 6th, 2010 | Posted in Linux | No Comments
I finally made the leap to doing most of my research on computers that run on Linux. The distribution I’m using is Ubuntu. So far I’ve found it quite good. One thing I do frequently is open a Terminal (command) window in a specific directory. However, when you open the Terminal, it by default opens [...] Read more »
April 24th, 2010 | Posted in Linux | 2 Comments
I was trying to install some packages in R recently that depended on the XML package. I used the nifty install.packages() command, but I was getting an error:
“cannot find xml2-config”
This error was preventing these other packages from being installed properly. It turns out that I needed to install a library called libxml2-dev. In my case, [...] Read more »
April 22nd, 2010 | Posted in Linux, R | 5 Comments
I installed cygwin, which allows you to execute Linux-based applications on your Windows machines. But what I wanted to do was connect (using ssh) to a Linux box and run an application that has a GUI from there. In this case, I wanted to be able to connect to server and run firefox from the [...] Read more »
December 28th, 2009 | Posted in Linux | No Comments
Cygwin is a software tool that allows you to run Linux programs in Windows. I have had good success in using it to run commands locally and to connect to other servers via ssh, scp, etc. I just got a new computer and installed the latest version of Cygwin, but when I tried to ssh [...] Read more »
September 29th, 2009 | Posted in Linux | No Comments
I’m learning something new about Linux every day, so this is something that will probably be obvious to many of you out there. But I needed today to read the contents of a file into a variable in a bash script. The simple way to go about doing this is to use the following command:
myvar=`cat [...] Read more »
September 11th, 2009 | Posted in Linux | No Comments
I am running an application in one location on the file system, and I need to be able to invoke an application that is in a different directory on the file system. Due to personal preference, this other directory is not specified in the PATH variable. So I’m wondering how I can get Linux to [...] Read more »
September 9th, 2009 | Posted in Linux, Tip | No Comments
In Linux, you sometimes want to run a command when the server first starts up. I was doing this recently where I would have to manually go in and run a command each time the server got rebooted. This was a pain, so with a little help from my friend Martin, I learned how to [...] Read more »
September 4th, 2009 | Posted in Linux, Tip | No Comments
I’m sure this one will be obvious to many readers, but it wasn’t to me, so I’m going to share it. A bash script is a file that you can run at the command line in Linux/Unix environments to automate something. In my case, I have a Java program that I need to run over [...] Read more »
June 30th, 2009 | Posted in Linux | No Comments
I recently had a scenario where part of what I wanted to do was in Java, and the other part was in an application that was written in Python. Rather than than rewrite my entire code base in one language or the other, I wanted to find a (quick and dirty) way to invoke the [...] Read more »
June 4th, 2009 | Posted in Java, Linux, Python, Tip | No Comments
In Linux, you have the ability to determine which processes are running at a given time on the server. This post explains how to do this using the top command.
Let’s say you have a process that is not getting as much CPU time as you would like, maybe because it is getting beat out by [...] Read more »
January 7th, 2009 | Posted in Linux, Tip | No Comments
Linux comes in many flavors. If you did not perform the installation (or forgot), you may need to find out which flavor is being run on a given box. In Linux, it is pretty easy to do this. Simply type the following command at the command line, and it will give detail about it:
cat /proc/version Read more »
January 6th, 2009 | Posted in Linux, Tip | No Comments
If you want to be able to encrypt and decrypt files with Python, you might check out the following sites:
http://www.dlitz.net/software/pycrypto/
http://www.amk.ca/python/code/crypto.html
However, if you know you’re going to only be using Linux, I recommend doing file encryption as explained in this post. You can invoke commands at the command line by following the explanation here. Read more »
December 20th, 2008 | Posted in Linux, Python, Tip | No Comments
Say you log in to a Linux machine but then want to switch to a different user. You can do this without logging out as the first user. A time when this might come in handy is when you are logged in as a regular user but want to install some software as the root [...] Read more »
December 20th, 2008 | Posted in Linux, Tip | No Comments