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

learn more… | top users | synonyms

23
votes
2answers
37k views

Bash: Display each sub-directory size in a list format using 1 line command?

I want to get a list of the directories and their sizes in a list format like how you get when you do a ls -l. The thing is that is there a one line command that can do this? I see others have long ...
1
vote
1answer
148 views

put in bash or zsh history absolute path to files I working on

I have found that in bash i frequently use something like that: vim ./somefile1 less less ./dir1/dir2/somefile2 cp some_other_relative_path_to_file and so on After that when I trying to find a ...
1
vote
2answers
418 views

How to display the size in human readable format in the find command

I am trying to display the filze size in human readable format in following find command find $BASE_DIR/ -user $USER -size +$LOWERSIZELIMIT -mtime +$MY_MTIME -type f -printf "%s %p\n" 2> ...
4
votes
1answer
166 views

Color in Bash Prompt messing up the prompt

In my bashrc file I have my prompt set as follows: TC_GRE="^[[0;32;40m" TC_RESET="^[[0m" ...
0
votes
1answer
155 views

gzip many files one by one

I have 100 files, n1.txt, n2.txt,… and I want to gzip each of them, but not in one file – finally I'd like to have 100 n*.txt.gz files. How can I do that in Linux with Bash?
2
votes
2answers
107 views

Run Total commander from bash on windows

I am trying to setup alias/function to call Total Commander from bash (MINGW) on windows. So far all my attempts failed, the closes function tc() { dir="$1" if [ "$dir" == "" ]; then dir="." ...
0
votes
1answer
195 views

How do I run a shell script with export command in crontab?

I have a shell script that exports values of variables when executed. The same values will be used in another script. #!/bin/sh export I="10" echo $I I will be using root access for cron. I ...
1
vote
1answer
179 views

How to conditionally send an email in crontab

I am using the following function to find large files (> 40MBytes) for various linux users in my team. It is possible that some of them may not have files larger then 40MBytes. The output of $DUMPFILE ...
0
votes
1answer
516 views

csh -> bash, autostart .bashrc PCBSD (FREEBSD)

Hey Im stucked with this problem... Im using PCBSD (freebsd) which has default csh shell, now I wanted to use bash as a default so I made > chsh -s /bin/bash milo now i have in passwd > ...
1
vote
1answer
131 views

Change mac terminal settings from the command line

I can change the appearance of Terminal by typing Cmdi and picking from the list of saved settings. Is it also possible to do this directly from the command line? I would like to write a bash script ...
2
votes
2answers
2k views

bash home/end/delete key inserting tilde, or if preceded by escape key, [1~ [3~

bash home/end/delete key inserting tilde, or if preceded by escape key, [1~ say I type echo hellp, move cursor to hel|lp and type delete, and bam, i got ~tilde say I type echo hellp, move cursor to ...
2
votes
1answer
382 views

Execute git pre-commit hook only if files in certain directory modified

I am trying to create a bash script for a git pre-commit hook. Whenever a commit is made, I want to check if files in a certain directory are part of the staged files and if so, run a command (Grunt ...
0
votes
1answer
186 views

Virtualbox command line

How do I start Virtualbox from the command line and start a Ruby script on the guest and after the script is done close the guest? What could be easiest way to do this?
0
votes
2answers
186 views

bash --norc failed when I want my test script with clean output

I want my test script could be run without initial startup scripts. I found the option "--norc" can not work. The bash version is 4.2.0(2) my ~/.bashrc contains echo "in .bashrc" I want to bash ...
0
votes
3answers
2k views

“/usr/bin/env bash” is not found when running from a cron script

I have this in my crontab: PATH=/usr/bin:/usr/local/bin:$PATH */1 * * * * /usr/bin/env bash > ~/cron.log 2>&1 The ouput in cron.log is the following: /usr/bin/env bash: No such file or ...
2
votes
1answer
74 views

Trying to create bash function which collects and quotes all arguments, but it doesn't work if args contain brackets or single quotes

I saw the following shortcut for "git commit" suggested somewhere: function gc { git commit -m "$*" } This is supposed to allow you to write the commit message inline in the shell, without quotes ...
0
votes
2answers
6k views

nohup output redirection to a different file

I use nohup quite often for important long running processes under linux/bash, so much so that nohup time my command with arguments && mv nohup.out my.log is almost an idiom for me. The ...
2
votes
1answer
307 views

bash and multiline PS1

\n in PS1 works fine, but when you try to type a command which takes more than one line, you type second line over the first and when you want to edit the part of such command that normally should be ...
1
vote
1answer
371 views

How can I get bash-like job control in zsh?

I want to configure zsh so that its job control behaves more like (I think) bash does by default. In particular: When I start a background job, it is by default owned by the shell and can be ...
2
votes
1answer
327 views

Bash script: “[[: not found”

This is my code: #!/bin/bash if [[ -d ~/viwiki ]]; then cd ~/viwiki else mkdir ~/viwiki cd ~/viwiki fi if ! [[ -d ./log ]]; then mkdir log mkdir log/log mkdir "log/wget" elif ! [[ -d ./log/log ...
0
votes
1answer
120 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
27 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
88 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
955 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
134 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
132 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
218 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
201 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
196 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
386 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
6k 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
115 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
1answer
186 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
133 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
3k 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
210 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
89 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
364 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
76 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
105 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
61 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
298 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 ...