Linux
How to extract files from RPM
Jul 26th
All the files present in a RPM file can be extracted using rpm2cpio and cpio utilities. The rpm2cpio command is used to convert RPM to cpio compatible archive and cpio command can be used to extract files from the archive.
The following example shows how extract files from ElectricFence RPM.
[liz@techpulp ~]# rpm2cpio ElectricFence-2.2.2-23.rpm | cpio -idv
Identify processes that have open sockets
Jul 26th
The lsof can be used to find the list of processes that have active sockets open.
Let us see the list of current TCP connections using netstat command.
[liz@techpulp ~]# netstat -nt Active Internet connections (w/o servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 192.168.20.24:40816 74.125.19.83:80 ESTABLISHED tcp 0 0 192.168.20.24:43059 74.125.19.83:80 ESTABLISHED [liz@techpulp ~]#
Now let us find which process has these TCP sockets open using lsof command.
[liz@techpulp ~]# /usr/sbin/lsof -i
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
firefox-b 3288 liz 13u IPv4 157814 TCP
liz.techpulp.com:43058->cf-in-f83.google.com:http (ESTABLISHED)
firefox-b 3288 liz 40u IPv4 158205 TCP
liz.techpulp.com:43059->cf-in-f83.google.com:http (ESTABLISHED)
[liz@techpulp ~]#
So Firefox More >
Linux file compression tools/utilities
Jul 26th
Linux has various types of compression and decompression tools like tar, gzip, bzip2, zip and compress. This article describes practical usage of these utilities.
tar and untar
tar command operates on one or more files or directories and creates an archive. An archive created by tar command is called a tarball. Generally such archives will have .tar as file extension. tar is more of a archiving utility than a compression utility. Typically it is used along with file compression utilities like gzip and bzip2. See various ways of creating a tarball using -cvf option in the following examples.
[liz@techpulp ~]# tar -cvf mydir.tar mydir/ [liz@techpulp ~]# tar -cvf myfiles.tar file1.txt More >
Stack of a Running Process in Unix/Linux
Jul 26th
The command pstack can be used to view the stack trace of a running process.
Let us select a running process.
[neo@techpulp ~]# ps -e | grep konqueror 22937 pts/5 00:00:17 konqueror
Run pstack command with PID of the process.
[neo@techpulp ~]# pstack 22937 22937: konqueror (No symbols found) 0x001fb402: ???? (89c6ed8, 2, bfa39b08, 3812df0, 89c6ed8, 3c21362) 0x0325074b: ???? (89c6ed8, 8a00908) 0x03250656: ???? (89c6ed8, 3c372ec) 0x03237a59: ???? (bfa39c20, bfa39d48, bfa39de8, bfa39d1c, 0, bfa39fb4) + 4c0 0x03bb1d0d: ???? (1, bfa3a094, bfa3a09c, 0, bfa3a094, 1) + 40 0x00248de6: ???? (80485ec, 1, bfa3a094, 8048600, 8048650, 21ff2d) + 405c5f78 [neo@techpulp ~]#
There is an alternate way to use gdb and attach More >
ELF Binary Optimization for size
Jul 26th
The following steps help in reducing the size of a Linux application ELF binary. These operations can be used for application binary as well as shared library.
Use compiler optimization flags
-Os (optimize for size)
-O2
While linking, try to use following options. But do not use ‘-s’ option for kernel modules.
# ld -r -s --discard-local --discard-all testApp.o -o testApp # ld -r -s --discard-local --discard-all testLib1.o testLib2.o -o testLib.so # ld -r --discard-local --discard-all testMod1.o testMod2.o -o testMod
Strip the binary including unnecessary sections
# strip --remove-section=.note --remove-section=.comment testApp # strip --remove-section=.note --remove-section=.comment testLib.so
Find how long a command takes to complete
Jul 25th
Some times it is required to know how long a command is taking to execute, especially in case of huge scripts. The command “time” can be used to determine the time taken by a command or a script. The following example shows how it can be used.
[liz@techpulp ~]# time sleep 3 real 0m3.016s user 0m0.000s sys 0m0.008s [liz@techpulp ~]#
In the above example we attempted to determine time taken by the command “sleep 3” using time command. After the command finishes, time prints the information on standard error. This information contains “real” which is actual time taken by the command from the invocation More >


Recent Comments