Tuesday, 27 November 2012

Linux File systems programming tricks and tips

Possible paths from struct file*:
1- Get the struct dentry* object from struct file* ;
file->f_path.dentry

2- Get the struct inode* from struct file *:
file->f_inode




Possible paths from struct dentry:
1- Get the file name of the current struct dentry * object:
dentry->d_name.name

2- Get the length of file from the current struct dentry * object:
dentry->d_name.len

3- Get the struct inode* from struct dentry *:
dentry->d_inode


Continues.... (coming up)

Thursday, 15 November 2012

Starting with Linux Environment

Some important Hot keys and commands to administer Linux Box:


- To change and go to system command based terminal.

use <ALT> with F1-4
Usually <ALT> with F7 for GUI environment

-How list files:

 $ls -l (List files in long format)
Documents
...
...

-How to know, current Directory structure?

$pwd
/home/pankaj

-How to make directory on current working directory?

$mkdir testdir
It will create directory on current directory.

-How to make directory on absolute path?

$mkdir -p /home/pankaj/testdir

-How search a file in current directory and subdirectories?

$find .-name file1

-How to use pipe with grep pattern matching:
   - search file name in ls output,whether that file exist in current directory.

      $ls -l | grep file1

-Listing process in full format

$ps -ef
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 Nov09 ?        00:00:03 init [5] 
root         2     0  0 Nov09 ?        00:00:00 [kthreadd]
root         3     2  0 Nov09 ?        00:00:01 [ksoftirqd/0]
root         6     2  0 Nov09 ?        00:00:00 [migration/0]
root         7     2  0 Nov09 ?        00:00:00 [watchdog/0]
root         8     2  0 Nov09 ?        00:00:00 [migration/1]
root        10     2  0 Nov09 ?        00:00:02 [ksoftirqd/1]
root        12     2  0 Nov09 ?        00:00:00 [watchdog/1]
root        13     2  0 Nov09 ?        00:00:00 [migration/2]
root        14     2  0 Nov09 ?        00:00:00 [kworker/2:0]
root        15     2  0 Nov09 ?        00:00:01 [ksoftirqd/2]
root        16     2  0 Nov09 ?        00:00:00 [watchdog/2]
...
...

-List process in single page:

$ps -ef | more

-Search for process existence:

$ps -ef | grep sshd
root      4578     1  0 Nov09 ?        00:00:00 /usr/sbin/sshd -o PidFile=/var/run/sshd.init.pid
root     27282  4578  0 11:56 ?        00:00:00 sshd: root@pts/1                                  
root     28443 28327  0 14:01 pts/2    00:00:00 grep sshd


-Remove grep process from the list:

$ps -ef | grep sshd | grep -v grep
root      4578     1  0 Nov09 ?        00:00:00 /usr/sbin/sshd -o PidFile=/var/run/sshd.init.pid
root     27282  4578  0 11:56 ?        00:00:00 sshd: root@pts/1                                  

-Status of all service, running in the system:

$service --status-all | more

-Checking ssh service status: (Says running)

$service --status-all | grep sshd
You do not have enough privilege to read the profile set.
Usage: /etc/init.d/ipmievd {start|stop|restart|force-reload}
..dead..dead
Checking for service sshd ..running

- Remote Desktop:

$rdesktop <ip-adr>