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

learn more… | top users | synonyms

24
votes
8answers
8k 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.
23
votes
3answers
1k views

Have a file named ~ (tilde) in my home-directory (Linux)

I just noticed that I have a file called ~ in my ~-directory. $ ls -la ~ ... -rw-r----- 1 x1 x1 733962240 Mar 1 17:55 ~ ... Any idea how I can mv or rm it?
9
votes
3answers
18k 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 ? ...
14
votes
5answers
13k 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 ...
22
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.
18
votes
1answer
11k 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
4answers
41k 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 ...
13
votes
5answers
4k 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 ...
11
votes
4answers
2k 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 ...
10
votes
5answers
13k 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 ...
10
votes
4answers
2k 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
2answers
5k 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?
8
votes
1answer
5k 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?
8
votes
2answers
440 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 ...
5
votes
2answers
563 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 ...
12
votes
2answers
4k 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 ...
9
votes
1answer
2k 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 ...
6
votes
2answers
3k 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 ...
5
votes
4answers
2k 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 ...
3
votes
3answers
13k 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 ...
3
votes
4answers
3k 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 ...
15
votes
2answers
4k 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 ...
10
votes
4answers
4k 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 ...
9
votes
8answers
26k 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 ...
7
votes
2answers
2k views

Will a job put in background continue running after an SSH session is closed?

I have an AWS instance, and there I some tasks that I need to complete that will take some time. If I run these before commuting to/from work (e.g. wget <someStuff>), then commit it to ...
7
votes
2answers
625 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.
6
votes
8answers
10k views

Bash: is there a way to search for a particular string in a directory of files? [duplicate]

Possible Duplicate: Search for a text pattern in linux In bash, I was wondering if there were any commands that would let you know if a particular string you are looking for exists within ...
3
votes
2answers
629 views

How can I create keyboard shortcuts to run commands in a terminal?

I was wondering is it possible to bind say F5 to output sudo apt-get update so I can press one key to write this into the terminal?
20
votes
2answers
1k views

What is /usr/bin/[ and how do I use it?

I was looking at coreutils and found this as one of the files included as part of coreutils: /usr/bin/[. What is [ and what does it do? It is an executable. I just don't know what it does or how to ...
10
votes
3answers
2k 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
3answers
9k 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 ...
8
votes
4answers
592 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 ...
8
votes
5answers
1k views

How can I still see the 'man' text after I quit man?

I typically use tcsh or bash and often want to use 'man' to review a command's options. Currently when I quit man or ctrl-C, the man text disappears and I see the scrollback buffer that was there ...
6
votes
4answers
3k 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 $ ...
5
votes
3answers
3k views

How to automatically restart a linux background process if it fails?

I have a process which is executed by init.d script on the background. Eg: case "$1" in start) /bin/myprocess & stop) killall myprocess restart) killall ...
5
votes
1answer
2k views

Regex for “or” of multiple words in grep

[Computer]$ grep "foo|bar" filename I understand the above command should return each line in filename where there exits "foo" or "bar". The man pages confirms | as the Regex or symbol and the code ...
5
votes
5answers
2k views

Must I sftp to an intermediate server?

I can't sftp directly into a particular host. To move a file from my home machine to the host, I must sftp a file to an intermediate host; ssh into the intermediate host; and sftp the file to the ...
5
votes
4answers
5k views

Unix command to list all directories larger than 10mb

Is this possible, and what would the command be?
3
votes
1answer
2k views

How can I execute a script each time I log in and out from OS X?

What I want is to send a URL with variables to a server which will track when someone is present based on when they login and logout of their workstation. I've tried setting the LoginHook in ...
3
votes
3answers
2k views

How can I grep in source files for some text?

At the moment I'm using two commands, I'm sure there must be a better way... wim@wim-acer:~/ffmpeg$ find . -name "*.h" -print0 | xargs -0 grep -i invalid\ preset wim@wim-acer:~/ffmpeg$ find . -name ...
3
votes
2answers
837 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 ...
2
votes
2answers
314 views

How to invoke Windows' gvim in a Windows environment from within Cygwin?

When I give a gvim command in Cygwin, I want it to invoke the gvim I've installed in my Windows. I tried writing a function in my .bashrc called gvim that invokes the gvim.exe in my Program Files ...
2
votes
4answers
936 views

Keyboard shortcuts in Bash shell [closed]

I know some useful Bash shell shortcuts, and I am wondering if there are others. The ones I know: CTRL + W: delete until beginning of word CTRL + U: delete until beginning of line Up / Down: ...
1
vote
1answer
80 views

Bash - how do you make it so that the result of a command gets placed into a variable?

For instance, let's say I wish to type the command pwd. It gives me a really long path to the current directory I am in. What I would really like to do is make it so that I can go into a completely ...
0
votes
2answers
147 views

How to replace a command with the result of another in linux?

I want to create a command which uses the result of another like this: JNLP_FILE='find . -name viewerApplet.jnlp' cp ${JAR_FILE} ../../sign-jar/$PROFILE/ But I don't know how to execute the find ...
11
votes
4answers
4k views

Going to directory using bash variables doesn't work when directory names have spaces

Let's say I want to store the following command in a variable cd "/cygdrive/c/Program Files/" So I do this dir="cd \"/cygdrive/c/Program Files/\"" That should store the command to navigate to ...
8
votes
4answers
12k 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
6
votes
7answers
362 views

Can I shorten my directory commands in Ubuntu?

When working on a rails app I like to open all of my files through the command line like so CD my_app gedit app/views/user/show.HTML.erb Is there a way that I could shorten this so that I could ...
4
votes
3answers
894 views

cp -u is illegal on mac. What are the alternatives?

I have a MacbookPro Lion, and I have tried to archive my files that is tried to copy and overwrite if the source is newer than the destination. I tried the following command cp -u source destination ...
4
votes
4answers
9k views

bash process uses 90% CPU, comes back on computer restart

I’ve replaced the old HDD of my late 2008 unibody MacBook (8 GB of RAM, running OS X 10.7.4) with an OCZ Vertex 3 SSD. After doing this, I've installed Lion and restored my data from a Time Machine ...