Searching For and Inside Files (find, grep)

The command find is used to find files with various attributes. It has many options. This makes it somewhat awkward for just searching for a file by name. For example, the command

finds all the files in the current directory and any directories below that have a name which ends in .tex and then prints the result of the search at the terminal.

The program grep looks inside files for specified text. For example,

will search the file paper.tex for any occurrences of the text Diophantine” and then then print those lines at the terminal. If you are searching in more than one file as in grep Diophantine *.tex it will print the name of the file in which the line was found.

 

How To Search Inside Files Via The Terminal in Linux

find ./ -name “*.ext” -print | xargs grep “keyword”

In the command given above, you have to change “.ext” with the file extension you are going to search inside, then replace “keyword” with text you want to search.

Here is an example:

find ./ -name “*.php” -print | xargs grep “

–> This command will search inside the current folder all PHP files for this code: “”.

Here is another example:

find ./ -name “*.txt” -print | xargs grep “How to unlock”

–> This command will search all text files under the current folder for this keyword: “How to unlock“.

opencv ubuntu setup, debian and configuration of library

/* Installing OpenCV 2.3 in Ubuntu.I had a lot of problems initially to install and port the OpenCV library to Python. But after reading a lot of blogs I finally found a solution which I have posted below. */
1)Install all pre requisites

 

2)Install the python development headers
sudo apt-get install python-dev 

3)Download the source code:
http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.3/

4)Go to the directory where OpenCV is downloaded via the terminal only and then un zip the package:
(note:- It is recommended that you move the downloaded OpenCV package to the home/ directory

5)Now make a new directory called build and go in to it
mkdir build & cd build

6)Run Cmake

7)Now make

make

8) Make it permanent

sudo make install

9)Configuring OpenCV for using shared libraries:

sudo gedit /etc/ld.so.conf.d/opencv.conf

Add the following line at the end of the file (it may be an empty file, that is ok) and then save it:

Close the file and run the following command to configure the library:

sudo ldconfig

OR RUN : export LD_LIBRARY_PATH=/usr/local/lib
10)Open your .bashrc file and add the following:

Save and close the file

11) Reboot the system

http://ubuntuone.com/0qwnXh8VoufDMHGiu5kLIK

Code::Blocks is an GPL based and cross-platform IDE. This is the tutorials using Code::Blocks with OpenCV.

There are 2 different ways to configure OpenCV (shown below), but first you should create a new project:

Create a simple console project.

We can use project wizard to create a simple console project. Here is the steps

Give this project name of “test_opencv”

Then copy some sample code to main.cpp, such as the contents of "C:\OpenCV\samples\cpp\kutayzorlu.cpp"

Configuring Code::Blocks for OpenCV v2.4

Now you need to configure the compiler to find the OpenCV header files and libraries. There are 2 different ways you can configure Code::Blocks for OpenCV v2.4. OpenCV was made of just 4 libraries originally (until v2.1), but now there are many more library files, so you are highly recommended to use the tool “pkg-config” (as mentioned on CompileOpenCVUsingLinux), but if you are using MinGW on Windows then you might prefer the manual method.

  1. Automatically with the pkg-config tool (easier with Linux or Mac).
  2. Manually adding the OpenCV library (easier with MinGW on Windows).

Configuring Code::Blocks for OpenCV using pkg-config

pkg-config is a free command-line tool (available on Windows, Mac and Linux) that should have been automatically setup correctly if you built OpenCV with CMake. Open a command-line and enter pkg-config opencv –cflags or pkg-config opencv –libs, it will display the compiler and linker arguments to successfully compile your own OpenCV projects without worrying about where OpenCV is installed or worrying about which version you have installed, or how to link to the library in each Operating System, etc. If you get an error that it does not know what pkg-config is, then install pkg-config yourself (Linux or Mac can use the official release, but for Windows (MinGW) you should use the tool pkg-config-liteinstead).

If you were compiling your project on the command line you could type:

(Note: pkg-config is surrounded by back-tick characters, not quote or apostrophe characters (its usually the same key as the Tilda key ~, next to the 1 and Esc keys).

To setup Code::Blocks to use pkg-config, first you should right-click on your project and open the “Build options …” dialog.

Now you can simply put this into “Linker settings -> Other linker options”:

And put this into “Compiler-> Other options”:

(Remember to include the back-tick characters, by copy-pasting those lines directly into Code::Blocks).

The beauty of this method is that it should work for Linux, Windows and Mac, and for all versions of OpenCV, whereas the old manual method has different lib filenames for different Operating Systems and different versions of OpenCV.

Troubleshooting

If you have tried the pkg-config method above but Code::Blocks does not find OpenCV headers and libs but you have verified that pkg-config works for OpenCV on a command-line, then Code::Blocks probably doesn’t know where pkg-config is installed. So you should place a link into "/usr/bin/" (Linux & Mac) or "C:\Windows\" (Windows) so that it will be found. For Linux or Mac, you can find the path to pkg-config if you type this into a terminal:

This might print something like “/opt/local/bin/pkg-config”.

So then type this in a terminal:

This allows accessing pkg-config from the most common program folder “/usr/bin/” as well as it’s actual location.

Configuring Code::Blocks for OpenCV v2.4 manually

In this tutorial I will be using OpenCV v2.4.2 and Code Blocks v10.05 with GNU compiler (MinGW) on Windows 7. To work on OpenCV with Code Blocks you just need to add some OpenCV libraries and the folder with OpenCV header files. Following are some simple steps that I followed:

1.  http://sourceforge.net/projects/opencvlibrary/files/opencv-win/,

2.  installed OpenCV to “C:\OpenCV”, so adjust the paths if you installed somewhere else)。In Code::Blocks, goto the menu “Settings > Compiler and Debugger > Search Directories”. Then goto “Add” and add the directory “C:\OpenCV\include\opencv”. This will let your project find the OpenCV header include files when compiling (before linking):

4. In the Linker tab, add the directory "C:\OpenCV\build\x86\mingw\lib":

5. Now click on “Linker Settings”. Add all the .lib files from "C:\OpenCV\build\x86\mingw\lib" (many files). This will let you project link to OpenCV libraries:

6. That’s it!! Now you are ready to run your first OpenCV program. I tested a sample program “kutayzorlu” in the folder “C:\OpenCV\samples\cpp\kutayzorlu.cpp”.

Alternative method, for OpenCV 2.2

In order to make OpenCV 2.2 (containing C++ code) work under Windows with Code::Blocks and MinGW, Matthew (mazeus12 on the mailing list) did the following:

As mentioned in "OpenCV-2.2.0-win-README.txt""OpenCV-2.2.0-win32-vs2010.exe" does not contain binaries for MinGW so they need to be built from the contents in "OpenCV-2.2.0-win.zip".

Steps to build OpenCV 2.2 with Code::Blocks and MinGW:

1. Install Code::Blocks (10.05) with the (MinGW) C++ compiler option. This should among other install the C++ compiler and mingw32-make to"C:\Program Files\CodeBlocks\MinGW\bin" (I also tried to install the latest MinGW using "mingw-get install gcc g++ mingw32-make" from www.mingw.org but I got an error in extracting some files…)

2. Add "C:\Program Files\CodeBlocks\MinGW\bin" to system PATH (at your own judgment: remove any other paths to MinGW (SomehowDevCpp MinGW paths with probable different versions messed up the build process))

3. Install Cmake (2.8)

4. Extract "OpenCV-2.2.0-win.zip" to "C:\OpenCV-2.2.0-win" (It creates a second folder so the final destination looks like that: "C:\OpenCV-2.2.0-win\OpenCV-2.2.0")

5. Run Cmake (cmake-gui)

6. Set the source code: "C:\OpenCV-2.2.0-win\OpenCV-2.2.0"

7. Set where to build the binaries: e.g. "C:\OpenCV2.2MinGW"

8. Press configure

9. Let Cmake create the new folder

10. Specify the generator: MinGW Makefiles

11. Select “Specify native compilers” and click next

12. For C set: C:/Program Files/CodeBlocks/MinGW/bin/gcc.exe

13. For C++ set: C:/Program Files/CodeBlocks/MinGW/bin/g++.exe

14. Click finish

15. In the configuration screen type in “RELEASE” (or “DEBUG” if you want to build a debug version) for “CMAKE_BUILD_TYPE”. Select BUILD_EXAMPLES if you want (I didn’t change anything else here like “WITH_TBB” or “WITH_QT” etc. I’ll try that when time comes to use TBB or Qt)

16. Click configure again

17. Click generate

18. Close cmake

19. Go to the command prompt and inside the folder "C:\OpenCV2.2MinGW" type "mingw32-make" and hit enter (takes some time)

20. Then type "mingw32-make install" and hit enter again

21. Open Code::Blocks and create a new C++ project (Configuration similar to the guide: CodeBlocks).

22. In menu: “Project/Build options/Linker settings/Link libraries” add "C:\OpenCV2.2MinGW\lib\libopencv_calib3d220.dll.a" and all the other *.dll.a files in this folder

23. In menu: “Project/Build options/Search directories/Compiler” add "C:\OpenCV2.2MinGW\include" (includes in a new program schould look like this: “#include , #include , #include etc.”)

24. In menu: “Project/Build options/Search directories/Linker” add "C:\OpenCV2.2MinGW\lib" The options in steps 22 – 24 can also be added as global options in menu: Settings/Compiler an Debugger/Global compiler settings/…, so they will apply to any project and opened *.cpp file.

25. If necessary, in menu: Settings/Compiler an Debugger/Global compiler settings/Toolchain executables” specify"C:\Program Files\CodeBlocks\MinGW" for the compiler’s installation directory.

26. Open a sample file (or import it into the project), e.g. "C:\OpenCV2.2MinGW\samples\cpp\dft.cpp" and built it. (If the *.cpp files do not exist in this folder, you can find them in the initial folder where you extracted "OpenCV-2.2.0-win.zip" i.e. "C:\OpenCV-2.2.0-win\OpenCV-2.2.0\samples\cpp")

27. Add "C:\OpenCV2.2MinGW\bin" to the system path

28. Run the program

Configuring Code::Blocks using old method for OpenCV v1.1

Set the include header file path (OpenCV v1.1):

Set the library path (OpenCV v1.1):

Add the libraries (OpenCV v1.1) directive:

Here is another way you can add the include path and lib path in Code::Blocks

First, you need to add a global variable in Codeblocks, see here: You can open this dialog in:

Then you can define the #cv.include and # cv.lib  path, in my system,

fill the include edit bar with(this is where your opencv include path locates) : $(#cv)\OpenCV-2.1.0\include\opencv

fill the lib path with(this is where your opencv libraries locate) : $(#cv)\opencv_build\lib

Later, in your Opencv project, you can change the build options like below:

Also, you can add the libraries by using these linker options:

 

great programs for terminal linux

cmus
cmus is a music player that I admire the most when it comes to command-line because it’s really powerful and has a lot of nice features. It is built with ncurses and therefore providing a text-user interface. cmus is indeed feature-rich, with several view modes and Last.fm song submission support via scripts. It supports Vi-like commands and auto-completion with Tab too. Recently I wrote a full guide on how to use cmus, you can read it here.
Homepage


finch
Finch comes bundled with Pidgin, the popular IM client. Finch offers the same functionality that Pidgin offers, only that it does it in a terminal by using the ncurses library. It supports IM protocols like Yahoo, Google Talk, XMPP (Facebook), WLM (Windows Live Messenger) and more. A while ago I put up a detailed guide to Finch, which you can read here.
Homepage

htop
htop is an interactive process viewer tool using ncurses which has the great benefit that it allows to scroll up and down the list of processes, and it also uses graphs and colors. I think all these make htop a real gem for the Linux user.
Homepage

irssi
Very powerful IRC (Internet Relay Chat) client with an ncurses-based interface, implements multi-server support, can be expanded with Perl scripts, supports themes, DCC chat and every other possible feature IRC servers allow.
Homepage

mc
Midnight Commander is the famous twin-panel file manager for the Linux terminal, also based on ncurses and with lots of features.
Homepage

lynx
lynx is a popular web browser for the terminal. It supports protocols like HTTP, FTP or Gopher.
Homepage

gzip
gzip is a command-line tool for compressing and uncompressing files. All the files that end in a .tar.gz extension are archived with tar and compressed with gzip.
Homepage

bzip2
Same as gzip, bzip2 is a data compressor which takes a longer time to compress and uncompress files, but it also provides a more efficient compression algorithm which results in smaller files.
Homepage

tar
This tool is used to create archived files, and will also work in conjunction with gzip or bzip2. The command to compress a file or folder to gzip is (what follows after # is a comment):

The c argument means compress, the z specifies the type of file to create (gzip file in this case), and f specifies the output file name. The command to uncompress a .tar.gz file:

This will extract the contents of input_file.tar.gz to the current working directory. Here are the commands for bzip2:

Homepage

aaxine
aaxine is a video player for console based on xine-lib multimedia player, using ASCII characters for video output. In Ubuntu it is provided by the xine-console package.
Homepage


…it’s Big Buck Bunny by the way

aview
This tool allows to view images as ASCII art. It only supports the following formats, which are either in binary form or ASCII plain text: PNM, PGM, PBM, PPM. It also supports FLI and FLC video formats.
Homepage

mencoder
mencoder is a powerful video encoder and decoder included in MPlayer and can convert between various video files.
Homepage

ffmpeg
Using libavcodec, ffmpeg is yet another powerful tool to encode/decode, record and stream video files.
Homepage

convert
Included in ImageMagick, convert is a tool that can convert between image formats, and also apply various effects to images or edit certain aspects, including resizing, cropping, blur or dither effects. convert is also used on web servers for image processing.
Homepage

moc
moc (music on console) is yet another ncurses-based music player for the terminal which plays formats like Ogg Vorbis, FLAC, MP3, WAV or WMA. It also supports themes and searching for files.
Homepage

qt how to add new library

Projects  > right click , 1>>  ADD library ,

pro .file    adding libs,

 INCPATH = -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/lib/x86_64-linux-gnu -I/usr/lib/x86_64-linux-gnu -I/usr/lib/x86_64-linux-gnu -I/usr/share/qt4/mkspecs/linux-g++ -I/usr/include/qt4/QtCore -I/usr/include/qt4 -I. -I../Kutuphane_icin_method_test_projesi -I.
#INCPATH = -I/usr/share/qt4/mkspecs/linux-g++ -I/usr/include/qt4/QtCore -I/usr/include/qt4 -I. -I../Kutuphane_icin_method_test_projesi -I.

#LINK = g++
#LFLAGS = -Wl,-O1
#LIBS = $(SUBLIBS) -L/usr/lib/x86_64-linux-gnu -lQtCore -lpthread -lcurl

LINK = g++
LFLAGS = -Wl,-O1
LIBS = $(SUBLIBS) -L/home/sus/Documents/VS2010/C_Projects/Kutuphane_icin_method_test_projesi/../../../../../../usr/lib/x86_64-linux-gnu/ -lQtCore -lQtGui -lQtDesignerComponents -L/usr/lib/x86_64-linux-gnu -lQtCore -lpthread -lcurl