Searching for files in Linux with ack-grep
The ack-grep tool is suitable for searching within files on the command line under Linux. In this article, you will find information on how to use ack-grep.
Installation
You can install ack-grep with the following command on Ubuntu
sudo apt-get install ack-grep
Search for file content
Use the following command to search for the specified search term in all files in the local directory and all subdirectories. Capital and small letters are not taken into consideration (-i parameter):
ack-grep -i "search term"
Supported file types
ack-grep shows all supported file formats with the following call:
ack-grep --help=types
The following example shows the output on Ubuntu 14.04:
admin@ubuntu-1404:~$ ack-grep --help=types
Usage: ack-grep [OPTION]... PATTERN [FILES OR DIRECTORIES]
The following is the list of filetypes supported by ack-grep. You can
specify a file type with the --type=TYPE format, or the --TYPE
format. For example, both --type=perl and --perl work.
Note that some extensions may appear in multiple types. For example,
.pod files are both Perl and Parrot.
--[no]actionscript .as .mxml
--[no]ada .ada .adb .ads
--[no]asm .asm .s
--[no]asp .asp
--[no]aspx .master .ascx .asmx .aspx .svc
--[no]batch .bat .cmd
--[no]cc .c .h .xs
--[no]cfmx .cfc .cfm .cfml
--[no]clojure .clj
--[no]cmake CMakeLists.txt; .cmake
--[no]coffeescript .coffee
--[no]cpp .cpp .cc .cxx .m .hpp .hh .h .hxx
--[no]csharp .cs
--[no]css .css
--[no]dart .dart
--[no]delphi .pas .int .dfm .nfm .dof .dpk .dproj .groupproj .bdsgroup .bdsproj
--[no]elisp .el
--[no]elixir .ex .exs
--[no]erlang .erl .hrl
--[no]fortran .f .f77 .f90 .f95 .f03 .for .ftn .fpp
--[no]go .go
--[no]groovy .groovy .gtmpl .gpp .grunit .gradle
--[no]haskell .hs .lhs
--[no]hh .h
--[no]html .htm .html
--[no]java .java .properties
--[no]js .js
--[no]json .json
--[no]jsp .jsp .jspx .jhtm .jhtml
--[no]less .less
--[no]lisp .lisp .lsp
--[no]lua .lua; first line matches /^#!.*\blua(jit)?/
--[no]make .mk; .mak; makefile; Makefile; GNUmakefile
--[no]matlab .m
--[no]objc .m .h
--[no]objcpp .mm .h
--[no]ocaml .ml .mli
--[no]parrot .pir .pasm .pmc .ops .pod .pg .tg
--[no]perl .pl .pm .pod .t .psgi; first line matches /^#!.*\bperl/
--[no]perltest .t
--[no]php .php .phpt .php3 .php4 .php5 .phtml; first line matches /^#!.*\bphp/
--[no]plone .pt .cpt .metadata .cpy .py
--[no]python .py; first line matches /^#!.*\bpython/
--[no]rake Rakefile
--[no]rr .R
--[no]ruby .rb .rhtml .rjs .rxml .erb .rake .spec; Rakefile; first line matches /^#!.*\bruby/
--[no]rust .rs
--[no]sass .sass .scss
--[no]scala .scala
--[no]scheme .scm .ss
--[no]shell .sh .bash .csh .tcsh .ksh .zsh .fish; first line matches /^#!.*\b(?:ba|t?c|k|z|fi)?sh\b/
--[no]smalltalk .st
--[no]sql .sql .ctl
--[no]tcl .tcl .itcl .itk
--[no]tex .tex .cls .sty
--[no]tt .tt .tt2 .ttml
--[no]vb .bas .cls .frm .ctl .vb .resx
--[no]verilog .v .vh .sv
--[no]vhdl .vhd .vhdl
--[no]vim .vim
--[no]xml .xml .dtd .xsl .xslt .ent; first line matches /<[?]xml/
--[no]yaml .yaml .yml
More information
- Beyond grep: ack 2.14 is a tool like grep, optimized for programmers (beyondgrep.com)
- ack-grep manpage (manpages.ubuntu.com)
|
Author: Werner Fischer Werner Fischer, working in the Knowledge Transfer team at Thomas-Krenn, completed his studies of Computer and Media Security at FH Hagenberg in Austria. He is a regular speaker at many conferences like LinuxTag, OSMC, OSDC, LinuxCon, and author for various IT magazines. In his spare time he enjoys playing the piano and training for a good result at the annual Linz marathon relay.
|
|
Translator: Alina Ranzinger Alina has been working at Thomas-Krenn.AG since 2024. After her training as multilingual business assistant, she got her job as assistant of the Product Management and is responsible for the translation of texts and for the organisation of the department.
|


