Pages

Wednesday, June 27, 2012

Commands on Commands

Share it Please

There are few commands in Linux which can be executed on other commands

To see how the command is executing and what actually is command is doing

 strace ls

An excerpt of the output,

execve("/bin/ls", ["ls"], [/* 36 vars */]) = 0
brk(0)                                  = 0x8e51000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY)      = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=61502, ...}) = 0
mmap2(NULL, 61502, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7fb2000
close(3)                                = 0
open("/lib/librt.so.1", O_RDONLY)       = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\200\210\213\0004\0\0\0"..., 512) = 512
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7fb1000
fstat64(3, {st_mode=S_IFREG|0755, st_size=48156, ...}) = 0
mmap2(0x8b7000, 33324, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x8b7000
mmap2(0x8be000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x7) = 0x8be000
close(3)                                = 0
open("/lib/libacl.so.1", O_RDONLY)      = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0@2\212\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0755, st_size=25624, ...}) = 0

Strace is  to trace system calls and signals

Monitor activity: We can monitor activity using the watch command ,

watch –l 3 logName.log

watch command is used  execute a program periodically, showing output fullscreen. We can pass the time to execute the command using “-l”

Time : we can use time command to find how much time the command has taken to execute
Time ls

Whereis: we can use this to find the location of the command ,
Whereis ls

Whatis: we can use this command to get information about a command
Whatis ls

Happy learning :-)