Most Popular

1500 questions
88
votes
10 answers

Autocomplete server names for SSH and SCP

I have a few servers configured in ~/.ssh/config, such as alpha and beta. How might I configure Bash such that the commands $ ssh alTab and $ scp file.tgz alTab autocomplete the names of the configured servers? I don't want to add the servers to…
dotancohen
  • 15,494
  • 26
  • 80
  • 116
88
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,334
  • 5
  • 21
  • 25
88
votes
1 answer

Preserve the permissions with rsync

Let's say I have a file a.txt in LINUX with permission of 0664. When I use rsync to copy the file to my Mac with rsync -r -t -v LINUX MAC, the file's permission becomes 0644. How can I keep the permission for a file when using rsync? The -g option…
prosseek
  • 8,418
  • 16
  • 47
  • 43
88
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
  • 981
  • 1
  • 7
  • 6
88
votes
4 answers

What does adduser do that useradd doesn't?

In addition to the more widespread useradd, Debian based systems also contain an additional adduser command which provides a higher level interface for adding users and some related tasks. There are various questions/answers on other SE sites which…
Graeme
  • 33,607
  • 8
  • 85
  • 110
88
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,189
  • 24
  • 102
  • 168
88
votes
5 answers

How to persistently control maximum system resource consumption on Mac?

Before Mavericks, I could use /etc/launchd.conf file to change maximum system resource consumption, for example: limit maxfiles 16384 unlimited limit maxproc 16384 unlimited It no longer works in Mavericks. What is the correct way to do it in the…
Howard
  • 5,149
  • 5
  • 30
  • 34
88
votes
4 answers

Can I somehow add a "&& prog2" to an already running prog1?

Most shells provide functions like && and ; to chain the execution of commands in certain ways. But what if a command is already running, can I still somehow add another command to be executed depending on the result of the first one? Say I ran $…
us2012
  • 943
  • 6
  • 6
88
votes
13 answers

How can I best copy large numbers of small files over scp?

I have a directory that's got several gigabytes and several thousand small files. I want to copy it over the network with scp more than once. CPU time on the source and destination machines is cheap, but the network overhead added by copying each…
nmichaels
  • 980
  • 1
  • 7
  • 8
87
votes
7 answers

How can I read line by line from a variable in bash?

I have a variable which contains multiline output of a command. What's the most effecient way to read the output line by line from the variable? For example: jobs="$(jobs)" if [ "$jobs" ]; then # read lines from $jobs fi
Eugene Yarmash
  • 14,675
  • 14
  • 50
  • 57
87
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,127
  • 4
  • 19
  • 31
87
votes
9 answers

keyserver timed out when trying to add a GPG public key

I am trying to add a public key for installing a program with CPG. But I am pretty new to this but every command I found gave me the same error: gpg --keyserver keyserver.ubuntu.com --recv-keys 94558F59 gpg: requesting key 94558F59 from hkp server…
Sander Van der Zeeuw
  • 1,501
  • 2
  • 13
  • 15
87
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,284
  • 40
  • 125
  • 208
87
votes
6 answers

How can I tell what version of apache I'm running?

I know about the phpinfo() way but is there any other way? I'm using CentOS and I can't find the httpd executable to run httpd -v.
tooshel
  • 1,441
  • 6
  • 16
  • 17
87
votes
6 answers

How to edit command line in full screen editor in ZSH?

In bash, using vi mode, if I hit Esc,v, my current command line is opened in the editor specified by $EDITOR and I am able to edit it in full screen before 'saving' the command to be returned to the shell and executed. How can I achieve similar…
Murali Suriar
  • 2,734
  • 4
  • 21
  • 24