Most Popular
1500 questions
91
votes
3 answers
Joining bash arguments into single string with spaces
I'm trying to join all of the arguments to a Bash function into one single string with spaces separating each argument. I also need to have the string include single quotes around the whole string.
Here is what I have so…

Schwagmister
- 1,053
91
votes
2 answers
suppress stderr messages in a bash script
Consider the following (slightly silly) script name 'test1.sh':
#/bin/bash
#
sleep 10 &
echo sleep pid = $!
pkill sleep
When I run it, I get not only the output of the echo, but bash's reporting of the death of sleep on stderr:
$ ./test1.sh
sleep…

fearless_fool
- 1,075
91
votes
10 answers
How to assign a string value to a variable over multiple lines while indented?
The issue:
I need to assign a variable a value that is decently long.
All the lines of my script must be under a certain number of columns.
So, I am trying to assign it using more than one line.
It's simple to do without indents:
VAR="This…

JamesL
- 1,270
- 1
- 14
- 19
91
votes
5 answers
Comparing two files in Vim
Is it possible to view two files side-by-side in Vim? If so, how can I set up my editor to do this, and is there a way to diff between the two files within Vim?
I am aware of the :next and :prev commands, but this is not what I'm after. It would…

Zaid
- 10,642
91
votes
11 answers
Autocomplete server names for SSH and SCP
I have a few servers configured in ~/.ssh/config, such as alpha and beta. How might I configure Bash such that the commands $ ssh alTab and $ scp file.tgz alTab autocomplete the names of the configured servers?
I don't want to add the servers to…

dotancohen
- 15,864
91
votes
4 answers
What are the responsibilities of each Pseudo-Terminal (PTY) component (software, master side, slave side)?
I am trying to figure out how a tty works1 (the workflow and responsibilities of each element). I have read several interesting articles about it, but there are still some blurry areas.
This is what I understand so far:
The emulated terminal makes…

Pierre-Jean
- 2,239
91
votes
1 answer
Command history in Zsh
How does Zsh keep track of command history?
I see two files in my home directory: .zhistory and .zsh_history. What is the difference between them? The files seem to contain all of my history. Does Zsh keep appending lines to one of them forever?…

Amelio Vazquez-Reina
- 41,161
90
votes
5 answers
What's the difference between pkill and killall?
I know that pkill has more filtering rules than killall. My question is, what is the difference between:
pkill [signal] name
and
killall [signal] name
I've read that killall is more effective and kill all processes and subprocesses (and…

mavillan
- 3,097
90
votes
12 answers
Is there a way to make "mv" fail silently?
A command like mv foo* ~/bar/ produces this message in stderr if there are no files matching foo*.
mv: cannot stat `foo*': No such file or directory
However, in the script I'm working on that case would be completely fine, and I'd like to omit…

Jonik
- 1,480
90
votes
6 answers
Which file compression software for Linux offers the highest size reduction for source code?
I do a ton of file compression. Most of the stuff I am compressing is just code, so I need to use lossless compression.
I wondered if there was anything that offers a better size reduction than 7zip. It doesn't matter how long it takes to compress…

Zach
- 1,031
90
votes
5 answers
Find the owner of a directory or file, but only return that and nothing else
I am looking for a command that will return the owner of a directory and only that--such as a regex parsing the ls -lat command or something similar? I want to use the result in another script.

Jason
- 1,059
90
votes
5 answers
In bash, is it possible to use an integer variable in a brace expansion
I have the following bash script:
#!/bin/bash
upperlim=10
for i in {0..10}
do
echo $i
done
for i in {0..$upperlim}
do
echo $i
done
The first for loop (without the variable upperlim in the loop control) works fine, but the second for loop (with…

Andrew
- 16,855
90
votes
4 answers
Using OR patterns in shell wildcards
Contents of my dir are
$ ls -lrt
total 0
-rw-r--r-- 1 user1 admin 19 Oct 8 12:31 night.txt
-rw-r--r-- 1 user1 admin 19 Oct 8 12:31 noon.txt
-rw-r--r-- 1 user1 admin 38 Oct 8 12:31 day.txt
I would like to list out details of files that have a…

mtk
- 27,530
- 35
- 94
- 130
90
votes
7 answers
How to match case insensitive patterns with ls?
I would like to list all files matching a certain pattern while ignoring the case.
For example, I run the following commands:
ls *abc*
I want to see all the files that have "abc" as a part of the file name, ignoring the case, like
-rw-r--r-- 1 mtk…

mtk
- 27,530
- 35
- 94
- 130
90
votes
2 answers
An easy bash completion tutorial?
I want to learn how to write bash completion scripts. Which tutorial would you recommend?

tshepang
- 65,642