Most Popular
1500 questions
201
votes
9 answers
How to make `sudo` preserve $PATH?
I have a program that is installed in a custom directory under /opt. To make it easier to run it, I edited my bashrc to add said directory to my path:
export PATH=$PATH:/opt/godi/bin:/opt/godi/sbin
This works fine if I want to run the program…
hugomg
- 5,543
- 4
- 35
- 53
201
votes
20 answers
Is there an easy way to replace duplicate files with hardlinks?
I'm looking for an easy way (a command or series of commands, probably involving find) to find duplicate files in two directories, and replace the files in one directory with hardlinks of the files in the other directory.
Here's the situation: This…
Josh
- 8,311
- 12
- 54
- 73
200
votes
9 answers
Split string by delimiter and get N-th element
I have a string:
one_two_three_four_five
I need to save in a variable A value two and in variable B value fourfrom the above string
I am using ksh.
Alex
- 2,255
- 3
- 17
- 12
200
votes
6 answers
Return only the portion of a line after a matching pattern
So pulling open a file with cat and then using grep to get matching lines only gets me so far when I am working with the particular log set that I am dealing with. It need a way to match lines to a pattern, but only to return the portion of the line…
MaQleod
- 2,594
- 4
- 21
- 18
200
votes
3 answers
ifconfig command not found
I've just installed CentOS7 as a virtual machine on my mac (osx10.9.3 + virtualbox) .Running ifconfig returns command not found. Also running sudo /sbin/ifconfig returns commmand not found. I am root. The output of
echo $PATH is as below.…
RobSeg
- 2,440
- 2
- 13
- 13
199
votes
2 answers
How to suspend and resume processes
In the bash terminal I can hit Control+Z to suspend any running process... then I can type fg to resume the process.
Is it possible to suspend a process if I only have it's PID? And if so, what command should I use?
I'm looking for something…
Stefan
- 24,830
- 40
- 98
- 126
199
votes
3 answers
Quoting within $(command substitution) in Bash
In my Bash environment I use variables containing spaces, and I use these variables within command substitution.
What is the correct way to quote my variables? And how should I do it if these are nested?
DIRNAME=$(dirname "$FILE")
or do I quote…
CousinCocaine
- 2,155
- 3
- 13
- 12
199
votes
13 answers
How to start tmux with attach if a session exists
If I use
tmux attach
I can attach to a running session but if there is no session running, I only get the error
no sessions
How can I automatically start a new session if there is none running? something like
tmux attach-or-create-new-session
rubo77
- 27,777
- 43
- 130
- 199
198
votes
8 answers
Using the not equal operator for string comparison
I tried to check if the PHONE_TYPE variable contains one of three valid values.
if [ "$PHONE_TYPE" != "NORTEL" ] || [ "$PHONE_TYPE" != "NEC" ] ||
[ "$PHONE_TYPE" != "CISCO" ]
then
echo "Phone type must be nortel,cisco or nec"
exit
fi
The…
munish
- 7,825
- 24
- 71
- 97
198
votes
7 answers
How to use watch command with a piped chain of commands/programs
I usually use watch Linux utility to watch the output of a command repeatedly every n seconds, like in watch df -h /some_volume/.
But I seem not to be able to use watch with a piped series of command like:
$ watch ls -ltr|tail -n 1
If I do that,…
Tulains Córdova
- 2,926
- 4
- 18
- 26
198
votes
14 answers
Batch renaming files
I have a directory full of images:
image0001.png
image0002.png
image0003.png
...
And I would like a one-liner to rename them to (say).
0001.png
0002.png
0003.png
...
How do I do this?
Internet man
- 3,551
- 3
- 17
- 9
198
votes
5 answers
How to choose directory name during untarring
Say I have file named ugly_name.tar, which when extracted, becomes ugly_name directory. What command can I use such that the resulting directory name is pretty_name instead?
tshepang
- 64,472
- 86
- 223
- 290
197
votes
8 answers
Automated ssh-keygen without passphrase, how?
I would like to make an automated script that calls ssh-keygen and creates some pub/private keypairs that I will use later on. In principle everything works fine with....
ssh-keygen -b 2048 -t rsa -f /tmp/sshkey -q
...except that it asks me for the…
humanityANDpeace
- 13,722
- 13
- 61
- 107
197
votes
5 answers
Is it possible to find out the hosts in the known_hosts file?
I would like to see what hosts are in my known_hosts file but it doesn't appear to be human readable. Is it possible to read it?
More specifically there is a host that I can connect to via several names and I want to find out what the fingerprint I…
Colin Newell
- 2,073
- 2
- 14
- 9
197
votes
2 answers
Bluetooth Pairing on Dual Boot of Windows & Linux Mint/Ubuntu - Stop having to Pair Devices
When dual booting Windows 7/10 and Linux Mint/Ubuntu, you may find yourself having to re-pair your Bluetooth devices again and again. This will happen every time you switch OS.
Now, how do you prevent this?
I'm answering my own question with the…
Mario Olivio Flores
- 4,813
- 4
- 11
- 12