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

learn more… | top users | synonyms

9
votes
6answers
3k views

Running commands in parallel with a limit of simultaneous number of commands

Sequential: for i in {1..1000}; do do_something $i; done - too slow Parallel: for i in {1..1000}; do do_something $i& done - too much load How to run commands in parallel, but not more than, for ...
6
votes
2answers
22k views

How to find all soft links (symbolic links) in current directory?

Question relates to shell-scripting in bash. How to check with a script which files within the current directory are soft links? In case I have used the wrong term, when I say soft links, I am ...
15
votes
3answers
7k views

Change Terminal Title in Mac OS X

How can I arbitrarily change the title of a Terminal window in Mac OS X? I have seen this question and this magicwrap thing, but think it's just a simple Mac OS X command.
12
votes
5answers
8k 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 | ...
7
votes
3answers
805 views

Bash Run command for certain time?

I am making bash script for my use. How can i run a command for certain time, like 20 second and terminate command? I tried a lot of solutions but nothing works, I also tried timeout command with no ...
7
votes
2answers
6k views

Passing two arguments to a command using pipes

Usually, we only need to pass one argument: echo abc | cat echo abc | cat some_file - echo abc | cat - some_file Is there a way to pass two arguments? Something like {echo abc , echo xyz} | cat ...
4
votes
4answers
7k 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 ...
33
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... ...
17
votes
1answer
24k views

Show only current directory name (not full path) on bash prompt

The way my bash prompt is currently configured, it shows the whole path to the current directory. This is annoying when I'm deep inside a directory tree, as the prompt becomes so long that every ...
14
votes
5answers
4k views

Is there a shortcut to mkdir foo and immediately cd into it?

This is something I do frequently $ mkdir foo $ cd foo This works as a single command, but it's more keystrokes and saves no time. $ mkdir foo && cd foo Is there a shortcut for this? ...
12
votes
1answer
1k views

How do I reload .inputrc using a bash script?

This question explains how to reload .inputrc using C-x C-r. But how would one reload it using commands in a bash script?
10
votes
1answer
2k 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 ...
9
votes
6answers
4k 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 ...
8
votes
4answers
4k 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 ...
7
votes
3answers
4k views

grep for “term” and exclude “another term”

I am trying to build a grep search that searches for a term but exludes lines which have a second term. I wanted to use multiple -e "pattern" options but that has not worked. Here is an example of a ...
7
votes
4answers
8k 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 ...
5
votes
2answers
14k 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, ...
4
votes
2answers
2k 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
1answer
3k 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 ...
29
votes
5answers
17k views

Change default text editor for crontab to vim

I'm using ubuntu 9.10 and the default text editor is nano, which i hate. (doesn't everyone?) Normally it's not a problem as i just vi or gedit everything but crontab -e is opening with nano. I ...
21
votes
6answers
24k 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 ...
14
votes
3answers
8k 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'?
9
votes
3answers
3k 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? ...
9
votes
3answers
1k 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
2answers
282 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?
8
votes
3answers
16k 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 ...
7
votes
6answers
2k views

Best practices to alias the rm command and make it safer

Some time ago I erroneously deleted my home folder because I ran a rm -rf * on the wrong terminal, whose working directory was the home folder! I wish I had an alias for the rm command, but it was ...
7
votes
2answers
2k 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
4answers
1k views

Open hidden configuration files without using Terminal

I made some changes to my .profile which corrupted the Terminal app. I can launch terminal but I no longer get a prompt. I can't show hidden files in order to delete the .profile or .bashrc files. ...
7
votes
6answers
4k 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 ...
6
votes
1answer
1k 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 ...
6
votes
3answers
5k 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 ...
6
votes
1answer
19k 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
15k 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
2answers
750 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
5answers
4k 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 ...
2
votes
1answer
394 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 ...
20
votes
3answers
15k 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 ...
10
votes
3answers
2k 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 ...
10
votes
6answers
14k views

Run part of a bash script as a different user

Is there a way to make part of a script run as a different (non-root) user? If it helps , the part to be run as a different user occurs at the end of the script Edit : OS -> Ubuntu 9.04
9
votes
2answers
6k views

Avoid unwanted path in Zip file

I'm making a shell script to package some files. I'm zipping a directory like this: zip -r /Users/me/development/something/out.zip /Users/me/development/something/folder/ The problem is that the ...
9
votes
1answer
4k views

Why does my remote process still run after killing an ssh session?

I'm tailing a remote logfile by running this command in a local shell: ssh remotemachine tail -100f /path/to/error_file When I ctrl-c out of this command, it seems that the ctrl-c kills the local ...
8
votes
4answers
4k 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 ...
7
votes
3answers
1k 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 ...
7
votes
8answers
324 views

Save me from gibbrerish terminal

While logged in to a remote ssh session, sometimes I do cat to the wrong file (a binary or a diretory) and the display converts to gibberish. The only way out is to close the terminal and open a new ...
6
votes
1answer
3k 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 ...
6
votes
6answers
16k views

Sudo - is there a command to check if I have sudo and/or how much time is left?

(Originally posted on Stack Overflow. They suggested I try here instead. Here's the original post: ...
6
votes
2answers
1k views

Smart tab completion (for directories)?

Are there shell versions that have a more intelligent tab completion? I'd like to be able to type cd foo-<TAB> Then it would show me the possible completions along with numbers that I can ...
5
votes
4answers
2k views

Accessing the output of a Bash pipe with 'read'

I'm trying to pipe some data from a Bash pipe into a Bash variable using the read command, like this: $ echo "Alexander the Grape" | read quot $ echo $quot $ But quot is empty. Some Googling ...
4
votes
2answers
113 views

Making custom, single-character directory mappings like ~ > $HOME

We all know that ~ maps to $HOME or /home/user. Is it possible to make other mappings like this on other characters (@,_)? A possible workaround I thought of was to use variables (which require at ...