Solved

How to trace the Linux command rm

Posted on 2011-09-22
6
337 Views
Last Modified: 2012-05-12
Would like to trace the command "rm" or "cp" as deep as possible. For example,
rm /usb/file.txt

Remove a file file.txt from USB stick.

What kind of operations are involved in this removal? As a user we know when we issue "rm", the file will be removed. OS kernel takes care of that.
Can any gurus shed some light on how the kernel does it, any code for it, or any links talking about it?
0
Comment
Question by:jl66
  • 3
  • 2
6 Comments
 
LVL 21

Assisted Solution

by:Papertrip
Papertrip earned 240 total points
ID: 36583437
strace rm /usb/file.txt

Open in new window

0
 
LVL 38

Accepted Solution

by:
Gerwin Jansen, EE MVE earned 260 total points
ID: 36583729
You can add -v to strace for verbose output or use ltrace -S to trace system and library calls::

strace -v rm /usb/file.txt

Open in new window

or
ltrace -S rm /usb/file.txt

Open in new window

0
 

Author Comment

by:jl66
ID: 36583977
Thanks for both of you. I will test them and get back to you.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jl66
ID: 36585078
I ran the commands and got the following outputs:

...
SYS_brk(NULL)                                                      = 0x9128000
SYS_access(0x529ec6, 4, 0x52ffc4, 0x530660, 0x529ec6)              = -2
SYS_open("/etc/ld.so.cache", 0, 00)                                = 3
SYS_fstat64(3, 0xbfc53d84, 0x52ffc4, 0x5305e8, 3)                  = 0
SYS_mmap2(0, 90150, 1, 2, 3)                                       = 0xb7856000
SYS_close(3)                                                       = 0
SYS_open("/lib/libc.so.6", 0, 00)                                  = 3
SYS_read(3, "\177ELF\001\001\001", 512)                            = 512
SYS_fstat64(3, 0xbfc53dc8, 0x52ffc4, 0xb7869210, 0x8057cd4)        = 0
SYS_mmap2(0, 4096, 3, 34, -1)                                      = 0xb7855000
SYS_mmap2(0x533000, 0x16f928, 5, 2050, 3)                          = 0x533000
SYS_mmap2(0x69d000, 12288, 3, 2066, 3)                             = 0x69d000
SYS_mmap2(0x6a0000, 10536, 3, 50, -1)                              = 0x6a0000
SYS_close(3)                                                       = 0
SYS_mmap2(0, 4096, 3, 34, -1)      
....

Could you please tell me those functions belong to which *.cpp or *.h? Is thtere any way to show the info too?
 
0
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 36588645
Well, I guess you'd have to start digging in the Linux source code. I'm no expert at that, sorry.
0
 

Author Closing Comment

by:jl66
ID: 36713558
Thanks a lot.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question