Most Popular
1500 questions
82
votes
7 answers
How can I get bash to exit on backtick failure in a similar way to pipefail?
So I like to harden my bash scripts wherever I can (and when not able to delegate to a language like Python/Ruby) to ensure errors do not go uncaught.
In that vein I have a strict.sh, which contains things like:
set -e
set -u
set -o pipefail
And…

Danny Staple
- 2,161
- 1
- 15
- 22
82
votes
6 answers
How to determine the maximum number to pass to make -j option?
I want to compile as fast as possible. Go figure. And would like to automate the choice of the number following the -j option. How can I programmatically choose that value, e.g. in a shell script?
Is the output of nproc equivalent to the number…

tarabyte
- 4,296
82
votes
4 answers
Write Python stdout to file immediately
When trying to write the stdout from a Python script to a text file (python script.py > log), the text file is created when the command is started, but the actual content isn't written until the Python script finishes. For example:
script.py:
import…

Bart
- 920
82
votes
6 answers
What is a socket?
Could someone explain to me what a socket is? I see it in many acronyms in context of SSL, etc.
Also, why is it called a socket? Is it purely because it was what a name they invented? Or was it the first name they came up with?

chrisjlee
- 8,523
82
votes
5 answers
Why is SIGINT not propagated to child process when sent to its parent process?
Given a shell process (e.g. sh) and its child process (e.g. cat), how can I simulate the behavior of Ctrl+C using the shell's process ID?
This is what I've tried:
Running sh and then cat:
[user@host ~]$ sh
sh-4.3$ cat
test
test
Sending SIGINT to…

rob87
- 823
82
votes
3 answers
top command on multi core processor
I am using freescale IMX6 quad processor. I want to know if the top command lists the CPU usage of all 4 cores or of a single core. I am seeing an application's CPU usage being the same with 4 cores and with a single core. I was guessing the CPU…

user3818847
- 1,171
82
votes
1 answer
Single command to login to SSH and run program?
Is there a way to structure a single command to login via SSH to a remote server and run a program on the remote login shell?
In the OpenSSH manual, it reads "If command is specified, it is executed on the remote host instead of a login shell." So,…

user981178
- 1,047
82
votes
13 answers
How to randomly sample a subset of a file
Is there any Linux command one can use to sample subset of a file? For instance, a file contains one million lines, and we want to randomly sample only one thousand lines from that file.
For random I mean that every line gets the same probability…

clwen
- 953
82
votes
15 answers
mount.nfs: access denied by server while mounting on Ubuntu machines?
I have three machines in production -
machineA 10.66.136.129
machineB 10.66.138.181
machineC 10.66.138.183
and all those machines have Ubuntu 12.04 installed in it and I have root access to all those three machines.
Now I am supposed to…

arsenal
- 3,093
81
votes
2 answers
What do square brackets mean without the "if" on the left?
As far as I know, square brackets are used to enclose an expression usually in if else statements.
But I found square brackets being used without the "if" as follows:
[ -r /etc/profile.d/java.sh ] && . /etc/profile.d/java.sh
in the following…

supertonsky
- 913
- 1
- 7
- 6
81
votes
5 answers
So what are logical cpu cores (as opposed to physical cpu cores)?
I was googling about how I could find the number of CPUs in a machine and I found some posts but I am confused as some mentioned that you get the logical cores vs physical cores etc.
So what is the difference between logical and physical cores and…

Jim
- 10,120
81
votes
3 answers
Which process has PID 0?
I'm looking for the process started in Linux which has process ID 0. I know init has PID 1 , which is the first process in Linux, is there any process with PID 0?

user9744
- 721
- 2
- 8
- 10
81
votes
5 answers
What is D-Bus practically useful for?
dbus is supposed to provide "a simple way for applications to talk to one another".
But I am still not sure what it is useful for, practically. I have never seen a situation where dbus is useful, I only see warnings that some dbus component has…

Martin Vegter
- 358
- 75
- 236
- 411
81
votes
11 answers
View pdf file in terminal
I want to view pdf files directly on our cluster rather than copying them to my local machine and then opening them in a viewer.
How can I view a pdf file in my terminal?

bioinformatician
- 993
81
votes
5 answers
Remove unused packages
I have installed some rpm package on my Fedora 17. Some packages had a lot of dependencies.
I have removed some packages but I forgot remove unused dependencies with yum remove.
How can I do that now?
mudlee