Live Chat!

How to redirect output to a file as well as display it out

* * * * * 1 votos

December 6th, 2007 mysurface

To redirect standard output to a file is easy, you just need to use the redirection symbol, for example:
echo “hello world” > test.txt
But what if I want to display it out as well as store into a file?
Answer: tee
echo “hello world” | tee test.txt
Okay it seems very easy, how about append?
Related PostsRedirect stderr to stdoutVery [...]

Posted in Text Manipulation, pipeline, python, tee | Hits: 28417 | 1 Comment »

CLI magic: programable bash completion

* * * * * 3 votos

May 4th, 2007 mysurface

Ubuntu, a Linux distribution that is getting popular because it has successfully improves it’s user friendliness with simple User interface. You can install any applications with few clicks, configuration under GUI dialogs etc. People usually have the thinking of maybe one day, Ubuntu will become another new operating system like Microsoft Windows.
Never! The concept of [...]

Posted in Bash, apt-cache, apt-get, complete, pipeline, sort, svn | Hits: 27980 | 5 Comments »

Enable a user to gain write permission when mounting

          0 votos

October 10th, 2006 mysurface

We need to perform mounting with root privilege, but after a simple mounting, we need to be root in order to write to the mounting point. This is the default for a simple mounting, check out more mounting examples here.

But we can grant the mount point ownership to other user besides root. We can do [...]

Posted in Admin, cat, mount, pipeline | Hits: 8598 | No Comments »

easily extract a column of data from multiple columns

          0 votos

October 2nd, 2006 mysurface

To extract a column of data from multiple column, we can use cut. Usually cut use to extract value from huge trace file or data file such as /etc/passwd.
To extract all available user name from /etc/passwd, you can do this
cut -d”:” -f1 /etc/passwd
Cut extract value line by line, to put all into 1 line, you [...]

Posted in Misc, Text Manipulation, cut, pipeline, xargs | Hits: 11614 | 2 Comments »

xargs use stardard output as parameter for another command

          0 votos

October 2nd, 2006 mysurface

xargs is a command line of findutils package. It is not so common for new user, but it is a very useful tools, let me pick an example to show the usage. Bare in mind, xargs is a kind of combo command use together with other command through pipeline.
I have a list of links to [...]

Posted in Text Manipulation, cat, pipeline, wget, xargs | Hits: 11267 | 9 Comments »

Redirect stderr to stdout

* * * *   1 votos

October 1st, 2006 toydi

Very simple, just remember:

1 = stdout
2 = stderr

In python, its
unittest
module loves to dump test results to stderr (rather than stdout). In order to pipe the results to
less
, you may need to redirect stderr to stdout:
python eggtest.py 2>&1 | less

To redirect stderr into a file:
python eggtest.py 2> result.txt
To redirect both stdout and stderr into a [...]

Posted in pipeline, stderr, stdout | Hits: 12550 | 1 Comment »

generate and print a sequence of number

          0 votos

September 28th, 2006 mysurface

To generate a sequence of number we can use seq
seq 1 10
With this it prints 1 to 10 line by line, because by default separator is new line, anyway you can check, do this
seq -s” ” 1 10
Doing this it change new line to a single blank space.
But that is the usage of the this [...]

Posted in Misc, Text Manipulation, backquote, cat, pipeline, seq, wc | Hits: 9813 | 1 Comment »

query using debian packaging manager

          0 votos

September 24th, 2006 mysurface

I am here to show you two examples of using dpkg to query package info.
To know what deb package is installed, you can do this
dpkg -l
Usually we do this with grep, to filter only info that we are interested in, let say i want to know the packages consist of keyword gcc.
dpkg -l | grep [...]

Posted in Admin, backquote, dpkg, grep, pipeline, which | Hits: 6796 | 2 Comments »

get to know which command use to trigger the GUI program

          0 votos

September 9th, 2006 mysurface

If you are light weight windows manager user which depend on certain desktop such as kde, gnome, sometimes you want to know what is the command that call a particular program that you usually click with your mouse in kde/gnome, so that you can run it in console or trigger with key mapping.
You can get [...]

Posted in X11, grep, pipeline, xprop | Hits: 4062 | No Comments »

Command line calculator, bc

* * * * * 1 votos

September 4th, 2006 mysurface

How to do calculation if I only have command line? If you have BC you can, and you can do a very complicated calculation. To perform calculation, you can type bc and start to type your question, or passing question through pipeline, such as
echo “56.8 + 77.7″ | bc
Let say you want to convert decimal [...]

Posted in Calculation, bc, pipeline | Hits: 8695 | 7 Comments »