Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Friday, February 6, 2009

Looking for content within files in Linux

Within your directory, type the following command:

sudo find . -print xargs grep "pattern to search for"

or if you have the name type, you can try

sudo find . -name "*.pl" xargs grep "pattern to search for"

Wednesday, January 21, 2009

Wednesday, October 1, 2008

Looking for files inside Linux

A command that i somehow cannot remember, dead easy but oh well:

$> find / -name *isr

Monday, September 22, 2008

Makefiles in C

Typically in most c programs (especially those written for opensource purposes), there exist a file call Makefile. Makefile is pretty much like a macro (for those familiar with Microsoft Office), or a batch file (for those familiar with DOS). Well basically, in very simple terms, it automates repetitive stuffs so that it makes life easier to program.

In a huge program, we tend to have many classes and dependencies (i.e. header files). For example, if we have a single program4 file which is make up of program1.c, program1.h which in turn make up program2.c together with program3.c to make the final program4 file.

In this example, the modification of program1.c will result in a recompilation of program1.c and program3.c which is technically inefficient. Imagine having to do this each time you are trying to debug and found a bug. So to make life easier, Makefile comes to the rescue. It basically automate compilation so that we don't have to type a long string of dependencies from scratch each time we make modification.

For a proper tutorial on how to create your own Makefile, visit:
http://www.eng.hawaii.edu/Tutor/Make/3.html

In very short term, in order to execute the makefile, run the command "make" inside a folder.
Yes, correct, just type
"make" and hit ENTER. A chunk of output should normally appear, type "ls" and the executable program (normally in green) can be seen.

Random Linux Commands

cp - copy files from one place to another
chown - change owner of the file or directory
chmod XXX - change the access permission to the file or directory
ls -all - list the entire directory and files information
rm - remove filename
rmdir - remove directory
apt-get install - install the filename of the specified package name
apt-get update, - update the existing repository list specified in /etc/apt/sources.list
apt-cache search - search the list of packages by the term specified

GIT Repository

GIT is pretty much like a repository to faciliate sharing of work amongst developers (mostly), you need to know this if you are looking at open source development, let me introduce a few commands that may potentially be useful:

1. git clone - this clones the directory of the repository.
e.g. git://scarlet.aura.cs.cmu.edu/openisr.git

2. git push - this pushes the files from your local drive to the central repository (the default is master for the first file) If there are some errors, in regards to non-fast-foward, use the -f option.
e.g. ssh://aarontwc@scarlet.aura.cs.cmu.edu/~aarontwc/openisr.git master

http://davitenio.wordpress.com/2008/10/08/synchronize-git-repositories-between-deskop-and-laptop/

3. git add . - this command adds the existing files in the correct directory to be commited. Basically, it specifies the files to be committed into GIT.

4. git commit -m "message to commit", (instead of just typing git commit, having the -m parameter, allows you to put meaningful text messages to commit, so that its easier for you to track your changes later.

5. git show - this command allow you to see the list of commits make, when and why


6. git pull - this command pulls the latest updates to your local repository.

Kernal.org has a comprehensive guide on GIT.

VIM Editor

An alternative to the EMACs/Nano (my favourite), due to the usage of GIT, (a CVS program), i have to start learning VIM, here are some useful commands to remember.

1. There are different modes in this editor. To get into editing mode, we need to hit "i", (which is the equivalent of insertion. To escape from editing mode after we are done, we need to hit the 'ESC" key which will then bring us to the main prompt.

2. It allows us to do stuffs faster here in he main prompt, for example, by typing "d" on a line, it allows us to remove the entire line.

3. To save, type, "ZZ" (Shift + Z + Z) or use ":x" (Colon + x + ENTER), this qill automatically save and quit. To quit, go outside insertion mode (press ESC), and then type "ZQ" (Shift + Z + Q) or ":q!" (Colon + q + ! + ENTER). The program will quit without saving.

4. To do more complete stuffs like after being able to recover from a lost SSH connection, look under the area of a swap file. When we try to access the file, it will say something like the file already exist. do you want to edit, recover, delete, quit or abort.

Try the following steps to recover the files or do side by side comparion of iles
1. hit "r" when it asked what you want to do (to recover)
2. :sav! /tmp/%
3. :vs
4. :diffthis
5, CTRL + W + I
6. :bp
7. e (to edit anyway)
8. :diffthis (finds the difference between the two files side by side)

Right that should be all you ever need to know about VIM for basic usage.