Questions tagged [bash]
Bash is a free shell for Unix-like operating systems from the GNU Project.
990
questions
74
votes
6
answers
179k
views
How to SSH into WSL from Windows on the same machine
I followed the instructions in this answer:
How can I SSH into “Bash on Ubuntu on Windows 10”?
I'm attempting to SSH from PuTTY in Windows on the same machine. Using Port 22, which matches my config ...
71
votes
9
answers
117k
views
Can I use pipe output as a shell script argument?
Suppose I have a bash shell script called Myscript.sh that need one argument as input.
But I want the content of the text file called text.txt to be that argument.
I have tried this but it does not ...
66
votes
5
answers
62k
views
Bash command to focus a specific window
Is there a way, in bash command line, to give focus to a specific window of a running process. Assume I know the process' name, number, and anything else I need.
For instance, if I have a single ...
65
votes
7
answers
66k
views
Newlines in sed on Mac OS X
I find that \n doesn't work in sed under Mac OS X.
Specifically, say I want to break the words separated by a single space into lines:
# input
foo bar
I use,
echo "foo bar" | sed 's/ /\n/'
But the ...
55
votes
5
answers
173k
views
How to cd to a directory that contains a space in its name?
I have a directory called "Reader 0.5" in my Desktop on Mac Os X. When to access the directory in terminal, I am using below code:
cd /Users/niho/Desktop/Reader 0.5
but it throws:
No such file or ...
52
votes
4
answers
176k
views
Copy list of files
I have a list of files separated by spaces in a file list.txt. I'd like to copy them to a new folder.
I tried to do:
cp `cat list.txt` new_folder
but it did not work.
How would you do this ?
...
51
votes
6
answers
91k
views
Change DNS Server From Terminal (or script) on Mac OS X
How can I change my DNS server from the Terminal on Mac OS X? [I need this because my DNS is not working correctly with my VPN. Sometimes it's using the DNS for my main connection, and sometimes it's ...
51
votes
6
answers
55k
views
"watch" the output of a command until a particular string is observed and then exit
I'm looking for a way to programmatically watch the output of a command until a particular string is observed and then exit. This is very similar to this question, but instead of tailing a file, I ...
44
votes
9
answers
54k
views
How do I keep my bash history across sessions?
I am working on a x86 target running fedora 9.
Whenever I reboot it, my history returns to some state, and I do not have commands I did in the sessions before the reboot.
What I have to change to ...
41
votes
5
answers
72k
views
Writing "tail -f" output to another file
As a continuation from my last post where I have used grep & tail -f to find occurences of "rare" events. I would like to record this in another file.
I've tried turning
tail -f log.txt | ...
35
votes
5
answers
32k
views
How to replace part of a text file between markers with another text file?
Say I have a text file like this:
# custom content section
a
b
### BEGIN GENERATED CONTENT
c
d
### END GENERATED CONTENT
I'd like to replace the portion between the GENERATED CONTENT tags with the ...
33
votes
3
answers
161k
views
How to replace line in file with pattern with sed?
I'm reading a lot of documentation on sed, and am still stumped on my particular use case.
I want to replace this line in a conf file with my own line:
Replace this line: #maxmemory <bytes>
...
30
votes
7
answers
117k
views
'No such file or directory' error in bash, but the file exists?
On Ubuntu, I get a 'No such file or directory' error when I try to execute a command.
I have checked with ls -la , the file adb is there and it has 'x' flag
So why I am getting a 'No such file or ...
28
votes
2
answers
4k
views
Where is the Ubuntu console on Windows10? [duplicate]
I updated my Windows 10 system to the 1607 "Anniversary Update" version and I can't find the Ubuntu Bash console.
So... Where is it?
27
votes
4
answers
7k
views
A command before every bash command
Does anyone know a mean of putting a 'time' command before every command in a bash session?
26
votes
2
answers
4k
views
Tab-completion with directories/links
I have this problem with tab-completion in terminal in both archlinux and ubuntu:
I have a link which links to a directory named "something" in my home directory. Now when I open a terminal and want ...
26
votes
6
answers
137k
views
How to get real-time network statistics in Linux with KB/MB/Bytes format and for specific port or application processID?
I used IPTraf, Iftop, vnstat, bwm-ng, ifconfig -a. None of them is helping me to find real-time packets that are being sent/received from my application in KB or MB format. The reason is I am writing ...
23
votes
2
answers
9k
views
Writing shell scripts that will run on any shell (using multiple shebang lines?)
I've just started getting deeper into shell scripting, and I've always just thrown my script in a file, marked it chmod +x and then done /path/to/script.sh and let whatever interpreter is the default ...
22
votes
11
answers
20k
views
Pushing my PS1 prompt over ssh
I use a specific "PS1" prompt that I like. I share a few logins with other other people on a few different servers. I was wondering if there was a way to specify in my local bash profile a remote ...
21
votes
2
answers
5k
views
Cannot execute script while its permission is 'x'
I have a script in the current directory, however, given that:
the permission is -rwxr-xr-x
the script has a shebang #!/bin/bash at the top of the file
my shell is /bin/bash
I can execute it using ...
20
votes
9
answers
15k
views
How to retrieve the absolute path of an arbitrary file from the OS X
I'm looking for a simple command that can be used within Bash to find the absolute and canonicalized path to a file on an OS X (similar to ``readlink -f'` under Linux).
The following sample bash ...
19
votes
3
answers
17k
views
Program to check/look up UTF-8/Unicode characters in string on command line?
I've just realized I have a file on my system; it lists normally:
$ ls -la TΕSТER.txt
-rw-r--r-- 1 user user 8 2013-04-11 18:07 TΕSТER.txt
$ cat TΕSТER.txt
testing
... yet, it crashes a piece of ...
18
votes
1
answer
737
views
Multiple Installations and Understanding $PATH
I have an older version of Git installed at:
/usr/bin/
I recently downloaded a newer version to:
/usr/local/bin
When I type:
which git
I get the location of the old version. I believe that this ...
16
votes
1
answer
2k
views
When should I put configurations into .bashrc vs into. .bash_profile?
I was looking at Questin 9152: Why doesn’t my path update now?. Which customizations should go into my ~/.bashrc file vs. into my ~/.bash_profile file?
16
votes
2
answers
9k
views
What happens to running processes when I lose a remote connection to a *nix box?
I occasionally lose my remote SSH connection to my VPS. I use screen for long-running processes, but am wondering what happens to the processes I had running aside from those run within a screen ...
14
votes
4
answers
8k
views
Bash Run command for certain time?
I am making a bash script for my own use. How can I run a command for a certain time (like 20 seconds) and then terminate it? I have tried a lot of solutions but nothing works. I also tried the ...
14
votes
2
answers
31k
views
Write a PID file manually from Bash script
How could I write a Bash-script that runs a long running program and stores the programs process id in a separate file?
I want something like
#!/bin/bash
exec long_running_tool
echo `ps af |grep "...
14
votes
5
answers
9k
views
How to replace vim screen buffer with previous bash activity after quitting?
I'm trying to find out what a bash (or vim) feature is. Here's the scenario. I'm in a bash terminal, then edit something with vim, then exit back to bash. In some terminals, the vim session screen ...
13
votes
3
answers
517
views
Reuse text on a bash command
If i'm writing a long command or just typing an extensive file path, is there any that i can "reuse" it with some command shortcut?
e.g:
1.cp /home/myuser/really/big/file/here/and/there.png /home/...
13
votes
6
answers
14k
views
Messed up keys in vim when running inside tmux
I have been playing with tmux and I'm loving it. However, there's an annoying issue when running vim inside it.
Somehow the arrow keys get remapped, but only on certain times, like when firing up ...
12
votes
5
answers
26k
views
Ubuntu/ Gnome : Open an application in a specific workspace
How do tell an application to open in a specific workspace?
More info:
I like to have my C++ IDE in workspace 2, my Java IDE in workspace 3, and my email, browser and miscellaneous in workspace four....
12
votes
2
answers
7k
views
Make OS X Terminal commands I type BOLD
I'd like to make commands I've typed (input) into terminal stand out from all the output.
For example:
imac:~ buster$ chmod -R g-w myfolder
imac:~ buster$ cd myfolder
imac:myfolder buster$ ls -l
...
12
votes
2
answers
3k
views
How do I make OS X set the terminal title back to the original title when coming back from ssh?
Starting on OS X, I ssh into foo (a Linux box). My terminal title changes to foo. I then ssh into bar (another Linux box). My terminal title changes to bar. I log out of bar. My terminal title ...
11
votes
3
answers
3k
views
Calling a script with ./bla.sh vs. . bla.sh
Can anybody explain to me what the shell does in the two examples A) and B) below?
It obviously behaves differently, but I can't find out why the output is different.
Example:
Let's have a script in ...
9
votes
2
answers
1k
views
How do I delete a file named "-p" from bash?
How do I delete a file named -p in bash? Trying rm "-p" complains that -p is not a valid argument.
9
votes
1
answer
8k
views
colouring output of ls according to file extension
I am working on some C++ files all of which are in a single folder.
When I do ls both the .cpp and the .h files show up in the same colour.
Is there a way to tell the bash shell that I want to ...
9
votes
2
answers
2k
views
Creating an alias containing bash history expansion
I often forget to run a command with sudo, so I find myself often typing sudo !! immediately afterwards.
I tried aliasing this, but bash chokes on the !! part. Is there some way to represent this ...
8
votes
2
answers
43k
views
Find difference with mtime - and +
What is the difference with mtime's - and + switches as both are not bringing back the results I need?
I'm looking to delete all files older than 5 days:
find /mnt/sdb1/tmp/ -type f -mtime +5 -exec ...
8
votes
4
answers
4k
views
Terminal: prefix previous command?
Frequently in Terminal (though I fully expect any answer will work in bash and most others), I type some command, and then get some sort of permission error due to missing sudo.
Okay, so press 'up', ...
8
votes
5
answers
31k
views
How do I run a script in the background and leave it running when I log out? [duplicate]
Possible Duplicate:
Leave bash script running on remote terminal while not logged in?
I have a bash script that runs Gaussian, a chemical structure calculator, which spends a couple days toying ...
7
votes
2
answers
3k
views
How to set the command prompt's color in Bash?
Browsing the last command's results in Bash is a bit hard because the command prompt and results are the same color. This makes it hard to separate the results of consecutive commands.
How do I ...
7
votes
1
answer
14k
views
Associating linux shell (.sh) scripts on Windows 10 to Bash or WSL [duplicate]
If you ever tried to run an .sh linux script on Windows 10 by double-clicking it, after assigning it to bash.exe (Ubuntu Bash for Windows 10) by default, you most likely noticed it wouldn't open.
Why ...
7
votes
1
answer
2k
views
Bash pipeline signal propagation - how does it work?
While answering this question, I was unable to fully explain how signals propagate through a pipeline.
Consider the following examples.
Using timeout as the first element in the pipeline
This ...
7
votes
3
answers
17k
views
Why does `ls` work on my cmd? (Windows)
I'm running windows 7, it's old and I have messed around with it a bit. When I'm in cmd I find that ls works just like I would expect it to in Linux. So do a few other commands such as mv and rm. This ...
7
votes
1
answer
967
views
bash: per-command history. How does it work?
OK. I have an old G5 running Leopard and a Dell running Ubuntu 10.04 at home and a MacPro also running Leopard at work.
I use Terminal.app/bash a lot. On my home G5 it exhibits a nice feature: using ↑...
5
votes
2
answers
3k
views
How to keep the command line prompt on the first line of terminal?
I need to keep the command line on the top of the screen and see the output of any command below it. How can I achieve this using any available tools on any platform?
Currently, on the all terminal ...
4
votes
5
answers
1k
views
Command-T for shell
I'm looking for a shell extension that allows me to do filename completion similarly to Command-T.
Command-T a feature in TextMate and a plugin for Vim that allows you to select filenames by typing ...
4
votes
2
answers
751
views
How to foreground a process started by upstart?
Is it possible to foreground a process started by upstart?
root@me:~# ps aux | grep my-app
root 2208 0.2 0.0 1456 480 ? S 17:38 0:01 /opt/me/my-app
root@me:~# fg 2208
-bash: fg:...
4
votes
3
answers
10k
views
sudo permission denied
I ran this code:
sudo cat <<EOF | sudo sed -e "s,%,$,g" >/etc/init.d/dropbox
echo "Hello World"
EOF
But even though, I get "permission denied", cause you have to be root to make changes ...
4
votes
2
answers
4k
views
Crossfading Video AND Audio with ffmpeg
This Super User answer crossfade between 2 videos using ffmpeg has got me so far, but now that I have tried many solutions and seen every SO link out there, it's time to ask you all for help.
I am ...