How can I find all files containing specific text (string) on Linux?

Do the following: grep -rnw ‘/path/to/somewhere/’ -e ‘pattern’ -r or -R is recursive, -n is line number, and -w stands for match the whole word. -l (lower-case L) can be added to just give the file name of matching files. -e is the pattern used during the search Along with these, –exclude, –include, –exclude-dir flags … Read more

Inconsistent strcmp() return value when passing strings as pointers or as literals

TL:DR: Use gcc -fno-builtin-strcmp so strcmp() isn’t treated as equivalent to __builtin_strcmp(). With optimization disabled, GCC will only be able to do constant-propagation within a single statement, not across statements. The actual library version subtracts the differing character; the compile-time eval probably normalizes the result to 1 / 0 / -1, which isn’t required or … Read more

How can I get the source code for the linux utility tail?

The tail utility is part of the coreutils on linux. Source tarball: ftp://ftp.gnu.org/gnu/coreutils/coreutils-7.4.tar.gz Source file: https://git.savannah.gnu.org/cgit/coreutils.git/tree/src/tail.c (original http link) I’ve always found FreeBSD to have far clearer source code than the gnu utilities. So here’s tail.c in the FreeBSD project: http://svnweb.freebsd.org/csrg/usr.bin/tail/tail.c?view=markup

How to get hard disk serial number using Python

Linux As you suggested, fcntl is the way to do this on Linux. The C code you want to translate looks like this: static struct hd_driveid hd; int fd; if ((fd = open(“/dev/hda”, O_RDONLY | O_NONBLOCK)) < 0) { printf(“ERROR opening /dev/hda\n”); exit(1); } if (!ioctl(fd, HDIO_GET_IDENTITY, &hd)) { printf(“%.20s\n”, hd.serial_no); } else if (errno … Read more

how to bind raw socket to specific interface

const char *opt; opt = “eth0”; const len = strnlen(opt, IFNAMSIZ); if (len == IFNAMSIZ) { fprintf(stderr, “Too long iface name”); return 1; } setsockopt(sd, SOL_SOCKET, SO_BINDTODEVICE, opt, len); First line: set up your variable Second line: tell the program which interface to bind to Lines 3-5: get length of interface name and check if … Read more

How do you write a C program to execute another program?

#include <stdio.h> #include <stdlib.h> #include <unistd.h> /* for fork */ #include <sys/types.h> /* for pid_t */ #include <sys/wait.h> /* for wait */ int main() { /*Spawn a child to run the program.*/ pid_t pid=fork(); if (pid==0) { /* child process */ static char *argv[]={“echo”,”Foo is my name.”,NULL}; execv(“/bin/echo”,argv); exit(127); /* only if execv fails */ … Read more

Signing Windows application on Linux-based distros

You can try osslsigncode To sign an EXE or MSI file you can now do: osslsigncode sign -certs <cert-file> -key <der-key-file> \ -n “Your Application” -i http://www.yourwebsite.com/ \ -in yourapp.exe -out yourapp-signed.exe or if you are using a PEM or PVK key file with a password together with a PEM certificate: osslsigncode sign -certs <cert-file> … Read more

tech