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

learn more… | top users | synonyms

2
votes
1answer
126 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 ...
33
votes
6answers
41k 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 ...
101
votes
2answers
77k views

Go back to previous directory in shell

Is there a way to go back to previous directory we were in using bash,tcsh without using pushd/popd ? I'd like to type something like "back" and got returned to the previous directory I was in. Edit: ...
23
votes
4answers
30k views

How to pipe command output to other commands?

Example: ls | echo prints nothing ( a blank line, actually ). I'd expect it to print a list of files. ls | grep 'foo', on the other hand, works as expected ( prints files with 'foo' in their name ). ...
12
votes
3answers
25k 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
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?
29
votes
8answers
13k 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
3answers
2k 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?
16
votes
6answers
16k 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 ...
29
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.
5
votes
4answers
22k 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 ...
13
votes
4answers
3k 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 ...
21
votes
5answers
22k 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 ...
21
votes
4answers
57k 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
6answers
6k 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 ...
13
votes
5answers
11k 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 | ...
9
votes
1answer
6k 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?
21
votes
2answers
13k 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?
16
votes
2answers
6k 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 ...
11
votes
1answer
1k 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 ...
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
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?
8
votes
2answers
484 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
693 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
4k 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 ...
14
votes
6answers
21k 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
13
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 ...
12
votes
8answers
36k 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
11k 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
2answers
9k 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 ...
8
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 ...
7
votes
6answers
4k 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 ...
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 ...
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 ...
13
votes
5answers
6k 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 ...
10
votes
4answers
17k 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
8
votes
3answers
8k 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 ...
7
votes
2answers
3k 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
8answers
16k 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 ...
7
votes
4answers
4k 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 $ ...
7
votes
2answers
714 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.
3
votes
2answers
518 views

Practical (closer to the classical Linux one) way to use (automate) SUDO for CygWin

Being able to use sudo commands in CygWin is useful, and faster than opening an elevated shell: Luis@Kenobi /cygdrive/c/Users/Luis $ net user /add TestUser System error 5. Access denied. Luis@Kenobi ...
3
votes
2answers
775 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
2k 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 ...
9
votes
4answers
771 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 ...
9
votes
5answers
2k 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
1answer
3k 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 ...
6
votes
4answers
6k views

Unix command to list all directories larger than 10mb

Is this possible, and what would the command be?
5
votes
5answers
3k 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 ...
4
votes
1answer
3k views

Bash Find Files with zero size and delete files with different extensions

This command will find files of zero size: find . -size 0 A filename returned might be filename.001 I am looking for a one liner that will delete files found with this, plus any that have the ...