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

learn more… | top users | synonyms

0
votes
1answer
134 views

Making an alias for `tree -P '*name*'`

I'm creating an alias for the following command with the tree program: tree -P '*name*' This works exactly as I want. But when I create an alias for this command, the command behaves differently: ...
51
votes
5answers
2k views

How to “unextract” a zip file?

I extracted a zip file into a non-empty folder. The zip file has lots of files and a deep hierarchy, that merged with the existing tree of the target directory. How can I remove the files and ...
0
votes
1answer
29 views

how to edit aliases

I just started looking into aliases and I already created a couple aliases before reading how to write alias commands into files so you can easily edit them. If you just directly run the command ...
2
votes
1answer
94 views

bash function to write comments to a newly created file

Please see the following function — function touchm(){ date=$(date +'%Y-%m-%d %H:%M:%S') read Y M D h m s <<< ${date//[-: ]/ } file_name=$1 if [[ $file_name =~ ...
0
votes
0answers
32 views

How to Create A Command Line Command [duplicate]

So I recently installed Cassandra on OSX. I have it in my /usr/bin/ file. In order to start cassandra though I have to be in the /usr/bin/apache-cassandra-1.2.1/ directory (or specify the path). How ...
2
votes
2answers
2k views

What method executes on bash exit via CTRL-D?

Similar to a post about cd, I've overwritten exit to do the following: function exit() { $HOME/script.sh && builtin exit "$@"; } Though this works as expected when exit is called directly, ...
1
vote
3answers
1k views

Why doesn't piping grep output into xargs work with color?

I have a strange issue. My grep has colored output, and if I do something like this: grep -lr '80' /etc/apache2/sites-available/|xargs ls I got: ls: cannot access ...
4
votes
2answers
1k views

Vim execute process in background

I would like to run a process in the background in Vim on Mac OS X (or Unix in general). I would hope and expect the following, or some variant, to accomplish this: execute "!my_command &" or ...
0
votes
1answer
145 views

Ubuntu Custom ls Listings With Strings

I am trying to add certain strings to file types in the bash "ls" command. For example, "ls"-ing a directory with an .exe inside, would appear as <file name>* E.g. helloworld* Instead of ...
0
votes
1answer
139 views

Zsh alternative to bash's quick assignment and inheritance trick

There's a trick available in bash allowing you to set environment variable for child process and run it in single line, retaining original values of variable in the shell. For example, in order to set ...
0
votes
3answers
247 views

HTTP Packet inspection scripting

I have a HTTP application running on a server. I cannot modify the application, but I would like to trigger an event when a specific POST request is sent to the application. I would like to run a ...
1
vote
2answers
217 views

passwd pauses after bad password has been entered

Say you type in passwd and you enter in the wrong password. There's a noticeable delay between when it tells you that the password was bad and when you enter it. Any ideas as to why? Seems kinda ...
0
votes
1answer
260 views

Make Bash script with “chattr” work under OS X

Can anyone help me adapt this script to Mac OS X? USR=$(logname) f=`find /home/$USR/documents -name "*.doc" -o -name "*.xsl" -o -name "*.pdf"` for file in $f do chattr +i $f done My goal is to ...
1
vote
1answer
430 views

Can't assign a keyboard shortcut to a certain bash commands using xfce-keyboard-settings in Linux Mint

Can't assign a keyboard shortcut to certain bash commands using xfce-keyboard-settings in Linux Mint I'm using Linux Mint 14 Nadia I use xfce-keyboard-settings to assign keyboard shortcuts to ...
2
votes
3answers
8k views

Bash: Find and replace text strings

I figured this would be easy, but I'm overlooking something simple: I have a text file called test. It contains, for example, the string Alfred Hitchcock. I want to replace this with Alfred\ ...
0
votes
1answer
129 views

How can I check the contents of folders for certain files?

How would I go about writing a script to loop through every folder on a hard drive, find any video files, extract them to the root of the hard drive, and then delete everything else?
3
votes
1answer
1k views

How can I determine the last line of “while read line”?

How can I determine the last line of "while read line"? for example: while read line; do if [ "$line" = "last line" ]; then echo "this line is the last one ($line);" ...
0
votes
2answers
217 views

How can I prevent bash from executing 'rm' when ' * ' is one of the arguments?

I wish to insure myself from accidentally using rm [argument_i] * [argument_j] i.e. it should always refuse to execute the command, when the asterisk character is separated by white space on both ...
1
vote
1answer
134 views

How does the boot sector know what to load?

I am just getting started with bootable removable media (DVD, USB, etc) but I have no idea how to make my own. I've reading up on how to make bootable ISOs and this post describes a process by which ...
3
votes
1answer
4k views

diff directories, excluding one folder inside

I think I have two directories with the same content, but I want to check it. Also, I want to exclude a folder that is inside both directories. How can I do it?
3
votes
2answers
243 views

Is a subshell executed with a here string?

I'm trying to better organise a bash script as part of a re-write/re-organisation and am wondering what "best practice" is in the following situation: ymd=`echo "${NOEXT}" | egrep -o -m 1 ...
2
votes
1answer
90 views

Where are bash variables defined?

How can I find the file that a bash variable is defined there? Assume the echo command shows $ echo $DB_ROOT /home/mahmood/db-4.0 Now, how can I find the file that this variable has been defined ...
3
votes
1answer
2k views

Bash script to wait for Virtualbox VM shutdown?

Virtualbox has the ability to issue a command to a running vm: vboxmanage controlvm NameOfRunningVM acpipowerbutton However this command returns immediately which results in non-graceful shutdown ...
0
votes
1answer
416 views

Bash: Copy logs to other file and remove copied log

I am using linux and doing some bash scripting. I have a log file which is making logs of all the events/changes our in particular directory. I need to copy these logs to some other file so that I can ...
13
votes
2answers
2k views

Tmux current pane border not obvious

I'm struggling to tell which pane is the current one in tmux if there are only two. The border only seems to highlight the adjoining edge which makes it impossible to tell. Here's a Gif to highlight ...
1
vote
3answers
79 views

A better way to extract lots of files from zip archive in bash

I have a zip archive with lots of files and a plaintext file with list of files (~10000 items), that I need to extract from that archive using bash. What is the best way to perform that operation? ...
1
vote
2answers
112 views

Using command substitution to execute multiple commands

What I am trying to do in bash is write a script, foo, that when I run $(foo), it changes the directory and runs a script using source. The contents of foo: echo cd bar echo "&&" echo source ...
1
vote
2answers
62 views

Open remote git repository from command line

I'm using git on a Mac, and I'd like to know if there's a command to open the remote repository (origin) in a browser from the terminal.
2
votes
1answer
346 views

bash/readline for “move forward by whitespace-delimited word?”

In bash/readline, if you want to navigate through a command, often you have things like: cat /home/foo/bar.txt /home/bar/baz.txt If my cursor is at the end of the line (^e), and I want to move back ...
0
votes
1answer
58 views

gnu screen command that stops running then switching to another tab

I use GNU screen to keep a bunch of tabs open in my terminal session, and I would like to have a bash command, watch -n 1 ps aux | grep something, that runs when I am looking at that screen tab, but ...
0
votes
1answer
864 views

Creating a movie from pdf images

I have a bunch of pdf files, from which I want to produce a movie. I'm using sips (on Mac OS) to convert the pdfs to .png, and then produce the movie with ffmpeg. So far, I'm doing this: for i in ...
0
votes
1answer
2k views

Executing scripts with bash from vim

I'm trying to get vim to execute the script I'm editing with a key mapping, say ctrl + x, so I used this in vimrc :map <C-x> :!exec_file %<CR> To pass the file name to a script I wrote ...
6
votes
4answers
5k views

How do I start in bash when ssh'ing into my server?

I have a hosted Debian server. When I log in via ssh, I'm greeted with a sh environment. How do I change it so I start in a bash environment?
2
votes
3answers
376 views

How to start bash and immediately “type” command into it?

I want bash to first execute a command, but after the command finishes (or Ctrl+C'ed) go into interactive mode (preferrably with the command in history, available for up). How to attain it in easiest ...
1
vote
1answer
329 views

Alias defined in .bashrc not working after pipe

I'm stuck with the following problem. I've defined an alias in .bashrc (and .bash_profile): alias echo2="echo" This works well: $ echo2 "test" test However, if I try to use it after a redirect, ...
3
votes
1answer
977 views

A way to capture error output from ffmpeg/avconv in a bash script

I am trying to batch convert a bunch of files and i am doing an simple listing of the converted files to a text document so that i can stop the script and continue from approximately were i started. ...
1
vote
2answers
321 views

Extract a number from a column with Bash

I need to extract only bash script_c.sh process' number, from this output: 11545 pts/3 S+ 0:00 bash script_c.sh 11625 pts/3 S+ 0:00 grep script_c.sh in this case it will be: 11545 I ...
-1
votes
2answers
3k views

How to check if internet connection is available via Terminal

I'm trying to write a Bash script that is aware of internet connectivity. How can I achieve that? For example: if (something that checks internet connection);then curl -o new someurl else exit 1
3
votes
3answers
464 views

Breaking a file down of strings, into separate files each based on the first letter. BASH

Alright, so I have a file full of thousands of strings. Each one on it's own line. I want to make a script that will allow me to take this file, call it list.txt, and take the items from each line, ...
1
vote
2answers
444 views

What's the difference between /proc and /proc/ (with a trailing slash)?

I try using tar to backup my files. With --exclude=/proc/, the archive contains files under /proc, and --exclude=/proc does not. What causes the difference? P.S. The shell I use is Bash.
1
vote
3answers
64 views

Is it possible to retrive in one file bash's history commands?

I have a lot a commands that I want to run again, but there are a lot of them, and going up to them with the up arrow key is too long. Is it possible to get it in a cat/tail command and pipe it to a ...
0
votes
1answer
326 views

Combining multiple data files with header while also adding a data column

I have multiple tab delimited data files that are separated by month in the format jan06.txt, feb06.txt, ..., dec07.txt. Within each file, it looks something like: Header1 Header2 Header3 ... Data1 ...
0
votes
2answers
2k views

Find pid of a certain ssh instance

There can be more than one instance of ssh running: $ ps aux | grep ssh cpn 6098 0.0 0.0 58196 2032 ? S 10:08 0:01 ssh cz -nNCTR 5433:localhost4:5432 root 6313 0.0 0.0 ...
1
vote
1answer
100 views

bg command seems not to behave

Could anyone shed some light on this matter ? [root@test1 work]# tsung -f tsung_catalin_filetrans.xml start & [2] 6284 [root@test1 work]# Starting Tsung "Log directory is: ...
1
vote
2answers
2k views

Easy way to get mac address of network card

I use a lot of scripts that involve the Mac addresses of my network cards. Is there a file I can read or a command that I can use to JUST get the Mac address? I don't want any headers or anything, ...
4
votes
1answer
748 views

sudo -E not passing all variables

Reading the man pages I expected sudo -E to pass all environment variables to the subshell, but I am not getting the expected results. As expected, awesome: $ export ...
1
vote
4answers
883 views

Unable to make bash default shell in freebsd

I wanted to change my default shell to bash in freebsd. I tried the following: 1.chsh -s /bin/bash (or /usr/local/bin/bash) <my_username> I get this error after entering the password: chsh: ...
2
votes
2answers
599 views

Conditional spaces in a regular expression?

Using grep, how would I do this in one command line? I have this so far grep '\$[0-9][0-9]\.[0-9][0-9]' money.txt with various strings in the text file, but I'm having issues satisfying some of my ...
1
vote
1answer
213 views

Bash colorless on Plesk machine (debian)

Somehow from one day to the other, on my plesk server, the bash/terminal was colorless. A friend of mine managed to get it coming back to life (color, that is) by making some changes to the bash ...
2
votes
3answers
2k views

What's a reliable technique for killing background processes on script termination?

I use shell scripts to react to system events and update status displays in my window manager. For example, one script determines the current wifi status by listenining to multiple sources: ...