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

learn more… | top users | synonyms

8
votes
4answers
3k 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 ...
5
votes
2answers
1k 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 ...
3
votes
1answer
2k 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 ...
2
votes
1answer
650 views

How do you remove nested empty directories using a Bash script on Linux?

I want to be able to run a script that will remove all my empty directories. The problem is some of them are nested, i.e. directories that only have empty directories in them, so the script needs to ...
1
vote
6answers
617 views

downloading complete web pages (not sites)

I often use offline time (e.g. when on the car/train/plane) to read articles pulled from the web. To store the content, I currently use Firefox's Save Page As. (Note that's not recursively downloading ...
3
votes
2answers
521 views

How to reorder folders? (as displayed in `ls -U`)

I've got a number of unordered folders on a memory stick, which my car stereo shows in order of their real position on the stick (i.e. same as ls -U) What's the easiest way of physically reordering ...
3
votes
3answers
3k 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 ...
3
votes
2answers
8k views

How to use scp in a bash script without specifying password?

I am a bash newbie, and am writing a bash script that will allow transfer of files between two computers. BTW, is there a more secure alternative to scp? Currently, I am doing this manually, by using ...
2
votes
1answer
136 views

Difference between / and // directories in bash OSX

I was working in the bash terminal on my system (OSX 10.8.3 / bash version 3.2.48(1)-release (x86_64-apple-darwin12)) and I accidentally typed "cd //" instead of "cd /" to get back to the root ...
1
vote
1answer
169 views

Bash prompt error when pressing up arrow

I've written this nice and colorful prompt for my OS X terminal: parse_git_branch() { git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ [\1]/' } export ...
36
votes
6answers
48k views

Mac OS X keyboard shortcuts for terminal

After googling for some Mac OS X terminal shortcuts, I wanted to find how can I go back characters on a line on the terminal or words or similar. I found ALT + B but it does not work. Do you know ...
29
votes
4answers
17k views

Cygwin fatal error unable to remap.. What does it mean?

0 [main] python 6140 C:\cygwin\bin\python.exe: *** fatal error - unable to remap \\?\C:\cygwin\lib\python2.6\lib-dynload\time.dll to same address as parent: 0x2B0000 != 0x360000 Stack trace: Frame ...
15
votes
4answers
3k views

A command before every bash command

Does anyone know a mean of putting a 'time' command before every command in a bash session?
13
votes
3answers
31k 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 ? ...
25
votes
1answer
34k 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 ...
32
votes
8answers
16k views

Rename a group of files with one command

If I have a group of files with a .htm extention, how can I rename them all to .html? mv *.htm *.html does not work.
27
votes
5answers
30k views

How can I do a recursive find and replace from the command line?

Using a shell like bash or zshell, how can I do a recursive 'find and replace'? In other words, I want to replace every occurrence of 'foo' with 'bar' in all files in this directory and its ...
8
votes
4answers
33k 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 is getting send/received from my application in KB or MB format. The reason is i am writing ...
19
votes
4answers
21k views

I want to change DPI with ImageMagick without changing the actual byte-size of the image data

In GIMP there is a very simple way to do what I want. I only have the German dialog installed but I’ll try to translate it. I’m talking about going to Picture -> PrintingSize and then adjusting the ...
18
votes
6answers
20k views

In bash, how to sort strings with numbers in them?

If I have these files in a directory cwcch10.pdf cwcch11.pdf cwcch12.pdf cwcch13.pdf cwcch14.pdf cwcch15.pdf cwcch16.pdf cwcch17.pdf cwcch18.pdf cwcch1.pdf cwcch2.pdf cwcch3.pdf cwcch4.pdf cwcch5.pdf ...
26
votes
4answers
72k views

How to gzip multiple files into one gz file?

I have 100 files: cvd1.txt cvd2.txt ... cvd100.txt How to gzip 100 files into one .gz file so that after I gunzip it, I should have cvd1.txt, cvd2.txt ... cvd100.txt separately? Thanks for your ...
32
votes
4answers
2k views

Difference between “a=b” and “export a=b” in bash

What's the difference between: a=b and export a=b In bash? I understand that they both define environment variables, but I don't fully understand the difference.
16
votes
7answers
8k 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 ...
15
votes
4answers
4k views

Equivalent/Alternatives for Alt+Dot in Mac

One thing i miss from the Linux shell is the Alt+Dot shortcut. What it does is insert the last argument of the previous command. It appears to be a trivial technique, but it's really useful. i.e. if ...
15
votes
5answers
13k 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 | ...
13
votes
4answers
10k 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 ...
23
votes
2answers
8k 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 ...
17
votes
6answers
29k 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
14
votes
1answer
2k views

Why do we have login, non-login, interactive, and non-interactive bash shells?

So the bash man pages explain what login and interactive shells are: A login shell is one whose first character of argument zero is a -, or one started with the --login option. An ...
11
votes
4answers
24k views

How can I pipe output of ffmpeg to ffplay?

How can I pipe the output of ffmpeg to ffplay? At the moment I use a workaround in bash : mkfifo spam (ffplay spam 2> /dev/null &) ; capture /dev/stdout | ffmpeg -i - spam
10
votes
1answer
7k views

How can I see a timestamp for when a command was executed using history?

I'd like to check at what time/date a command in bash history was executed. Is this possible?
9
votes
2answers
7k views

Finding all symbolic and hard links to a file on UNIX

If I have a specific file in a UNIX filesystem, is there a way to use bash to find all links to that file, both symbolic and hard? If I need different commands for each, what are they?
5
votes
2answers
797 views

Access Finder's “Open With” menu from the commandline (for tab completion)

On Mac OS X, I know one can open a file from the commandline with its default application with open, and with other applications with open -a <application name>. Thus, open movie.avi open -a ...
3
votes
5answers
5k 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 ...
22
votes
2answers
15k views

Measure script execution time

In bash shell, is there a simple way for me to monitor the time taken to run a script and output the time taken?
17
votes
2answers
13k 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 ...
11
votes
4answers
3k views

Bash history loss

I like to keep a lot of history, so I have histappend set in my .bashrc. Most of the time everything works fine, with history built up from many shells appending. However, every once and a while, I'll ...
9
votes
4answers
3k 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. ...
8
votes
2answers
531 views

Can I keep . and .. out of .* expansion?

I often find it annoying (or worse) when I type command .* in bash and the command applies to the parent directory and current directory. Is there some shell option or other configuration I can ...
14
votes
1answer
3k views

Make bash's tab-completion case-insensitive [duplicate]

Possible Duplicate: Case insensitive tab completion in Bash Is there any way to make the tab-completion in bash case-insensitive? For instance, if I have a file called Hello.txt and try to ...
14
votes
6answers
8k 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 ...
13
votes
8answers
46k views

bash: how to pass command line arguments containing special characters

I've written myself a linux program program that needs a regular expression as input. I want to call the program in the bash shell and pass that regular expression as a command line argument to the ...
12
votes
3answers
14k views

Bash Man Page: kill <pid> vs kill -9 <pid>

My man page does not document the difference between kill <pid> and kill -9 <pid> Since these do different things why is the -9 not documented in the kill manpage? I thought maybe ...
10
votes
6answers
5k 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 ...
9
votes
4answers
6k views

Custom bash tab completion

I have my custom console utility cooltool with list of options fooOption barOption What should I do to able bash autocomplete the options by pressing the tab key? I mean the user typed $ ...
9
votes
2answers
4k views

How to write to KDE's OSD or notification from console?

How can I write, from a bash script, to KDE's OSD or notification area? I am using KDE 4.5, and basically what I want is my script to report some stuff when it is run. Since I run the script by a ...
8
votes
8answers
23k 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: ...
5
votes
4answers
3k views

Show Duplicate Files [duplicate]

Possible Duplicate: Find duplicate files on Mac OS X Hi all I am trying to sort out duplicate folders in a folder which again has an awful lot of subfolders on a Mac OS X system. I want to ...
4
votes
4answers
4k views

How do I only display the base dir in my Ubuntu Terminal?

In Ubuntu 10.04 Terminal when I traverse into some long directory structure the entire path gets displayed, this leads to lot of space wastage on my terminal, where the cursor comes way over to the ...
0
votes
2answers
4k views

Bash processes - reattach process started in background

Is there a way to reattach to a specific terminal a process that was started from terminal with &? For instance, I started Kate by: kate & and now I want to reattach the process to a given ...