1. Homepage
  2. Articoli
  3. Video
  4. Bash scripting
  5. Sistema
  6. Tips
  7. News


Bash tips

» Author: Andrea Ganduglia Date: 2010-07-05 14:07:15 Copyright: (c)2007 Andrea Ganduglia

Indice dei contenuti


Una semplice TODO list

alias cd='readme'

    readme() {
        TODO=".todo"
        cd "$@"
        if [ -f "$TODO" ]; then
            echo "== TODO =="
            cat $TODO
            echo ""
        fi
    }

Customizzare Login

Per customizzare i messaggi al prompt dopo il login editare /etc/motd e /etc/motd.tail

sort

Interessante articolo che spiega come usare sort per ordinare record secondo i campi:
http://www.cyberciti.biz/faq/linux-unix-sort-date-data-using-sortcommand/

es:

2008 ^ 09 ^ 21 ^ Basta con PHP
2007 ^ 07 ^ 13 ^ Accendi il computer
2008 ^ 12 ^ 17 ^ Impara la Shell

cat dati.txt | sort -t^ -k 1 -k 2 -k 3 -n

2007 ^ 07 ^ 13 ^ Accendi il computer
2008 ^ 09 ^ 21 ^ Basta con PHP
2008 ^ 12 ^ 17 ^ Impara la Shell

cat dati.txt | sort -t^ -k 3 -n

2007 ^ 07 ^ 13 ^ Accendi il computer
2008 ^ 12 ^ 17 ^ Impara la Shell
2008 ^ 09 ^ 21 ^ Basta con PHP

cat dati.txt | sort -t^ -k 4

2007 ^ 07 ^ 13 ^ Accendi il computer
2008 ^ 09 ^ 21 ^ Basta con PHP
2008 ^ 12 ^ 17 ^ Impara la Shell

Argument list too long

Common issue

$ ls cache* | wc -l
-bash: /bin/ls: Argument list too long
0
$ find . -iname cache* -print | wc -l
-bash: /usr/bin/find: Argument list too long
0
$ find cacheSQL* -print | wc -l
-bash: /usr/bin/find: Argument list too long
0

Quick solution

$ find . -iname "cache*" -print | wc -l
8873

Randomizzare una lista

Per ordinare random le linee di una lista si può utilizzare la variabile $RANDOM.

for i in *; do echo "$RANDOM $i"; done | sort -n | awk '{print $NF}'