Questions tagged [bash]

Bash is the Bourne Again SHell, the successor to the classic Unix sh (shell).

bash is the Bourne Again SHell, the successor to the classic Unix Bourne shell (sh). It's the default shell on many Linux distributions, including RedHat, CentOS, Debian, and Ubuntu.

The premier online guide is the BashGuide.

3527 questions
23
votes
2 answers

backslash at the beginning of a command

In Installing RVM manual I see a lot of lines starting with '\': Install RVM with ruby: $ \curl -L https://get.rvm.io | bash -s stable --ruby I'd think it is just mistype but they repeat it many times. So what is the reason?
Putnik
  • 2,217
  • 4
  • 27
  • 43
23
votes
9 answers

Make ls print it all on one line (like in terminal)

ls prints differently depending on whether the output is to a terminal or to something else. e.g.: $ ls . file1 file2 $ ls . | head file1 file2 Is there some way to make ls print out on one line as if it's to a terminal when it's not. There's a -C…
Amandasaurus
  • 31,471
  • 65
  • 192
  • 253
22
votes
6 answers

kill a screen (but not all screens)

I have multiple screens running on an Ubuntu server that are initiated as: screen -dmS screen1 cmd screen -dmS screen2 cmd etc... And I need to kill one screen, but not all of them. What is the correct command to kill a single particular screen…
BassKozz
  • 645
  • 2
  • 8
  • 15
22
votes
3 answers

Completely reset PostgreSQL to default?

Question Is there a way to completely reset a PostgreSQL installation on Linux, so it is in the same state as when I installed it? Idea I have considered rm -rf /var/lib/pgsql/* rm -rf /var/lib/pgsql/backups/* rm -rf /var/lib/pgsql/data/* but…
Jasmine Lognnes
  • 2,520
  • 8
  • 33
  • 51
22
votes
3 answers

iftop - how to generate text file with its output?

iftop is great tool to view almost live bandwidth usage distinguished by source-ip source-port destination-ip destination port. I'm using it to see which client's ip is using most bandwidth. Now I would like to store output somewhere. iftop uses…
mickula
  • 342
  • 1
  • 2
  • 10
22
votes
1 answer

Ctrl-C in bash scripts

How do I implement ctrl+c handling in bash scripts so that the script is interrupted, as well as the currently running command launched by the script? (Imagine there's a script that executes some long-running command. The user hits ctrl+c and…
kolypto
  • 11,058
  • 12
  • 54
  • 66
21
votes
4 answers

Count number of bytes piped from one process to another

I'm running a shell script that pipes data from one process to another process_a | process_b Does anyone know a way to find out how many bytes were passed between the two programs? The only solution I can think of at the moment would be to write a…
Simon Hodgson
  • 691
  • 3
  • 8
  • 15
21
votes
7 answers

Setting the Timezone with an automated script

I'm writing scripts to automate setting up new slicehost installations. In a perfect world, after I started the script, it would just run, with no attention from me. I have succeeded, with one exception. How do I set the timezone, in a permanent…
Tom
  • 213
  • 1
  • 2
  • 6
21
votes
3 answers

Why are environment variables different with `bash -c`

How come the following, i.e. echoing $PATH directly from bash -c: docker exec -i -t my_container bash -c "echo $PATH" returns a different value for $PATH than what follows, i.e. starting an interactive bash session and echoing the $PATH? docker…
Alessandro Vernet
  • 557
  • 2
  • 4
  • 9
21
votes
2 answers

Docker exec/run shell command nesting

A short introduction to the use case: I am using a docker container to run my go tests using go test ./.... This can be achieved easily using docker exec /bin/sh -c "go test ./...". Unfortunately go test ./... runs across all…
Wesley van Opdorp
  • 291
  • 1
  • 3
  • 10
21
votes
10 answers

Extract repository name from GitHub url in bash

Given ANY GitHub repository url string like: git://github.com/some-user/my-repo.git or git@github.com:some-user/my-repo.git or https://github.com/some-user/my-repo.git What is the best way in bash to extract the repository name my-repo from any…
Justin
  • 5,328
  • 19
  • 64
  • 84
21
votes
4 answers

Ordinary users are able to read /etc/passwd, is this a security hole?

ls -l /etc/passwd gives $ ls -l /etc/passwd -rw-r--r-- 1 root root 1862 2011-06-15 21:59 /etc/passwd So an ordinary user can read the file. Is this a security hole?
Ankur Agarwal
  • 457
  • 1
  • 6
  • 15
21
votes
1 answer

Is there a device file that just blocks?

... something similar to /dev/null, but that just blocks all bytes that are written to it? What I need is a trick to hold an arbitrary executable in memory by blocking its output. Pipes don't seem to be usable, because the output gets written to a…
Armin
  • 312
  • 1
  • 8
20
votes
2 answers

Redirect to stdin instead of argument when using xargs

for exmaple, using the command cat foo.txt | xargs -I{} -n 1 -P 1 sh -c "echo {} | echo" The foo.txt contains two lines foo bar The above command print nothing.
Ryan
  • 5,831
  • 24
  • 72
  • 91
20
votes
1 answer

Shell command slow when using pipe, fast with intermediate file

Does anyone understand this huge difference in processing time, when using an intermediate file, or when using a pipe? I'm converting tiff to pdf using standard tools on a fresh debian squeeze server. A standard way of doing this is to convert to ps…
plang
  • 325
  • 3
  • 10