227,599 questions
346
votes
9
answers
370k
views
How to write multiple line string using Bash with variables?
How can I write multi-lines in a file called myconfig.conf using BASH?
#!/bin/bash
kernel="2.6.39";
distro="xyz";
echo <<< EOL
line 1, ${kernel}
line 2,
line 3, ${distro}
line 4
line ...
...
346
votes
8
answers
269k
views
Create zip file and ignore directory structure
I need to create a zip file using this command:
zip /dir/to/file/newZip /data/to/zip/data.txt
This works, but the created zip file creates a directory structure mimicking the directory to the raw ...
345
votes
7
answers
290k
views
How to diff and only show filenames of files that differ?
I'm looking to run a Linux command that will recursively compare two directories and output only the file names of what is different. This includes anything that is present in one directory and not ...
340
votes
12
answers
438k
views
Environment variable substitution in sed
If I run these commands from a script:
#my.sh
PWD=bla
sed 's/xxx/'$PWD'/'
...
$ ./my.sh
xxx
bla
it is fine.
But, if I run:
#my.sh
sed 's/xxx/'$PWD'/'
...
$ ./my.sh
$ sed: -e expression #1, char 8: ...
339
votes
4
answers
193k
views
When to wrap quotes around a shell variable?
Should or should I not wrap quotes around variables in a shell script?
For example, is the following correct:
xdg-open $URL
[ $? -eq 2 ]
or
xdg-open "$URL"
[ "$?" -eq "2"...
337
votes
8
answers
401k
views
Find and replace with sed in directory and sub directories
I run this command to find and replace all occurrences of 'apple' with 'orange' in all files in root of my site:
find ./ -exec sed -i 's/apple/orange/g' {} \;
But it doesn't go through sub ...
336
votes
7
answers
230k
views
What's the difference between nohup and ampersand
Both nohup myprocess.out & or myprocess.out & set myprocess.out to run in the background. After I shutdown the terminal, the process is still running.
What's the difference between them?
329
votes
10
answers
769k
views
How to list running screen sessions?
I have a bunch of servers, on which I run experiments using screen. The procedure is the following :
ssh to server XXX
launch screen
start experiments in a few tabs
detach screen
disconnect from the ...
323
votes
13
answers
337k
views
How do I write a bash script to restart a process if it dies?
I have a python script that'll be checking a queue and performing an action on each item:
# checkqueue.py
while True:
check_queue()
do_something()
How do I write a bash script that will check if ...
321
votes
12
answers
234k
views
How do I fix the Rust error "linker 'cc' not found" for Debian on Windows 10?
I'm running Debian on Windows 10 (Windows Subsystem for Linux) and installed Rust using the command:
curl https://sh.rustup.rs -sSf | sh
There were no errors in the install, but when I tried to ...
319
votes
17
answers
731k
views
How to get the process ID to kill a nohup process? [closed]
I'm running a nohup process on the server. When I try to kill it my putty console closes instead.
this is how I try to find the process ID:
ps -ef |grep nohup
this is the command to kill
kill -9 ...
317
votes
14
answers
578k
views
Is there a "goto" statement in bash?
Is there a "goto" statement in Bash?
I know it is considered bad practice, but I need specifically a "goto".
315
votes
9
answers
260k
views
How to exit if a command failed? [duplicate]
I am a noob in shell-scripting. I want to print a message and exit my script if a command fails. I've tried:
my_command && (echo 'my_command failed; exit)
but it does not work. It keeps ...
313
votes
12
answers
1.0m
views
How can I set a proxy for Wget? [closed]
I want to download something with Wget using a proxy:
HTTP Proxy: 127.0.0.1
Port: 8080
The proxy does not need a username and password.
How can I do this?
313
votes
25
answers
215k
views
How do you normalize a file path in Bash?
I want to transform /foo/bar/.. to /foo
Is there a bash command which does this?
Edit: in my practical case, the directory does exist.
313
votes
25
answers
801k
views
How do I send a file as an email attachment using Linux command line?
I've created a script that runs every night on my Linux server that uses mysqldump to back up each of my MySQL databases to .sql files and packages them together as a compressed .tar file. The next ...
311
votes
25
answers
1.6m
views
How to set JAVA_HOME in Linux for all users
I am new to Linux system and there seem to be too many Java folders.
java -version gives me:
java version "1.7.0_55"
OpenJDK Runtime Environment (rhel-2.4.7.1.el6_5-x86_64 u55-b13)
OpenJDK 64-Bit ...
311
votes
14
answers
81k
views
How is the Linux kernel tested?
How do the Linux kernel developers test their code locally and after they have it committed? Do they use some kind of unit testing and build automation? Test plans?
308
votes
6
answers
236k
views
How do I check the operating system in Python?
I want to check the operating system (on the computer where the script runs).
I know I can use os.system('uname -o') in Linux, but it gives me a message in the console, and I want to write to a ...
308
votes
18
answers
552k
views
Maximum number of threads per process in Linux?
What is the maximum number of threads that can be created by a process under Linux?
How (if possible) can this value be modified?
306
votes
8
answers
300k
views
Virtual Memory Usage from Java under Linux, too much memory used
I have a problem with a Java application running under Linux.
When I launch the application, using the default maximum heap size (64 MB), I see using the tops application that 240 MB of virtual ...
304
votes
2
answers
161k
views
How to preserve line breaks when storing command output to a variable? [duplicate]
I’m using bash shell on Linux. I have this simple script …
#!/bin/bash
TEMP=`sed -n '/'"Starting deployment of"'/,/'"Failed to start context"'/p' "/usr/java/jboss/standalone/log/server.log" | tac | ...
302
votes
12
answers
247k
views
Define an alias in fish shell
I would like to define some aliases in fish. Apparently it should be possible to define them in
~/.config/fish/functions
but they don't get auto loaded when I restart the shell. Any ideas?
301
votes
24
answers
512k
views
Match two strings in one line with grep
I am trying to use grep to match lines that contain two different strings. I have tried the following but this matches lines that contain either string1 or string2 which not what I want.
grep '...
299
votes
3
answers
317k
views
Regex (grep) for multi-line search needed [duplicate]
I'm running a grep to find any *.sql file that has the word select followed by the word customerName followed by the word from. This select statement can span many lines and can contain tabs and ...