Most Popular
1500 questions
654
votes
10 answers
Why is it better to use "#!/usr/bin/env NAME" instead of "#!/path/to/NAME" as my shebang?
I notice that some scripts which I have acquired from others have the shebang #!/path/to/NAME while others (using the same tool, NAME) have the shebang #!/usr/bin/env NAME.
Both seem to work properly. In tutorials (on Python, for example), there…
TheGeeko61
- 6,911
- 3
- 17
- 18
646
votes
4 answers
Using "${a:-b}" for variable assignment in scripts
I have been looking at a few scripts other people wrote (specifically Red Hat), and a lot of their variables are assigned using the following notation
VARIABLE1="${VARIABLE1:-some_val}"
or some expand other variables
VARIABLE2="${VARIABLE2:-`echo…
Justin Garrison
- 7,359
- 4
- 20
- 21
635
votes
24 answers
Repeat a Unix command every x seconds forever
There's a built-in Unix command repeat whose first argument is the number of times to repeat a command, where the command (with any arguments) is specified by the remaining arguments to repeat.
For example,
% repeat 100 echo "I will not automate…
dreeves
- 6,499
- 3
- 15
- 7
616
votes
9 answers
What is the difference between /opt and /usr/local?
According to the Filesystem Hierarchy Standard, /opt is for "the installation of add-on application software packages". /usr/local is "for use by the system administrator when installing software locally". These use cases seem pretty similar. …
Patches
- 6,502
- 3
- 15
- 11
612
votes
4 answers
Does curl have a --no-check-certificate option like wget?
I am trying to make a curl request to one of our local development servers running a dev site with a self-signed SSL cert. I am using curl from the command line.
I saw some blog posts mentioning that you can add to the list of certificates or…
cwd
- 44,479
- 71
- 146
- 167
611
votes
15 answers
What if 'kill -9' does not work?
I have a process I can't kill with kill -9 . What's the problem in such a case, especially since I am the owner of that process. I thought nothing could evade that kill option.
tshepang
- 64,472
- 86
- 223
- 290
607
votes
10 answers
How to append multiple lines to a file
I am writing a bash script to look for a file if it doesn't exist then create it and append this to it:
Host localhost
ForwardAgent yes
So "line then new line 'tab' then text" I think its a sensitive format.
I know you can do this:
cat…
TheLegend
- 6,515
- 4
- 15
- 14
584
votes
27 answers
How can I resolve a hostname to an IP address in a Bash script?
What's the most concise way to resolve a hostname to an IP address in a Bash script? I'm using Arch Linux.
Eugene Yarmash
- 14,675
- 14
- 50
- 57
574
votes
7 answers
Scroll inside Screen, or Pause Output
I use screen for my command-line tasks while managing the servers where I work. I usually run small commands (mostly file-system tasks) but sometimes I run more extensive tasks (like DBA).
The output of those tasks is important to me. Since I use…
AeroCross
- 6,273
- 4
- 17
- 7
570
votes
10 answers
Can less retain colored output?
Can I get less not to monochrome its output?
E.g., the output from git diff is colored, but git diff | less is not.
ripper234
- 31,063
- 43
- 82
- 90
570
votes
9 answers
How to display `top` results sorted by memory usage in real time?
How can I display the top results in my terminal in real time so that the list is sorted by memory usage?
Theodor Coogan
- 5,701
- 3
- 12
- 3
563
votes
3 answers
What is a bind mount?
What is a “bind mount”? How do I make one? What is it good for?
I've been told to use a bind mount for something, but I don't understand what it is or how to use it.
Gilles 'SO- stop being evil'
- 807,993
- 194
- 1,674
- 2,175
561
votes
25 answers
How to generate a random string?
I would like to generate a random string (e.g. passwords, user names, etc.). It should be possible to specify the needed length (e.g. 13 chars).
What tools can I use?
(For security and privacy reasons, it is preferable that strings are generated…
landroni
- 10,288
- 12
- 30
- 48
557
votes
8 answers
Can grep output only specified groupings that match?
Say I have a file:
# file: 'test.txt'
foobar bash 1
bash
foobar happy
foobar
I only want to know what words appear after "foobar", so I can use this regex:
"foobar \(\w\+\)"
The parenthesis indicate that I have a special interest in the word right…
Cory Klein
- 18,391
- 26
- 81
- 93
554
votes
13 answers
How to clear journalctl
I couldn't find in google any safe way to clear systemd journal. Do anyone know any safe and reliable way to do so?
Let's say I was experimenting with something and my logs got cluttered with various error messages. Moreover I'm displaying my…
Łukasz Zaroda
- 6,083
- 4
- 17
- 24