Search This Blog

Sunday, April 24, 2011

Less tricks in linux on the bash command line

Some tricks that is worth to know when working on the linux bash cli that can save you a lot of time.

1. To tell less to normal print the raw control character of your stream you can use the '-r' or '-R' options.

$ ls -la --color | less -X 
total 3284
drwxr-xr-x 90 radoslaw radoslaw   4096 2011-04-24 10:22 ESC[0mESC[01;34m.ESC[0m
drwxr-xr-x  4 root     root       4096 2010-08-02 20:37 ESC[01;34m..ESC[0m
drwx------  5 radoslaw radoslaw   4096 2011-01-31 12:18 ESC[01;34m.adobeESC[0m
drwxr-xr-x  4 radoslaw radoslaw   4096 2009-11-07 20:53 ESC[01;34m.ankiESC[0m

$ ls -la --color | less -X -r
total 3284
drwxr-xr-x 90 radoslaw radoslaw   4096 2011-04-24 10:22 .
drwxr-xr-x  4 root     root       4096 2010-08-02 20:37 ..
drwx------  5 radoslaw radoslaw   4096 2011-01-31 12:18 .adobe
drwxr-xr-x  4 radoslaw radoslaw   4096 2009-11-07 20:53 .anki

2. To list only #n lines from the input with or without the raw characters being interpreted.

$ ls -la --color | cat -t | head -10
total 3284
drwxr-xr-x 90 radoslaw radoslaw   4096 2011-04-24 10:22 ^[[0m^[[01;34m.^[[0m
drwxr-xr-x  4 root     root       4096 2010-08-02 20:37 ^[[01;34m..^[[0m
drwx------  5 radoslaw radoslaw   4096 2011-01-31 12:18 ^[[01;34m.adobe^[[0m
drwxr-xr-x  4 radoslaw radoslaw   4096 2009-11-07 20:53 ^[[01;34m.anki^[[0m

$ ls -la --color | head -10
total 3284
drwxr-xr-x 90 radoslaw radoslaw   4096 2011-04-24 10:22 .
drwxr-xr-x  4 root     root       4096 2010-08-02 20:37 ..
drwx------  5 radoslaw radoslaw   4096 2011-01-31 12:18 .adobe
drwxr-xr-x  4 radoslaw radoslaw   4096 2009-11-07 20:53 .anki

3. To list files with line numbers.

$ less -N -X /etc/init.d/networking 
      1 #!/bin/sh -e
      2 ### BEGIN INIT INFO
      3 # Provides:          networking
      4 # Required-Start:    

$ ls -la --color | cat -n -t | head -5
     1 total 3284
     2 drwxr-xr-x 90 radoslaw radoslaw   4096 2011-04-24 10:22 ^[[0m^[[01;34m.^[[0m
     3 drwxr-xr-x  4 root     root       4096 2010-08-02 20:37 ^[[01;34m..^[[0m
     4 drwx------  5 radoslaw radoslaw   4096 2011-01-31 12:18 ^[[01;34m.adobe^[[0m
     5 drwxr-xr-x  4 radoslaw radoslaw   4096 2009-11-07 20:53 ^[[01;34m.anki^[[0m

$ ls -la --color | cat -n | head -5
     1 total 3284
     2 drwxr-xr-x 90 radoslaw radoslaw   4096 2011-04-24 10:22 .
     3 drwxr-xr-x  4 root     root       4096 2010-08-02 20:37 ..
     4 drwx------  5 radoslaw radoslaw   4096 2011-01-31 12:18 .adobe
     5 drwxr-xr-x  4 radoslaw radoslaw   4096 2009-11-07 20:53 .anki

Reference:

No comments:

Post a Comment