Most Popular
1500 questions
89
votes
8 answers
Logging SSH access attempts
I've configured an ubuntu server with openssh in order to connect to it and execute commands from a remote system like a phone or a laptop. The problem is... I'm probably not the only one.
Is there a way to know all the login attempts that have…

UserK
- 2,424
89
votes
13 answers
How to parse JSON with shell scripting in Linux?
I have a JSON output from which I need to extract a few parameters in Linux.
This is the JSON output:
{
"OwnerId": "121456789127",
"ReservationId": "r-48465168",
"Groups": [],
"Instances": [
{
…

user3086014
- 991
89
votes
3 answers
What happens when I run the command cat /proc/cpuinfo?
What happens when I write cat /proc/cpuinfo. Is that a named pipe (or something else) to the OS which reads the CPU info on the fly and generate that text each time I call it?

slm
- 369,824
89
votes
9 answers
How to measure time of program execution and store that inside a variable
In order to find out how long certain operations within a Bash (v4+) script take, I would like to parse the output from the time command "separately" and (ultimately) capture it within a Bash variable (let VARNAME=...).
Now, I am using time -f '%e'…

0xC0000022L
- 16,593
89
votes
4 answers
What is the difference between a builtin command and one that is not?
Is there any intrinsic difference between a builtin command and another command which can nominally do the same thing?
eg. Do builtins get "special" treatement? ... is there less overhead running them? .. or are they just simply 'built in'; like…

Peter.O
- 32,916
88
votes
4 answers
Use & (ampersand) in single line bash loop
I have been using this command successfully, which changes a variable in a config file and then executes a Python script within a loop:
for((i=114;i<=255;i+=1)); do echo $i > numbers.txt; python DoMyScript.py; done
As each DoMyScript.py instance…

ljs.dev
- 2,137
- 4
- 20
- 31
88
votes
3 answers
How do the internals of sudo work?
How does sudo work internally? How is it possible that it can become root without having the root password, unlike su? What syscalls, etc. are involved in the process? Is it not a gaping security hole in Linux (e.g. why couldn't I compile a…

strugee
- 14,951
88
votes
5 answers
How to make Vim display colors as indicated by color codes?
In short, I'm in an effort to replace less with vim (vimpager). I have settings for scripts to spit out colors (and bold and everything nice) whenever they can. less understands the color codes and displays them nicely. How can I make vim parse the…

phunehehe
- 20,240
88
votes
2 answers
Replacing string based on line number
I have a situation where i want to replace a particular string in many files
Replace a string AAA with another string BBB but there are lot of strings starting with AAA or ending in AAA ,and i want to replace only one on line 34 and keep others…

krypto
- 981
88
votes
6 answers
How to loop over the lines of a file?
Say I have this file:
hello
world
hello world
This program
#!/bin/bash
for i in $(cat $1); do
echo "tester: $i"
done
outputs
tester: hello
tester: world
tester: hello
tester: world
I'd like to have the for iterate over each line individually…

Tobias Kienzler
- 9,374
88
votes
8 answers
cron ignores variables defined in ".bashrc" and ".bash_profile"
I have defined "SHELL" variable in /etc/crontab file:
[martin@martin ~]$ grep SHELL /etc/crontab
SHELL=/usr/local/bin/bash
[martin@martin ~]$ file /usr/local/bin/bash
/usr/local/bin/bash: ELF 32-bit LSB executable, Intel 80386, version 1 (FreeBSD),…

Martin
- 7,516
88
votes
6 answers
Delete last line from the file
I use sed to quickly delete lines with specific position as
sed '1d'
sed '5d'
But, what if I want to delete the last line of the file and I don't know the count of lines (I know I can get that using wc and several other tricks).
Currently, using…

mtk
- 27,530
- 35
- 94
- 130
88
votes
4 answers
What is the difference between procfs and sysfs?
What is the difference between procfs and sysfs? Why are they made as file systems? As I understand it, proc is just something to store the immediate info regarding the processes running in the system.

Navaneeth Sen
- 9,489
88
votes
9 answers
What are the alternatives for checking open ports, besides telnet?
We can use the following in order to test telnet VIA port; in the following example we test port 6667:
[root@kafka03 ~]# telnet kafka02 6667
Trying 103.64.35.86...
Connected to kafka02.
Escape character is '^]'.
^CConnection closed by foreign…

yael
- 13,106
88
votes
1 answer
Variable substitution with an exclamation mark in bash
I have the following lines in my .cfg bash script file
DDF_SOURCE="siebel_DATA_DATE_FORMAT"
DATA_DATE_FORMAT=${!DDF_SOURCE}
how is ${!DDF_SOURCE} evaluated? It would be !siebel_DATA_DATE_FORMAT, which doesn't make sense to me.

van
- 1,129