Monday, 27 January 2014

Useful Linux Tools for Code Developers

CFLOW:
  cflow - generate a C-language flowgraph.
  cflow used to print the flow(graph) of external references. cflow has several options, please refer the man page of cflow.

cflow [r][-d num][-D name[=def]] ... [-i incl][-I dir] ... [-U dir] ...
file ... 
 
Examples: temp.c
 
#include<stdio.h>
extern void func4();
int func1();
int func2();

int func2()
{
  func4();
}

int func1()
{
  func2();
}
int main()
{
  func1();
}


Syntax:  
> cflow temp.c  or  cflow -i x temp.c
main() <int main () at temp.c:17>:
    func1() <int func1 () at temp.c:13>:
        func2() <int func2 () at temp.c:8>:
            func4()
 

temp2.c
void func4()
{
}
cflow temp.c  temp2.c
main() <int main () at temp.c:17>:
    func1() <int func1 () at temp.c:13>:
        func2() <int func2 () at temp.c:8>:
            func4() <void func4 () at temp2.c:1>



FIND command
--------------------
"find" command is used to search files in a Linux system. We can search or find files based on different ways using,
  • permissions
  • users,
  • groups
  • file type
  • data
  • size
How to find files using name in current directory ( . ["dot"] operator)?

1. Locate the files in current directory using . (dot) operator.

find . -name <filename>
e.g:root:/home/muni# find . -name sample.c./sample.c

2. How to Find  files under  particular directory

find /<directory-name> -name <file-name>
e.g:
root: find /home/muni -name sample.c
/home/muni/sample.c

root:/# find / -name sample.c
/home/muni/sample.c

root:/# find /home -name sample.c
/home/muni/sample.c

3. How to Find files with ignore case (-iname)

find /<directory-name> -iname <file-name>
e.g:
find /home/muni -iname sample.c

4. How to find directories using  name: (-type d )

find / -type d -name <directory-name>
e.g:
find / -type d -name muni

5.  How to find .sh files using name (-type f)

find /<directory-name> -type f -name <file-name.extension>
e.g:
find / -type f -name setup.sh

6. How to Find all files (using Wildcard)

find /<directory-name> -type f -name <*.extension>
e.g:
find / -type f -name *.sh

How to Find files with permissions (-perm)
find / -type f  -perm 664

How to find files With out permissions of 664
find / -type f ! -perm 664

How to find and remove particular file using  -exec rm -f {} \;
find / -type f -name setup.sh -exec rm -f {} \;

How to find and remove all files having *.sh using  -exec rm -f {} \;
find / -type f -name *.sh -exec rm -f {} \;

How to find files with 0644 permissions and change permissions to 0755
find / -type f -perm 0644 -exec chmod 777 {} \;

How to find empty files (-empty)?
find / -type f -empty

How to find empty Directories?
find / -type d -empty

How to find all files based on particular user?
find / -user muni

Find all files based on Size (-size option)
find / -size 10M -type f

How to find files by text in the file (using find + grep option)?

find . -type f -name "*.sh" -exec grep -l string {} \;    # find string in all *.sh files

find . -type f -name "*.sh" -exec grep -il string {} \; 


References:
https://alvinalexander.com/unix/edu/examples/find.shtml