Most Popular
1500 questions
692
votes
9 answers
How do I zip/unzip on the unix command line?
How can I create and extract zip archives from the command line?
joachim
- 7,967
689
votes
12 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,271
674
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
- 11,834
663
votes
12 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 temp.txt >>…
TheLegend
- 7,075
660
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,942
659
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,519
658
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,729
657
votes
17 answers
What if 'kill -9' does not work?
I have a process I can't kill with kill -9 <pid> . 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
- 68,112
638
votes
30 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,905
626
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
- 47,367
623
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
- 6,231
620
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'
- 872,165
612
votes
4 answers
In a bash script, using the conditional "or" in an "if" statement
This question is a sequel of sorts to my earlier question . The users on this site kindly helped me determine how to write a bash for loop that iterates over string values. For example, suppose that a loop control variable fname iterates over the…
Andrew
- 17,895
- 36
- 81
- 82
601
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,563
600
votes
10 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
- 19,581