Showing posts from December, 2013

Shell Script Examples

Bourne Again Shell (bash) is the common shell used in Unix/Linux based Operating Systems. Also these days, even Windows OS also comes with an option called Power Shell.  This post will list out some basic exercises that a shell can do. Do follow this blog with more number of exercises. To run a bash file, you can use either of these following commands bash sh ./ (in this case the should be made executable) For making executable file, use this command  chmod 755 1. A Shell to Handle a File, rename a given file, compress it and move it to a newfolder and decompress it in the newfolder 1: #!/bin/bash 2: touch pri.txt 3: ls > ; pri.txt 4: mv pri.txt file.doc 5: tar zcvf compress.tar.gz file.doc 6: mkdir newfolder/ 7: cp compress.tar.gz newfolder/ 8: cd newfolder/ 9: tar zxvf compress.tar.gz 2. A shell to find a particular string from a file and redirect it to another file.   #!/bin/bash echo "Enter a string