Most Popular
1500 questions
666
votes
11 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
- 7,041
655
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,459
648
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,629
644
votes
11 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,885
629
votes
8 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,632
623
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
- 65,642
617
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
- 45,389
608
votes
26 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,906
607
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
- 15,095
603
votes
16 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,593
586
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,403
585
votes
10 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,851
583
votes
11 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,763
580
votes
9 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,911
576
votes
7 answers
How do I check package version using apt-get / aptitude?
Before I install a package, I'd like to know what version I would get.
How do I check the version before installing using apt-get or aptitude on Debian or Ubuntu?
user4069