Leatherboard1

Linux Shell, Bash tutorial

I read a popular bash tutorial in digg which disappointed me so much. Bash is so much more powerful once you get a good hold of the tools. Oneliners and scripts will let you take full control your computer and increase productivity infinitely.

So starting from today, I'll be writing a little bit down each day and when Christmas comes, I'll put them all in organization and make it much more helpful.

This is not a crazy list of linux commands, instead, learn a bit a day, you'll find them really useful.

1. cat

If you want to have a quick look at a document or quickly create a document (with contents) then what do you do?

cat 1.txt to view the document and cat > 1.txt to enter contents for it.
If you want to simply create some empty documents however, you can use touch.
touch new.txt creates you a new empty document. If you want to massively create documents, then use:
seq 1 100 | xargs -i touch {}.txt , that creates you 100 txts...
seq 1 100 | xargs -i rm -f {}.txt

A much better way to write the above code however, is to use this:
seq 1 100 | xargs -i echo touch {}.txt | bash
And you can always run seq 1 100 | xargs -i echo touch {}.txt to see if your commands are correct.
It never occurs natural to me but I'll force myself to follow the critierion of completing my command then pipe it to bash. It is better this way because you always know what you are going to run before you actually execute it.

The last two commands utilizes xargs -i in the obvious way. They were both a little clumsy because we wouldn't really use it that way. We'll echo it and pipe it to bash but since this is the beginning of the tutorial, it'll be added afterwards.

On viewing the contents of a document, there are two more interesting functions. You can call head -n and tail -n to view the first and last n lines of a file.

seq 1 100 | cat > 1.txt and use head and tail to see how the two functions work.

This is interesting. Let me see more. : 2. It's all about the small things, wc, ls.



Technorati : , ,
Del.icio.us : , ,

No comments: