Thursday, April 17, 2014

5:45 PM
Good day!

Hello and welcome to another article on my howto; this time we will learn the basics on how to use the grep and mv commands effectively on *nix.These commands are to be run from the shell command prompt.

This is the fifth part of my howto in "Learning Linux/UNIX"


grep

print lines matching a pattern. This command is important when searching for a word in large files. It used to search for lines of text that matches one or many regular expressions and outputs the matching lines filtered.

usage:

grep [argument] [file name] - search for a file that contains the argument for example screenshot below:


What it did was to find the argument 'phone' in the file contact. If the argument consists of two or more words then it must be enclosed in single quotes.

Take note that you can also use it in shell pipes, ex:

$ netstat -an | grep tcp


mv


move (rename) files. To move SOURCE directory to a DEST directory use the mv command as follows:


usage:

mv [file name(s)] [ dir name ] - renames a file or moves it to another directory eg.



The screenshot above renames the file contact to contacts thereby deleting contact or if you want to move files then...

$ mv /home/index/docu/apps /home/index/installer/apps

This moves the file apps to the directory named installer.

Thanks for reading guys.. Happy vacation!

0 comments:

Post a Comment