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

learn more… | top users | synonyms

5
votes
3answers
8k views

How can I start multiple screen sessions automatically?

I'm trying to build a command that launches screen, creates four sessions with different names, and run four different commands. I know how to do this manually: 1. screen 2. ./command1 args 3. ...
31
votes
7answers
48k views

tar: Exiting with failure status due to previous errors

I have written a little script that tars and compresses a list of directories + files. The script appears to run succesfully, in that a useable .tar.gz file is created after the script runs. ...
17
votes
4answers
18k views

How do I convert a bash array variable to a string delimited with newlines?

I want to write out a bash array variable to a file, with each element on a new line. I could do this with a for loop, but is there another (cleaner) way to join the elements with '\n'?
11
votes
2answers
12k views

(reverse-i-search) in bash

I usually end up using CTRL+r for (reverse-i-search), however, sometimes I pass the command that I was looking for; if I do again a (reverse-i-search) it doesn't find it anymore. I assume that the ...
10
votes
2answers
3k 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 ...
9
votes
1answer
5k views

Why is cat not changing the access time?

The second call to cat a file does not update the access time. I was expecting the access time to be updated ever time a file contents gets displayed. I see the same behaviour if I open the file in ...
9
votes
2answers
3k views

How can you customize your terminal bash prompt with smiley faces?

I'm trying to figure out how I can customize my terminal's bash prompt to use smiley faces. What I want (as seen in the example blow) is for the cwd to be separated from the prompt by a \n and show a ...
7
votes
3answers
22k views

How to delete files on the command line with regular expressions?

Lets say I have 20 files named FOOXX, where XX is the number of the file, eg 01, 02 etc. At the moment, if I want to delete all files lower than the number 10, this is easy and I just use a wildcard, ...
6
votes
5answers
5k views

Clearing terminal

I would like to issue a command from a bash script to clear the terminal it is running from: I don't want to clear the bash history (history -c) I don't want to issue the clear command (which ...
6
votes
4answers
5k views

Bash: create anonymous fifo

We all know mkfifo and pipelines. The first one creates a named pipe, thus one has to select a name, most likely with mktemp and later remember to unlink. The other creates an anonymous pipe, no ...
5
votes
4answers
9k views

Is there a way to get iTerm + Bash usability on Microsoft Windows?

I've been using Bash for years and I really like iTerm. Is there a way to get that level of console usability for Micosoft's Windows cmd? By that I mean the sane tab completion, history (even if you ...
4
votes
3answers
3k views

Stop a Mac from sleeping while a bash script is running, then allow it to sleep as normal once complete

I've got my Mac to wake up during the night and run an rsync to back it up. This is configured through Energy Saver > Schedule. However it seems that it's going back to sleep before it can get ...
3
votes
2answers
4k views

OSX 'open with' bash script

I've got a bash script, potentially many of them in fact, which I'd like to be able to open files in OSX's finder with. It's a really, really simple concept but for some reason bash scripts are ...
34
votes
12answers
3k views

How do I remove a file in Linux whose name looks like it's ONLY a hyphen, as in “-”

I've tried rm -- - rm "-" rm "\-" rm \- Gave Perl a shot ~$ perl -e '$junk = glob("-"); chomp $junk; print "$junk\n"; `rm $junk`;' - rm: cannot remove `-': No such file or directory ...and... ...
15
votes
3answers
26k views

Extract/save a mail attachment using bash

Using normal bash tools (ie, built-ins or commonly-available command-line tools), is it possible, and how to extract/save attachments on emails? For example, say I have a nightly report which ...
13
votes
3answers
5k views

How can I do Ctrl-Z and bg in one keypress to make process continue in background?

So I realized I follow this pattern of suspending the task and then letting it to continue too often with the Ctrl-Z bg sequence, I was wondering is there any way to compress that to single keypress? ...
12
votes
1answer
3k views

Understanding control characters in .inputrc

My Linux account in a remote machine comes with the following pre-defined .inputrc "\e[1~": beginning-of-line "\e[4~": end-of-line “\e[5~”: history-search-backward “\e[6~”: history-search-forward ...
11
votes
6answers
6k views

How to remove duplicated files in a directory?

I downloaded a lot of images in a directory. Downloader renamed files which already exist. I also renamed some of the files manually. a.jpg b.jpg b(2).jpg hello.jpg <-- manually renamed ...
10
votes
1answer
11k views

run or send a command to a tmux pane in a running tmux session

I want to write a shell script which will attach to a named tmux session, select a window (or pane) in that session and run a command in that selected window (or pane). How do I do this from a bash ...
8
votes
1answer
252 views

Is there a way of using ctrl-r after typing part of command in bash?

In bash the Ctrl+r command is very useful, I type Ctrl+r whatever and it searchs my history for commands containing the word whatever. But if I type whatever and realize that I would like search that ...
8
votes
1answer
2k views

Configuring sysrq in linux

The file /proc/sys/kernel/sysrq contains a single number, such as 1 (enable all sysrq commands), 0 (disable all), or a base-10 positive integer which functions as a binary bitmask, enabling a subset ...
7
votes
4answers
5k 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 ...
7
votes
4answers
10k views

SCP from one external server to another

I am trying to use SCP on my local server to copy a file from one remote server to another remote server (both remote servers use a custom port (xxxx) I am trying: scp -r -P xxxx ...
6
votes
3answers
7k views

Recursive ls with conditions

Why can't I use a command like this to find all the pdf files in a directory and subdirectories? How do I do it? (I'm using bash in ubuntu) ls -R *.pdf EDIT How would I then go about deleting all ...
32
votes
4answers
28k views

Find out if user name exists

How can I find out, in a shell script, whether a given user name exists on the current system? /etc/passwd and /etc/shadow are incomplete. Consider OS X's Directory Services, or Linux with Likewise ...
13
votes
3answers
14k views

How to enter login information for a website from the linux command line

My internet connection is provided by the university. It is protected to a username/password combination. This means when I start up my computer, I have to start a web browser and open an arbitrary ...
11
votes
4answers
1k views

Who deals with the star * in echo *

Who deals (interprets) the * in echo * Does the echo see the star or the shell take care about it and return a list of filename .. What about cp temp temp*
9
votes
6answers
5k views

Custom vim highlighting

I am editing some xml right now and I have been leaving myself some comments of things to come back to. Like this <!-- Question: bla bla --> I am editing with vim right now and I would like ...
9
votes
3answers
2k views

Bash shell tab completion, don't expand the ~

I use the Tab key a lot when I use the shell (bash). But I'm getting annoyed that ~ always gets expanded to /home/"user". I don't think it's always been like this; is there any way to stop this ...
8
votes
3answers
1k views

Is there a shell which supports fuzzy completion as in Sublime Text?

I'm using bash and I was wondering if there is any plugin in bash or other shell which allows me to do this cat tfnislong.txt + [tab] completes to cat ThisFileNameIsSoLong.txt just like tab completion ...
8
votes
2answers
288 views

How would you delete a folder called * in / from bash?

Let's say i had a folder named * under /. I know that common commands like rm -rf * won't work. Any help?
7
votes
3answers
21k views

PHP script can't run bash script. sh: Permission denied

I'm trying to exec a .sh script from PHP, however it is not executing. I checked the error logs, and I'm getting the 'sh: Permission denied' error. I checked under which user php is being run, and ...
6
votes
1answer
23k views

Bash & 'su' script giving an error “standard in must be a tty”

Folks, I'm having an issue with a bash script which runs a particular command as a different user. The background: Running on a Linux box (CentOS), the script is quite simple, it's starting the ...
6
votes
4answers
18k views

How can I add menu items to the Gnome “Applications” menu from the command line?

I'm using Ubuntu 9.10, and I'd like to automate the addition of some menu items the Ubuntu "Applications" menu. I know that I can use alacarte to make one-off additions, but I'm looking to automate ...
5
votes
1answer
3k views

Counting occurrences in first column of a file

We have this file: 1 2 1 3 1 2 3 3 52 1 52 300 and 1000 more. I want to count the number of times each value occurs in the first column. 1 3 3 1 52 2 This means we saw 1 three times. How ...
5
votes
2answers
17k views

Linux: How to automatically run commands on SSH login?

Whenever I login to my Linux server I'd like to have several commands run automatically (set some variables, change location, etc.) This needs to be done on user login, not on system start. How can ...
5
votes
3answers
5k views

remove first line in bash

Do you have a method to quickly remove the first line of a file in bash shell ? I mean using sed or stuff like that.
5
votes
2answers
1k views

How can I run a different command but with the same arguments?

For example, I edit and then run the same source. vim arbit.py python arbit.py I know I could run it from within vim, but I want a general solution on Bash. I keep finding situations where I reuse ...
5
votes
7answers
2k views

What is the difference between “Shell” and “Terminal”? [duplicate]

I am fairly new to Ubuntu and I am loving it! But I don't quite understand the difference between the shell and the terminal. Can any one explain? Someone told me that a terminal is just a "tool" to ...
3
votes
2answers
3k views

bash home/end/delete key inserting tilde, or if preceded by escape key, [1~ [3~

bash home/end/delete key inserting tilde, or if preceded by escape key, [1~ say I type echo hellp, move cursor to hel|lp and type delete, and bam, i got ~tilde say I type echo hellp, move cursor to ...
2
votes
1answer
511 views

gnu screen: find which screen window has a given running process or variable?

I would like to find out which of my ~50 gnu screen windows has a process running with a specific variable defined in it. For example, about a week ago, I did this: id=ABC123456; ~/run_long_process ...
24
votes
3answers
24k 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 ...
14
votes
4answers
8k views

How do you escape apostrophe in single quoted string in bash?

I don't understand how bash evaluates escaping of apostrophe characters in single quoted strings. Here is an example: $ echo ''\''Hello World'\''' 'Hello World' # works $ echo '\'Hello World\'' ...
12
votes
3answers
2k views

How can I add a command to the Bash history without executing it?

Every now and then it would be useful to add a command directly to the history in Bash without actually executing it. So far the closed thing I have found is adding a # in front of it and hitting ...
11
votes
9answers
8k views

How do I copy file named starting with a dot?

I am trying to copy all files under directory A to directory B. All files under directory A are starting with dot, for example: A/.a A/.b A/.c which I found if I use: cp A/* B, always get error: ...
10
votes
5answers
25k views

command not found when using sudo

There are a few question on the site that seem related to my problem but I could not find a solution in any of them. My operating system is Ubuntu 12.04. I have mvn installed in ...
10
votes
4answers
4k views

`alias rm=“rm -i”` considered harmful?

I have read some time ago (can't find the reference) that using such an alias as alias rm="rm -i" was very bad. Is there historical evidence or common sense explanation for that fact? I would ...
10
votes
4answers
6k views

how to make bash not to wrap output?

Whenever some command generates long lines as output ( for example, when ls -l a folder which contains files with long names ), the long lines are wrapped to next line, thus messing up the column ...
9
votes
10answers
12k views

Bash scripting: test for empty directory

I want to test if a directory doesn't contain any files. If so, I will skip some processing. I tried the following: if [ ./* == "./*" ]; then echo "No new file" exit 1 fi That gives the ...
9
votes
3answers
3k views

avoid permission denied spam when using find-command

I often try to find files with following syntax: find . -name "filetofind" However it usually results as many rows or error reporting (Permission denied) about folders where permission is denied. ...