Linux/Unix

Posts about using Linux and Unix

Linux Logo

Find The Size Of Files And Directories In Linux With The du Command

29th June 2012 - 6 minutes read time

The du (or 'disk usage') command is a Linux command that can print a list of the files within a directory including their sizes and even summarize this information. It is useful if you want to see how large a group of files is and provides more information about directories than the ls command does.

Using du within a directory will show you the size (in bytes) of all files and directories under that directory, including the size of the current directory. To make du produce more readable results just use the -h flag to make the file sizes into a human readable format. You can also use the -c flag to produce a grand total of all of the sizes found, and the -s flag to display only a total. The -a flag can be used to display all files as well as directories, leave this out to just display directories.

Linux Logo

Remove SVN Files From Source In Linux

26th June 2012 - 1 minute read time

There might be a couple of reasons why you would want to do this. Perhaps the repository has been checked out instead of exported, or maybe the repository doesn't exist any more. A couple of strategies exist remove all SVN files from a set of directories in Linux. You can either use the rm command directly and pass in a find command using grave accent quotes (key to left of '1').

rm -rf `find . -type d -name .svn`

Or you can pass the output of the find command to the xargs command, which calls the rm command.

find . -type d -iname ".svn" -print0 | xargs -0 rm -rf

You can even use the -exec flag of the find command to run the rm command.

Linux Logo

Using xclip To Copy Output From The Command Line In Linux

21st June 2012 - 3 minutes read time

When copying the standard output from within a terminal I often push it to a file using the "command > file" syntax. The trouble is that I then end up with a file that I have to open in order to get the output, and I often forget to delete the file once finished. This is especially annoying when I just want to paste some debug output into a help topic or similar. The solution to this is to use xclip to store the output in the xclipboard instead of a file. This is essentially the function of xclip, it allows access to a clipboard that you can store anything in.

A good example of this in use is when pasting the output of php -i into the amazing xdebug tailored instillation instructions. When you print this to the terminal you get pages of output. To push this into xclip instead just pipe it like this.

Linux Logo

Installing A Realtek Wireless Card On OpenSuSE Linux 11

21st July 2011 - 4 minutes read time

I've been using my Medion Akoya E1222 netbook for about a year now and I still think it's an awesome little machine. Recently, I decided to swap from Ubuntu to another Linux distro and have been experimenting with Fedora, JoliOS, PuppyLinux before finally going for OpenSuSE. The only problem I had was figuring out how to get the wireless card working.

I had a little bit of trouble tracking down this information, so I thought I would put it here both for future reference and for anyone else looking for the same information. This is mainly specific for my netbook and particular distribution, but it might help others with the same sort of problems.

The first thing you need to do is find out if your system can actually see the wireless card. This can be done using the lspci command, which in my version of SuSE needed to be called directly from its location in the sbin directory.

Linux Logo

Running Commands In The Background In Linux

9th May 2010 - 2 minutes read time

A useful technique to know about when using Linux is to run commands in the background. Sometimes certain commands can either take a while (like copying a large file) or will simply take over the terminal window when run. For example, lets say that you open a file in gedit, you might use the following command.

gedit file.txt

Doing this will open the file in gedit but will not allow you to do anything in the terminal window until you close gedit. To open the file but still keep the terminal window active use the & symbol at the end of the command. This will run the proceeding command in the background.

gedit file.txt&

To run a file copy in the background do the following.

Linux Logo

DVD Backup With Linux

9th March 2009 - 3 minutes read time

If you are part of a company the chances are that you have either set up or are aware of a backup policy for your data. However, even if you are not then you might have the need to backup certain items to a DVD drive.

DVD burning is accomplished in Linux by using the mkisofs and growisofs programs. This can be run in either a two stage or a single stage process. The mkisofs program is used to create an iso file that is then written to the DVD using the growisofs program. The following will take three files and create an iso called toburn.iso, this will then be used to write the data to the DVD.

Linux Logo

Find And Replace On All Files In And Below A Directory

9th October 2008 - 1 minute read time

The following shell command uses the find function to find all files in or below the current directory that have the extension php. It then passes each file found onto a sed command which then replaces all with the longer

Linux Logo

Using !$ To Use Last Parameter

22nd July 2008 - 1 minute read time

Much like using Alt+. to print out last parameter you can also use !$ to use the last parameter from the previous command. Here is a simple example.

  1. # cd ..
  2. # cd !$

In this example we are moving up a directory and then doing the same action again, the !$ is a short cut to get hold of the ... This is more useful when doing things with longer parameters like directory or file names. For example here we are creating a directory and then moving into that same directory.

Linux Logo

Raising Skinny Elephants Is Utterly Boring

21st July 2008 - 2 minutes read time

This might sound odd, but this is a mnemonic that helps you remember a sequence of letters that you can enter when your Linux system is locked. This is a last ditch attempt to get things up and running again and should only be used if all else fails and the only other thing that you can do it pull the plug.

If you have also tried pressing Ctrl+Alt+backspace and this does nothing then you can try using the key sequence Raising Skinny Elephants Is Utterly Boring.

Hold down the left Alt key and the SysRq key (found on the print screen button) and press each letter in turn. Make sure that you give a little time between keystrokes.

  • r
  • s
  • e
  • i
  • u
  • b

Here is a description of what you are doing.

Linux Logo

Search And Highlight With Grep

14th July 2008 - 1 minute read time

Searching for things in many files is easy with the grep command, but in order to view the results with the expression results highlighted you need to use grep in conjunction with less.

grep expression *.txt | less +/expression

If you wanted to search all files called something.txt for the letter d you would use this line.

grep d *.txt | less +/d