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
86
votes
3 answers

How to apply a filter to real time output of `tail -f `?

tail -f path The above will output modifications to the file instantly, but I want to apply a filter to the output, only show when there is a keyword xxx in it. How to approach this?
wamp
  • 1,197
  • 3
  • 12
  • 17
85
votes
6 answers

What does passing the -xe parameters to /bin/bash do

Exactly what the title says. I'm not having much luck finding the proper documentation to see what -xe does in the following use case: #!/bin/bash -xe what do those parameters do and where it is documented?
imaginative
  • 1,971
  • 10
  • 32
  • 48
84
votes
8 answers

zcat/gzcat works in linux, not on osx. general linux/osx compatibility

First the specific problem: In linux, I use zcat to list a .zip file. In osx, zcat seems to automatically append .Z to the file name. Various people suggest replacing zcat with gzcat; however, gzcat complains that the file is not in gzip format!…
user23398
  • 1,191
  • 3
  • 9
  • 14
83
votes
12 answers

How can I run arbitrarily complex command using sudo over ssh?

I have a system that I can only log in to under my username (myuser), but I need to run commands as other user (scriptuser). So far, I have come up with the following to run the commands I need: ssh -tq myuser@hostname "sudo -u scriptuser bash -c…
VoY
  • 1,275
  • 2
  • 11
  • 9
83
votes
11 answers

How to remove invalid characters from filenames?

I have files with invalid characters like these 009_-_�%86ndringshåndtering.html It is a Æ where something have gone wrong in the filename. Is there a way to just remove all invalid characters? or could tr be used somehow? echo…
Sandra
  • 10,303
  • 38
  • 112
  • 165
82
votes
7 answers

Log all commands run by admins on production servers

It is company policy for admins to login to the servers via a personal username, and then run sudo -i to become root. Upon running sudo -i, sudo will create an environmental variable called SUDO_USER, which contains the original user's username. Is…
Soviero
  • 4,366
  • 8
  • 36
  • 60
80
votes
6 answers

How to test if my server is vulnerable to the ShellShock bug?

How can I ensure my Bash installation is not vulnerable to the ShellShock bug anymore after the updates?
gtirloni
  • 5,746
  • 3
  • 25
  • 52
78
votes
3 answers

In Bash, are wildcard expansions guaranteed to be in order?

Is the expansion of a wildcard in Bash guaranteed to be in alphabetical order? I am forced to split a large file into 10 Mb pieces so that they can be be accepted by my Mercurial repository. So I was thinking I could use: split -b 10485760 Big.file…
Sled
  • 927
  • 1
  • 7
  • 11
71
votes
4 answers

Is there a difference between how two ampersands and a semi-colon operate in bash?

If I wanted to run two separate commands on one line, I could do this: cd /home; ls -al or this: cd /home && ls -al And I get the same results. However, what is going on in the background with these two methods? What is the functional difference…
Sean P
  • 727
  • 1
  • 5
  • 3
71
votes
7 answers

How to read in N random characters from /dev/urandom?

read /dev/urandom 3 The above is not working..How can I read random bytes from /dev/urandom in bash?
linux
  • 1,223
  • 4
  • 13
  • 15
70
votes
5 answers

How can I check in bash if a shell is running in interactive mode?

How can I tell (in ~/.bashrc) if I'm running in interactive mode, or, say, executing a command over ssh. I want to avoid printing of ANSI escape sequences in .bashrc if it's the latter.
Alex B
  • 1,714
  • 2
  • 18
  • 30
70
votes
11 answers

Linux: How to use a file as input and output at the same time?

I've just run the following in bash: uniq .bash_history > .bash_history and my history file ended up completely empty. I guess I need a way to read the whole file before writing to it. How is that done? PS: I obviously thought of using a temporary…
MilliaLover
  • 967
  • 1
  • 8
  • 8
69
votes
6 answers

Newline-separated xargs

Is it possible to make xargs use only newline as separator? (in bash on Linux and OS X if that matters) I know -0 can be used, but it's PITA as not every command supports NUL-delimited output.
Kornel
  • 1,105
  • 1
  • 11
  • 16
68
votes
2 answers

GNU less: How can I search while ignoring case sensitivity without using less -I option?

From GNU less manpage -i or --ignore-case Causes searches to ignore case; that is, uppercase and lowercase are considered identical. This option is ignored if any uppercase letters appear in the search pattern; in other words, if a pattern contains…
Tom Feiner
  • 17,578
  • 8
  • 30
  • 24
67
votes
10 answers

Unique Features of bash compared to zsh

I have been a zsh user for quite some time (before that tcsh and before that csh). I am quite happy with it, but was wondering if there are any compelling features of bash that do not exist in zsh. And conversely, are there zsh features which do not…
Tim
  • 1,879
  • 3
  • 18
  • 16