Licence
Creative Commons License

This work by Stephane KATTOOR is licensed under a Creative Commons Attribution 3.0 Unported License.
Feeling like tipping ?
If you find this blog useful, you might consider sending a few bitcoins to support it : 1BTtsC3beGJ6ysd8DhrXjdo6jVw5WD9mvY
RSS
 
RSS Feed
Follow me !
Tech@Sakana on Facebook
Search this site

Newsletter

Get latest posts by email (No spam, only posts):

Enter your email address:

Delivered by FeedBurner

Categories
Monthly archives
June 2013
M T W T F S S
« May    
 12
3456789
10111213141516
17181920212223
24252627282930
Unix 101 : Shell wildcards expansion, to quote or not to quote - March 11, 2012 by Stephane Kattoor

Or why you usually use ls -l *txt without quotes, but use quotes in find . -name "*txt".

 

read this entry »

Bash / zsh : Using the history expansion - March 28, 2010 by Stephane Kattoor

One of the features of bash I’ve too long overlooked is its history expansion. In this post I’ll show a few examples to get a grip at it.
read this entry »

Linux / Unix : Disk usage and identifying biggest files - January 17, 2010 by Stephane Kattoor

When working as a systems administrator, you’ll always end up having to solve a file system full error in a hurry. Here are a few commands and hints to help you get out of it quickly on a UNIX like system.
read this entry »

shell tip : identify broken symlinks - November 29, 2008 by Stephane Kattoor

If you need to identify broken symlinks, you can do the following :
find -L . -type l

The -L options instructs find to follow symlinks when possible. Hence no “working symlink” will ever get returned as the targets won’t match -type l (meaning “file is a symlink”).

On the other hand, find will not be able to follow broken symlinks, so the information will be taken from the symlink itself and not from the non-existent or otherwise unreachable target. The -type l will then be a match and the broken symlink filename will be returned.

Broken symlinks

Case solved ;-)

Thanks to the “Ferg’s Gaff” blog (especially the comments) for showing the way !

Unix : shell tips - March 27, 2008 by Stephane Kattoor

I ran into this into the following article, “Learn 10 good UNIX usage habits“. This article is mainly common sense, but there are interesting points, such as :

  • avoid piping when you can, in order to save performance (the classical construct grep | wc to count the lines is useless as most versions of grep can count with grep -c)
  • use awk to “grep” on a specific field of a line with “… | awk ‘$1 == “XXX”‘ which is cool and I never use
  • the find | xargs construct (I’d add “find -print0 | xargs -0″, useful if your find brings back filenames with a space inside …)

All in all it is worth a reading, if only to refresh your memory.

Linux : Taking control of Virtual Terminals (VT) from command line - December 1, 2007 by Stephane Kattoor

When you use Linux in text mode (as opposed to with an X server), you readily have access to multiple Virtual Terminals (aka VT for short) by hitting one of your <Alt-Fn> keys (if you are running a X server, you’ll need to hit <Ctrl-Alt-Fn> simultaneously).

This lets you access one of the VTs which are initialized at boot time, but won’t let you create new ones even if your kernel configuration would allow more VTs. Furthermore, what if you want to deal with VTs from a script ?

This post covers the 3 commands which will let you control your VTs from the command line or from a script.

read this entry »

sed : replacing a text in a file - October 20, 2007 by Stephane Kattoor

To replace a text in a file, you can invoke sed as in the following example :

1
% cat file.txt | sed -e 's/text/replacement/g' > result.txt

This will change all the occurences of “text” to “replacement” in “file.txt” and output the result in “result.txt”

Note : As suggested by Matthias from adminlife in the comments, if you wanted to do “in place” text replacement (that is modify the file without a temporary file in between), you can do the following :

1
sed -i ’s/text/replacement/g’ file.txt

For more complicated text manipulations you might consider moving to Perl, but sometimes you don’t need the sledge-hammer :-)

Who am I ?
Ads