Showing posts with label find. Show all posts
Showing posts with label find. Show all posts

Tuesday, January 18, 2011

how to find the pattern within files?

Using grep we achieve this..
Say we have to find out the word "gdk" from all the '.c' files in a directory.. the command would be

$grep -i "pattern" files

ex: $grep -i "gtk" *.c          <===== Will search all .c files in the current directory.
ex: $grep -i "gtk" file1, file.23, file <== Will search only in the specified files.

Wednesday, December 29, 2010

Using "ls" and "find" command how to display only directories..?

Following commands list only directories in the current directory.

1. #ls -l | grep ^d

2. #ls -d */

3. #find -type d
Ex: #find /tmp -type d <-- This command shows all the directories with in the /tmp directory.

Want only files to be listed.. use 1. #ls -l | grep -v ^d

2. #find -type f
Ex: #find /tmp -type f <-- This command shows all regular files with in the /tmp directory.