The Archives
-
03.19.10Shell scripting for NautilusIt has been a while since I wrote my last post. Sorry for the delay, but I was a bit busy lately. In this post, I shall explain how to get the most of your nautilus file manager by using shell scripts. Nautilus provides some facilities available from shell scripts. Combining them with a small utility called zenity can improve your daily tasks. Nautilus has the ability of executing shell scripts applying them to the selected files. The executable scripts are those present in the following directory: ~/.gnome2/nautilus-scripts Every script present in that directory will be shown in the "Scripts" entry of the contextual ...
-
09.03.09Refreshing bash configurationAfter writting some changes in the .bashrc file, you can reload it running this command: $ source ~/.bashrc or the even simpler $ . ~/.bashrc
-
05.02.09Saving bash linesThanks to the short-circuit behaviour of the && operator, if-statements can be replaced by: [[ test ]] && if_true_do_this || otherwise_do_that So, instead of writing: if [[ "$1" == "$2" ]]; then echo "$1 equals $2" else echo "$1 differs from $2" fi One can write: [[ "$1" == "$2" ]] && echo "$1 equals $2" || echo "$1 differs from $2" Braces can be used to run more than a single command: [[ test_condition ]] && { true_stuff_1; true_stuff_2; } || { false_stuff_1; false_stuff_2; } Via | commandlinefu
-
04.30.09Changing your login shellYes, I have to admit this is the first thing I do on my account after installing FreeBSD :). This example however, comes from a Linux box (you may notice it due to the default installation paths for the shells). $ chsh -l /bin/ash /bin/bash /bin/csh /bin/tcsh The command above lists the available shells. (I have omitted some of the entries to shorten the list). $ chsh -s /bin/bash The next time you log in, your shell will be bash. Enjoy!
-
04.20.09Monitoring HTTP requests from the command lineSome days ago Javisantana sent me a tweet with a link to a one-liner HTTP requests monitor. It goes as follows with some ouput added: $ sudo tcpdump -i en1 -n -s 0 -w - | grep -a -o -E "Host\: .*|GET \/.*" Password: tcpdump: listening on en1, link-type EN10MB (Ethernet), capture size 65535 bytes GET / HTTP/1.1 Host: commandliners.com GET / HTTP/1.1 Host: google.com GET / HTTP/1.1 Host: www.google.com GET / HTTP/1.1 Host: www.google.es GET /intl/en_com/images/logo_plain.png HTTP/1.1 Host: www.google.es [...] Replace en1 with your network interface's name. Usually enX in BSD-like OSes and ethX in Linux. You can create an alias named httpdump and add it to ~/.bash_profile: alias httpdump='sudo tcpdump -i en1 -n -s 0 -w ...
-
03.08.09System information$ echo $OSTYPE $MACHTYPE freebsd7.1 amd64-portbld-freebsd7.1 Easy way of getting information with bash
-
02.25.09Bash 4.0 releasedVia Slashdot I found out about bash version 4.0 being out. Bash is the GNU Project's Bourne Again SHell, a complete implementation of the POSIX.2 shell spec, but also with interactive command line editing, job control on architectures that support it, csh-like features such as history substitution and brace expansion, and a slew of other features. The new version fixes several bugs in the 3.x releases and introduces a bunch of new features. The most notable ones are associative arrays, improvements to the programmable completion functionality, case-modifying word expansions, co-processes, support for the `**' special glob pattern, and additions to the shell ...
-
02.18.09AliasThis command, when invoked without arguments, shows the list of aliases in your shell session: $>alias alias dir='ls -l' alias l='ls -alF' alias md='mkdir -p' It also allows you to create your own aliases: $>alias lc='ls --color' If for some reason, you want to delete an alias, you can use the unalias command: $>unalias lc Aliases can help you saving a lot of time by avoiding repetitive and long commands and options. If you want them to be permanent, you should add those definitions to your .bashrc file.
-
02.14.09Is your site up?When I cannot reach one of my sites, I do not know if it is my problem, my ISP's or my hosting provider's. This is why I use the service down for everyone or just me. I have written a simple script which uses that service. Its usage is: $ ./is_up.sh commandliners.com commandliners.com is up and the script is: #!/bin/bash # is_up.sh # 2009 - Rafa Casado - rafacas@commandliners.com numargs=$# if [ $numargs -ne 1 ] then echo "Usage: $0 domain" echo "Ex: $0 commandliners.com" exit 1 fi DOMAIN=$1 IS_UP=`wget -nv -O ...
-
02.02.09Currency conversion scriptIn this time of crisis perhaps we need to pay more attention to financial issues. I am interested in converting some currencies so I have written a script that given two currencies, converts on to the other. The script searches the info on Google Finance's page. An example of its usage is: $ ./currencies.sh EUR USD 1 EUR = 1.316 USD The available currencies are: EUR - Euros USD - United State Dollar GBP - British Pound JPY - Japanese Yen CHF - Swiss Franc CAD - Canadian Dollar AUD - Australian Dollar INR - Indian ...