Skip to main content

Questions tagged [bash]

Bash is a free shell for Unix-like operating systems from the GNU Project.

Filter by
Sorted by
Tagged with
568 votes
6 answers
209k views

Difference between .bashrc and .bash_profile

What's the difference between .bashrc and .bash_profile and which one should I use?
cfischer's user avatar
  • 9,093
128 votes
8 answers
68k views

Forward SSH traffic through a middle machine

SSH tunneling is very confusing to me. I am wondering if I can do this in Linux. I have 3 machines.. A. My local machine at home. B. Machine at work that I can SSH into (middle man). C. My desktop ...
user avatar
489 votes
7 answers
260k views

What is the difference between executing a Bash script vs sourcing it?

What is the difference between executing a Bash script like A and sourcing a Bash script like B? A > ./myscript B > source myscript
Scottie T's user avatar
  • 5,091
402 votes
21 answers
562k views

How do I detach a process from Terminal, entirely?

I use Tilda (drop-down terminal) on Ubuntu as my "command central" - pretty much the way others might use GNOME Do, Quicksilver or Launchy. However, I'm struggling with how to completely detach a ...
user avatar
144 votes
6 answers
66k views

Does bash have a hook that is run before executing a command?

In bash, can I arrange for a function to be executed just before running a command? There is $PROMPT_COMMAND, which is executed before showing a prompt, i.e., just after running a command. Bash's $...
131 votes
17 answers
179k views

How to delete all files in a directory except some?

I need to delete all files in a directory, but exclude some of them. For example, in a directory with the files a b c ... z, I need to delete all except for u and p. Is there an easy way to do this?
Ashot's user avatar
  • 1,449
126 votes
6 answers
230k views

Windows 10 Ubuntu Bash Shell: How Do I Mount Other Windows Drives?

I'm using Windows 10's Ubuntu Bash shell. It maps the C drive fine as /mnt/c. I have other local physical hard drives, mounted in Windows as E: and F: How do I tell Bash to mount these drives too (...
Jason Champion's user avatar
72 votes
5 answers
25k views

Why is . not in the path by default?

On UNIX-like systems over the years (most relevantly to me, Linux), I've noticed that . (current dir) is never in the $PATH by default. Why is this? I recall reading years ago that it was a security ...
dirtside's user avatar
  • 1,061
6 votes
1 answer
4k views

How can I single-quote or escape the whole command line in Bash conveniently?

Introduction Consider a tool like watch that can take another command (e.g. ls -l) like this: watch ls -l # or equivalently watch 'ls -l' If the command is more complicated, it's all about quoting/...
Kamil Maciorowski's user avatar
4 votes
1 answer
5k views

Bash terminal not wrapping text correctly [duplicate]

I am using the gnome-terminal with bash, and when I have a command that should go over the line, it just stays on the same line. So instead of: echo "abcdefghijklmnopqrstuvwxyz" I would get ...
user avatar
127 votes
5 answers
230k views

How can I SSH into "Bash on Ubuntu on Windows 10"?

I have Windows 10 Anniversary Edition with "Bash on Ubuntu on Windows" installed and working. I'd like to be able to SSH into this Ubuntu instance, but although I have openssh-server installed and ...
Mick's user avatar
  • 1,961
53 votes
5 answers
62k views

Create permanent DOSKEY in Windows cmd

I think the title is pretty self explanatory. The question is how can I create an alias in a Windows cmd that will also work after I close and then reopen it. For example I would like an alias ...
nick zoum's user avatar
  • 605
40 votes
2 answers
12k views

Linux: coloring bash prompt will break carriage return

When I try to colorize the bash prompt like this: export PS1="\e[0;31m[\u@\h \W]\$ \e[m " it breaks the carriage return (instead of going to a new line when line is full, it starts in the same line ...
Abonec's user avatar
  • 502
22 votes
2 answers
13k views

Unix: Files starting with a dash, -

Ok, I have a bunch of files starting with a dash, -. Which is not so good... and I want to rename them. In my particular case I would just like to put a character in front of them. I found the ...
Svish's user avatar
  • 39.9k
15 votes
3 answers
3k views

Leave bash script running on remote terminal while not logged in?

I have a bash script that takes several hours to run. While it's running, I would like to do other things, which may involve logging out or disconnecting from the internet (my script runs network ...
Ritwik Bose's user avatar
7 votes
2 answers
1k views

What does ">> file command" do, and how does it differ from "command >> file"?

Picking up from this highly voted comment to What does `>>` mean in terminal command?: "program before" What does that mean? Command obviously, but redirections can also be written prepended, ...
Greenonline's user avatar
  • 2,333
1 vote
1 answer
309 views

Recursively search files with exclusions and inclusions

I would like to use find to recursively search files and print them to a file. I imagine a command like this: find /local/data/ --exclude 'database/session*' --include='database/session_*.db' > ...
machinery's user avatar
  • 253
4 votes
1 answer
4k views

What does #* mean in Bash?

Gave up everything else I have to do today to try to read the Bash script here. What does the "#*" mean instead of an array index in ${line#* } can't find this anywhere and special ...
Borea Deitz's user avatar
  • 1,167
220 votes
7 answers
297k views

Why does Ctrl + V not paste in Bash (Linux shell)?

When I copy something to the clipboard and press Ctrl + V in Bash, nothing happens; However, right clicking and selecting Paste does the job. Why? Is there any reasonable issue (I'm sure there is) ...
Yasser Zamani's user avatar
4 votes
1 answer
7k views

How to execute complex command line over ssh?

I sometimes want to get the env of a docker container running on a remote host. To do this I log into the host: ssh [email protected] and then I run this command: sudo docker exec -it `sudo ...
kramer65's user avatar
  • 1,424
798 votes
13 answers
855k views

What does 'source' do?

$ whatis source source: nothing appropriate. $ man source No manual entry for source $ source bash: source: filename argument required source: usage: source filename [arguments] It exists, and it is ...
Andrea Ambu's user avatar
  • 8,648
145 votes
8 answers
172k views

Where does $PATH get set in OS X 10.6 Snow Leopard?

I type echo $PATH on the command line and get /opt/local/bin:/opt/local/sbin:/Users/andrew/bin:/usr/local/bin:/usr/local/mysql/bin:/usr/local/pear/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/...
Andrew's user avatar
  • 15.1k
77 votes
9 answers
134k views

Unable to change file permissions on Ubuntu Bash for Windows 10

I was trying to use an ssh instance and I received the following error, which is odd since I tried to change the permission using chmod, but that didn't seem to work as permissions were still 777: @@@@...
iii's user avatar
  • 873
22 votes
1 answer
17k views

Why does `echo -e "\\\SOME_TEXT"` show only one backslash?

Could some one explain what is happening behind the scenes in character escaping in Linux shell? I tried the following and googled a lot, without any success in understanding what (and how) is going ...
Mohammed Noureldin's user avatar
4 votes
1 answer
5k views

How can the bash shell on Window be completely reset?

I'm new to Unix but interested learn, so started trying to use bash/Ubuntu on Windows. Unfortunately, bash crashed and now bash/Ubuntu seems to be broken as most folders are now missing from the ...
Matt's user avatar
  • 43
1 vote
2 answers
7k views

How can I execute a command on a remote server through scp?

When using ssh to access raspberry pi running balenaos, ssh -t -p 22222 root@device-ip "balena-engine exec -it <container_name> /bin/sh" grants me access to a specific container inside ...
Ken's user avatar
  • 11
152 votes
8 answers
139k views

How to configure PuTTY so that Home/End/PgUp/PgDn work properly in bash?

The keys Home, End, PageUp, PageDown all type a ~ in my bash session instead of moving the cursor / view around. Why does this happen and which settings do I need to change? GNU bash, version 4.0.28(...
RomanSt's user avatar
  • 9,817
118 votes
2 answers
72k views

How to remove/reset Windows Subsystem for Linux on Windows Insider Build 14316

I installed the Windows Subsystem for Linux on Windows 10 Insider Preview build 14316. Now I would like to remove it or, better, revert to its factory defaults i.e. as it was when just installed. I ...
shub's user avatar
  • 1,440
83 votes
1 answer
9k views

Is redirection with `>>` equivalent to `>` when target file doesn't yet exist?

Consider a shell like Bash or sh. The basic difference between > and >> manifests itself in a case when the target file exists: > truncates the file to zero size, then writes; >> ...
Kamil Maciorowski's user avatar
28 votes
2 answers
2k views

How to prevent Bash from altering history?

If I press the Up or Down arrows on my keyboard and then modify something from my history, it's changed forever. Even if I press Ctrl-C and then try to bring it up again, it's still changed -- I've ...
user541686's user avatar
  • 23.7k
24 votes
4 answers
7k views

What does this cryptic Bash command mean?

I was reading Ubuntu Forum's warning about malicious commands and found this interesting gem: :(){ :|:& };: WARNING: The above code will crash your machine unless you have strict proc limits in ...
TheLQ's user avatar
  • 2,887
4 votes
3 answers
7k views

Add folder to PATH

How to add something to PATH ? I have added like PATH=$PATH:/home/example export PATH and it works until I restart , after that when I type env in PATH there is no /home/example.
Saban's user avatar
  • 41
0 votes
3 answers
2k views

Move all files in local directory to remote SFTP directory

I want to move all files in local directory to remote directory. And I am using this code to achieve it SOURCE_FILE=/var/www/oneserver/* TARGET_DIR=/var/www/anotherServer ARCHIEVEFILE=/var/www/...
Al Kasih's user avatar
  • 109
156 votes
8 answers
258k views

Windows Linux Subsystem - Accessing Files outside of Ubuntu

Why, when I create a file from within Windows for example, can I not see it under the Linux sub system in Windows 10 (bash.exe) The screenshot should explain. Folder: OMG was created from within ...
Dave Hamilton's user avatar
137 votes
6 answers
49k views

How do I reload .inputrc?

Background I have heard that the readline module is reading ~/.inputrc and that is how it changes the behaviour of keystrokes under programs such as bash. Question How can I reload this after ...
Captain Lepton's user avatar
125 votes
6 answers
71k views

Git Bash Here in ConEmu

How do I create a right-click context menu entry to open Git Bash at a given folder within ConEmu? See Git Bash Here in Console2 for the equivalent question for Console2.
Charles Roper's user avatar
108 votes
2 answers
57k views

How to rehash executables in $PATH with bash

The subject says it all, how to rehash the available executables available within one of the $PATHs after having changed things: e.g. removed a binary from one $PATH which is available in another $...
Patrick B.'s user avatar
  • 2,978
96 votes
14 answers
63k views

How to get git-completion.bash to work on Mac OS X?

I have followed http://blog.bitfluent.com/post/27983389/git-utilities-you-cant-live-without to add git-completion.bash to my /opt/local/etc/bash_completion.d/git-completion and I put PS1='\h:\W$(...
n179911's user avatar
  • 3,683
89 votes
4 answers
60k views

How to backup (WSL) Linux Subsystem for Windows 10, before system reset or reinstall?

My problem is that I have to reset or reinstall windows because of some problems but I spent a lot of time to configure WSL for development and don't want to lose it. Is there any way of backing up ...
emipac's user avatar
  • 993
87 votes
22 answers
151k views

Monitoring a file until a string is found

I am using tail -f to monitor a log file that is being actively written to. When a certain string is written to the log file, I want to quit the monitoring, and continue with the rest of my script. ...
Alex Hofsteede's user avatar
78 votes
7 answers
48k views

Set the title of the terminal window to the current directory

How can I get the Terminal.app in OS X to display the current directory in its window or tab title? I'm using the bash shell.
kareman's user avatar
  • 891
52 votes
17 answers
60k views

Replace Symbolic Links with Files

Is there an easy way to replace all symbolic links with the file they link to?
Marty Trenouth's user avatar
32 votes
1 answer
7k views

Is there a way to make bash more TAB friendly?

I use bash on both my Mac and as my cygwin shell. Overall, I'm quite pleased with it. My one complaint however is that its TAB completion isn't as good as Windows Command Line TAB completion. For ...
Frank Krueger's user avatar
20 votes
6 answers
8k views

How can I move around the bash commandline efficiently?

So I use the up in my shell (Bash on OSX or Ubuntu, mostly) but some of the time I know that I want the stuff after the cursor's current location. Is there any way to have the line I'm on complete ...
Dan Rosenstark's user avatar
11 votes
4 answers
4k views

Unix tools: what if a file is named minus something?

I'm always wondering: most GNU/Unix tools take options in the form "minus something", sometimes followed by an argument. What if you got a file named minus something? $ ls -f $ rm -f $ ls -f $ mv -f ...
user avatar
5 votes
1 answer
6k views

How/why does ssh output to tty when both stdout and stderr are redirected?

I've just noticed that ssh user@host >/tmp/out 2>/tmp/err can write something like Warning the RAS host key... ... Are you sure you want to continue connecting (yes/no)? stdout and stderr ...
spraff's user avatar
  • 2,198
495 votes
11 answers
1.3m views

What is the home directory on Windows Subsystem for Linux?

When I start bash on Windows Subsystem for Linux, it drops me in the directory /mnt/c/Users/<username> When I ls this directory, I see the directories Desktop, Documents, etc. that I can see ...
bcf's user avatar
  • 5,093
249 votes
11 answers
371k views

What to do when Ctrl + C can't kill a process?

Ctrl + C doesn't always work to kill the current process (for instance, if that process is busy in certain network operations). In that case, you just see "^C" by your cursor and can't do ...
Dustin Boswell's user avatar
179 votes
23 answers
67k views

Add directory to $PATH if it's not already there

Has anybody written a bash function to add a directory to $PATH only if it's not already there? I typically add to PATH using something like: export PATH=/usr/local/mysql/bin:$PATH If I construct ...
Doug Harris's user avatar
168 votes
4 answers
117k views

How to use spaces in a bash alias name?

I am trying to create an aliases in bash. What I want to do is map ls -la to ls -la | more In my .bashrc file this is what I attempted: alias 'ls -la'='ls -la | more' However it does not work ...
sixtyfootersdude's user avatar

1
2 3 4 5
20