Tag Archives: bash

alias ll=?

On Ubuntu the default alias for ll is:

alias ll='ls -alF'

but my favourite one is:

alias ll='ls -lrhat --group-directories-first'

(or “list sorted by modification time, reversed, in long format, human readable with folders first”).
To remember it I just remember “Linux Red HaT” (my firsto distro in nineties)

What’s yours?

Leave a comment

Posted by on 2016/01/28 in sys


Tags: , , ,

cygwin (reinstall)

My work HDD is dead so I’m reinstalling a lot of stuff…
One annoying thing is that cygwin starts in /home/myself, while I’d like to use /cygdrive/c/Users/myself.

The trick is to set an environment variable under windows called HOME with the home path (/cygdrive/c/Users/myself) as value, then open cygwin and:

cp /home/myself/.bash* .


Here’s my to-reinstall checklist (what have I forgotten?):

  • Firefox
  • Brackets
  • Git
  • Node.js
  • cygwin
  • KeePassX (0.4)
  • SpiderOak
  • DropBox
  • Notepad++
  • Gimp
  • Telegram
  • 7zip
  • RDCman
  • VirtualBox
Leave a comment

Posted by on 2016/01/26 in sys


Tags: , ,

Find In Files

This is a tiny helper post: on bash (or cygwin =) most of the times I need to search some text inside many files.

Here’s the command:

find . -type f -name '*filter*'|xargs grep 'text to find' --color=auto

It searches the ‘text to find’ string inside every file named *filter*, starting from the ‘.’ folder.

There’s another way to search a string inside many files, listing the file info instead of the text found:

find . -type f|xargs grep -l 'text to find'| xargs ls -l

The “-l” (lowercase L) in the “grep” command means “list only filenames”. Every filename is then listed using the long listing format (lowercase L in the “ls” command).

Leave a comment

Posted by on 2013/07/23 in dev



Running multiple bash commands inline

‘&’ just runs the command in the background.

ls &

Remember that if the running command receives an HUP interrupt (maybe you’re closing the terminal), it will be killed.
If you want the command will survive your ‘exit’, you can launch the command with the nohup

nohup ls &

‘&&’ is to concatenate two commands (AND): the second command will only run if the first command finishes successfully, that is if it sends an exit code of 0.

command1 && command2

‘||’ is to concatenate two commands (OR): the second command will only run if the first one fails in some way (exit code is not 0; the command exited with an error).

command1 || logErrorAndExit1

‘;’ is to concatenate two commands: the second command will start right after the first one finishes, no matter whether it succeeds or not.

command1 ; command2
Leave a comment

Posted by on 2013/04/18 in dev


Tags: ,

Removing old kernels

Sometimes it’s just time to cleanup…and I, as always, like to work on a command line.

I found that the better way to remove old kernels is just to launch the purge command (incredible, don’t you think? 🙂 but I NEVER remember its correct syntax …
I made up a bash script that remember me how to do all that stuff:

# It just prints the purge commands ready to be copied pasted in a shell

KERNEL=`uname -r`
OLDKERNELS=$(dpkg -l | grep linux-image |grep -v image-generic|grep -v $KERNEL|awk '/^ii/{ print $2 }')

echo "Now using kernel $KERNEL ..."
echo " "

echo "To remove unused kernels (please, check them ALL!):"
while read PKG
  echo "sudo apt-get purge $PKG"
done < <(echo "$OLDKERNELS")
echo " "

I’m actually using a ‘process substitution’ (see LinuxJournal) that is not not POSIX compliant, but it works.

Finally, if you have GRUB installed on an external partition (mounted on /media/GRUB), you’ll need also to print:

echo "To rebuild GRUB:"
echo "sudo grub-mkconfig -o /media/GRUB/boot/grub/grub.cfg"
Leave a comment

Posted by on 2013/03/21 in sys


Tags: , , ,

How to create a script library in Bash

Create your common routines file (i.e. naming the file “”):

function fn1
  echo "fn1 called"
function fn2
  echo "fn2 called with parameter: " $1

Then “include” the library at the top of your bash script to use your common functions:

. "./"
fn2 "i'm the parameter"

This way the library file will be executed at the beginning, making all the functions ready to be called.

Leave a comment

Posted by on 2013/03/12 in dev


Tags: , , ,