WeakNet Home
Development // Programming
Nintendo Wii // DS Hacking
WeakNet Linux
>>> Fun With Linux
WeakNet Social Network
WardriveSQL
Catchme-NG!
Media // Papers // Music
RSS // Links // Affiliates

Contact Us // IRC
OLD NEWS ARCHIVE

WeakNetLabs has start a "Tips & Tricks" type of Linux page. This page will teach you something new, that maybe you might need one day when you grow up to be a system admin! If you would like to submit some tips simply Email trevelyn!

10.16.09

Xargs! Xargs is an awesome program that takes the data of the stream you have going in the command line and integrates it into another command! Here's and example of a stream:

ls -l | wc -l

This will take a list of ALL the contents frmo your current working directory (attributs and all) and pushes each line through the "pipe" or "|" and into the "wc" or word count program to count all each individual line "-l"

Now with xargs, you can do something like:

ls -l | grep 'mp3' | xargs -i rm -rf {}

This will delete ONLY any file that contains the string "mp3". Now, with regular expressions you can make this extremely powerful by filtering out your "grep" command, and make use of xargs almost everyday! Let's take a closer look at xargs in the above command:

The "-i" means that you are going to implement the arguments from "ls -l | grep 'mp3'" (all the files that contain the string "mp3") into the next command (which is "rm -rf"). The "{}" is simply a placeholder for those arguments, and the command will run for each line passed to it from the data stream (stream of lines from the "ls -l | grep 'mp3'" command). And there you have it! :)

10.02.09

Make your command Shell welcome you (DEBIAN TESTED OK) - by Trevelyn.

Why not make it welcome you? I mean you are the 1337est mo-fo to ever occupy your BASH shell! well, Here's the simple hack:

Open up ~/.bashrc and append the line "echo 'Hello <YOURNAME>'" to the file. This file is executed each time you login to your terminal! Each time you open Gnome-Terminal, xterm, Eterm, or even a real terminal (each time BASH successfully starts) it will welcome you!

10.02.09

Recompile BASH, your Linux shell (DEBIAN TESTED OK) - by Trevelyn.

sudo su
mkdir /tmp/source/bash && cd /tmp/source/bash
wget ftp://ftp.cwru.edu/pub/bash/bash-4.0.tar.gz
tar vxzf bash-4.0.tar.gz
cd bash-4.0
cat execute_cmd.c | sed 's/command not found/WHATEVER YOU WANT HERE/g' > out.txt
cat out.txt > execute_cmd.c && rm out.txt
./configure
make
make install

This hack changes BASH to say "WHATEVER YOU WANT HERE" whenever a command is typed that is not in your $PATH. (rather than saying "bash:lol:command not found."

Keep in mind that you should not put any RegExp or C special characters into the string "WHATEVER YOU WANT HERE" as they may screw up your build, when you try to compile BASH! It;'s a pretty heafty hack, if you screw anything up, you can simply use aptitude to reinstall bash from a repository I'm sure.

 

2009 / 2010 WeakNetLabs.com | Site Design: Douglas Berdeaux | Pittsburgh, Pa, 15210