Skip to content

Tag: shell

bash: grep exact matches based on the first column

I have a .txt file like below: For example, I want to generate a subset with the IDs 4324321_A3 and 9342432 (based on the first column!). I tried the following command to find the exact matches: But when I use this line, I end up with a dataset like this: The problem is that the line that matches a part

How does cmd > /dev/null 2>&1 work?

I’m reading up on redirecting data to /dev/null and so I tried a simple test: If I try this: However, if I do this: That last solution is the desired solution, but what is happening with this 2>&1? My research so far suggest that 2 represents stderr and 1 represents stdout. So if I read it that w…

How to base64 encode image in linux bash / shell

I’m trying to base64 encode an image in a shell script and put it into variable: I’ve also tried something like this: but still with no success. I want to do something like this: I found this http://www.zzzxo.com/q/answers-bash-base64-encode-script-not-encoding-right-12290484.html but still have h…

how to extract a substring in bash

I have the following string in bash with length > 4 and I want to extract into str2 the 5 first charachter of str. So How to do it with bash? Answer Do use the expression So in this case: See other usages: Taken from: – wooledge.org – How can I use parameter expansion? How can I get substrings?…

hex code implementation for spawning a shell

I am trying to implement the codes given in smashing the stack for fun and profit by Aleph to learn the basics of buffer overflow attacks. Machine architecture: Ubuntu 12.10 64 bit programs compiled using -m32 flag in gcc So far, I have managed to spawn a shell using the assembly instructions. The next step i…

Grouping common elements using awk

The following table illustrates a brief snapshot of the data that I wish to manipulate. I am looking for an awk script that will group similar elements into one group. For eg. if you look at the table below: Numbers (1,2,3,4,6) should all belong to one group. So row1 row2 row4 row8 will be group “1&#822…

how to make SSH command execution to timeout

I have a program like this: In the above code, I am trying to SSH to the remote server, and tries to check if I can connect or not. I have few servers, which is password less is activated and few servers for which passwords are still not yet deactivated. So my concern, if there is a password, it will

How to capture all the commands typed in Unix/Linux by any user?

I would like to capture all the commands typed in Unix/Linux by any user. There are few alternatives like using script command or acct utility. But the problem with them is they dumb everything from the terminal to a file or just provide the summary of the commands. I am looking for a utility where it will pr…