Splitting strings with IFS

2010-02-04 2 min read Bash Linux

Today I want to discuss splitting strings into tokens or “words”. I previously discussed how to do this with the <a href="http://bashcurescancer.com/reading-a-file-line-by-line.html">IFS variable and promised a more in depth discussion. Today, I will make the case on WHY to use IFS to split strings as opposed to using a subshell combined with <a class="zem_slink freebase/en/awk" title="AWK" rel="homepage" href="http://cm.bell-labs.com/cm/cs/awkbook/index.html">awk or cut.

I wrote this script which reads the /etc/password file line-by-line and prints the <a class="zem_slink freebase/en/user" title="User (computing)" rel="wikipedia" href="http://en.wikipedia.org/wiki/User_%28computing%29">username of any user which has a UID greater than 10 and has the shell of /sbin/nologin. Each test function performs this task 10 times to increase the length of the test:

Continue reading

Kill processes that have been running for more than a week

2010-02-04 1 min read Linux

<a href="http://blog.amit-agarwal.co.in/category/linux/">Bookmark this category

<span style="font-size: x-large;"><a href="http://feedproxy.google.com/~r/Command-line-fu/~3/kr_otvdAVxA/kill-processes-that-have-been-running-for-more-than-a-week">Kill processes that have been running for more than a week
$ find /proc -user myuser -maxdepth 1 -type d -mtime +7 -exec basename {} ; | xargs kill -9

  • <a href="http://www.commandlinefu.com/commands/view/3702/kill-processes-that-have-been-running-for-more-than-a-week">View this command to comment, vote or add to favourites
  • <a href="http://feeds2.feedburner.com/commands/by/sharfah">View all commands by <a href="http://feeds2.feedburner.com/commands/by/sharfah">sharfah

<a href="http://www.commandlinefu.com"><img src="http://blog.amit-agarwal.co.in/wp-content/uploads/2010/08/header-logo.jpg" alt="commandlinefu.com" align="bottom" />

by David Winterbottom (<a href="http://codeinthehole.com">codeinthehole.com)

<a href="http://feedads.g.doubleclick.net/~a/NeXCFRlIt7EM3A_bb4x2jLaegwk/0/da"><img src="http://blog.amit-agarwal.com/wp-content/uploads/amit-agarwal.co.in/~a/NeXCFRlIt7EM3A_bb4x2jLaegwk/0/di" border="0" alt="" align="bottom" />
<a href="http://feedads.g.doubleclick.net/~a/NeXCFRlIt7EM3A_bb4x2jLaegwk/1/da"><img src="http://blog.amit-agarwal.com/wp-content/uploads/amit-agarwal.co.in/~a/NeXCFRlIt7EM3A_bb4x2jLaegwk/1/di" border="0" alt="" align="bottom" />

Continue reading

Color in grep output to distinquish the matching entries

2010-02-04 1 min read Linux

Most of the times I end up spending a lot of time to look for the string in the grep output when I do a search. This is quite frustrating and thus I looked at the options for grep command that would make my life easier and there definately is something. Here it is:

export GREP_COLOR=&#8221;5;36&#8221;

But for this to work you would still need to give the &#8221;–color=auto&#8221; option in the grep command. There are two ways to do this, create a alias for grep as &#8221;grep –color=auto&#8221; or specify the same in GREPOPTIONS.

Continue reading

Top 3 Sites To Help You Become A Linux Command Line Master]

2010-02-04 0 min read Linux
\"Programming
Image by fogus via Flickr

The truth about Linux today is that one may never have to actually <a class="zem_slink" title="Spice Girls" rel="homepage" href="http://www.thespicegirls.com">touch a terminal or issue a single Linux command in order to run some versions of this flexible alternative <a class="zem_slink" title="Operating system" rel="wikipedia" href="http://en.wikipedia.org/wiki/Operating_system">operating system. While there are times when using the Linux <a href="http://www.makeuseof.com/tag/an-introduction-to-the-linux-command-line/">command line could be expeditious and the benefits of possessing the ability to use it are numerous, many users can be intimidated by the prospect.

Continue reading

Damn Vulnerable Linux – DVL review

2010-02-04 1 min read Linux

Today morning I got a chance to look at one of the other less commonly known Linux Distribution and out of the line distribution, very good for Learning purposes. The distribution is known as DVL (Damn Vulnerable Linux). As the name suggest this is for people looking at developing their skills in Security and Penetration testing. Quite a lot of good and interesting tools are included. More is left for users to experiment but I definately liked the distribution. Here is the <a href="http://www.damnvulnerablelinux.org/" target="_blank">homepage.

Continue reading

chfn – Change finger information

2010-02-04 1 min read Linux

Finger is a nifty nice utility to get the information on the user. A sample output of the command is as below:

-0-(ak) ~ > finger ak
Login: ak                     Name: Amit Agarwal
Directory: /home/amitag                 Shell: /bin/bash
Office: MGL
On since Sun Oct 19 13:50 (IST) on tty7 from :0
On since Sun Oct 19 13:50 (IST) on pts/0 from :0.0
No mail.
No Plan.
All this information can be changed with the command chfn. No hassles, just type in the command it does the rest, asking you for the information whatever required. You can also specify the details in the command itself with the below mentioned parmateres:

Continue reading

Web Thumbnails, create your account to upload your files.

2010-02-04 1 min read Linux

So, since I got one more address, I thought of some social service too ;). Just kidding. Got my gallery site up. You can use it too to upload your photos. For stopping social abuse I would personally be montoring the accounts thus created and you would need to send a mail to gallery@amit-agarwal.co.in for creation of the account. Right now there is no quota on the size of the space.

Continue reading
Older posts Newer posts