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

learn more… | top users | synonyms

3
votes
3answers
317 views

Why doesn't this for loop work?

This is on Ubuntu 12.04 I'm trying to figure out how to get ffmpeg to do a batch conversion of FLACs to MP3, recursively. If I cd into a directory and use for f in *.flac; do ffmpeg -i "$f" -c:a ...
3
votes
1answer
887 views

How to delete readonly variable in bash?

$ mySite="superuser" $ readonly mySite $ unset mySite bash: unset: mySite: cannot unset: readonly variable How can we delete mySite, as it is a readonly variable?
3
votes
1answer
445 views

How to make bash alias invocation conditional on PWD?

I currently have this alias: alias cmakerel='cmake -DCMAKE_BUILD_TYPE=Release -Wno-dev ../../ && make -j4' Essentially, it will call cmake to do an out-of-source build from PWD. It works ...
3
votes
3answers
177 views

Determine whether a bash script was launched by icon click or from terminal

I have a script that I want to have a different behaviour depending on whether it was launched from the terminal or by (double) clicking the icon in the file manager. Can I do this?
3
votes
2answers
286 views

is it plausible that Ubuntu's wildcard * with tar is somehow failing to restore some files?

In this command line sequence I use a *.sh wildcard to restore some files. I got three hits. Knowing that there must be more, I typed in the whole name. For example: goFindRanges.sh. I was able to ...
3
votes
2answers
2k views

Multiple parameters to bash script

I need to check for user provided options in my bash script, but the options won't always be provided while calling the script. For example the possible options can be -dontbuild -donttest -dontupdate ...
3
votes
1answer
319 views

How to shorten the no of characters display for the current directory in the prompt

I am using bash, and in my .basrhrc: I have the following which defined how my prompt looks: PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\w\[\033[00m\]:\[\033[01;34m\]\!:\#\[\033[00m\]\$ ' ...
3
votes
5answers
2k views

How to run a bash script outside of a terminal?

Hey All, wrote this script to confuse my girlfriend when she is using my computer. The only trouble is that if the terminal gets closed the script stops to execute. It currently executes in the ...
2
votes
1answer
73 views

sed: Removing \r\r before \n in a very large file

I have a corrupted disk image file (about 27 GB) in which before all \n characters \r\r was inserted. I want to remove these \r\r before all \n. I tried with awk: awk '{ sub("\r\r$", ""); print }' ...
2
votes
4answers
550 views

Bash script, string not replaced correctly with escaped $ and & characters

I have created a shell script which takes a string as input. If the string contains $ or &, then I need to replace those characters with \$ and \&. I could done that with sed command. After ...
2
votes
3answers
118 views

I used mv ./*/* to flatten a directory on a ntfs filesystem, without add . to the end of the command, now all of my files are gone

How can I recover these files? I used: mv ./*/* when it was supposed to be mv ./*/* . Now all of my files are gone.
2
votes
3answers
317 views

Mail me when someone runs sudo

I have added the below lines to /etc/sudoers.d/my_sudoers Defaults mail_always Defaults mailto="email@domain.com" I get an email every time sudo is run How can i modify this so I only ...
2
votes
1answer
412 views

SSH not reading rc files

Once upon a time, an ssh invocation to host1 like ssh u@host1 command would read .bashrc before executing command. host2 is administered by the same people, and reads .bashrc! I don't administer ...
2
votes
1answer
2k views

Two parts: linux startup script to connect to bluetooth and cron to keep it connected

I have a mini bluetooth keyboard and a Raspberry Pi running a Debian-based distro. I know the MAC address of the keyboard but for this question, let's just use AA:BB:CC:DD:EE:FF. Right now I have to ...
2
votes
3answers
2k views

Can I use pipe output as a shell script argument?

Suppose I have a bash shell script called Myscript.sh that need on argument as input. But I want the content of the text file called text.txt to be that argument. I have tried this but it does not ...
2
votes
1answer
272 views

bash 4.2 autocd command default over directory

Just switched from tcsh to bash 4.2 on OSX, and autocd was what allowed me to do it. But it seems that by default if you type the name of a directory that also happens to be the name of an executable ...
2
votes
1answer
189 views

Why is sort -k5nr not a syntax error?

$ ls -l | sort -k 5 -n -r $ ls -l | sort -k5nr I find out these two command generate the same output. But I don't understand why I can combine 5 with n? Why not a syntax error? edit: $ ls -l | cut ...
2
votes
2answers
260 views

Alias that allows to edit ~/.bashrc and then “sources” it automatically - Why it doesn't work?

I use MacBook Air with OSX 10.7.2. I would like to create an alias that does the following: Opens TextMate with ~/.bashrc and allows me to edit it Once I close TextMate, "sources" ~/.bashrc (so if ...
2
votes
2answers
1k views

execute command after process terminates in different shell

I am running a command that's processing some data in one shell window (let's say it has pid 200). Unfortunately I forgot to add the & to run it in the background. I need to run some analysis ...
2
votes
3answers
614 views

Can I use a bash script as a Service in OS X without having to set it up trough automator?

How can I use a bash script as a Service in OS X without having to set it up trough automator? I'd basically like to write a bash script, save it in ~/Library/Services and then just have it show up ...
2
votes
3answers
3k views

How to close all background processes in unix?

I have something like: cd project && python manage.py runserver & cd utilities && ./coffee_auto_compiler.py And I want both of them to close on Ctrl-C (or some other command). ...
2
votes
3answers
1k views

how to stop bash from printing alerts?

When killing a process with kill -9 $PID &>/dev/null in a script, a message is still printed to the terminal after the next command terminates. How do you stop this behaviour? For example ...
2
votes
1answer
881 views

Ubuntu Login Screen Reloads

I am trying to login to my Ubuntu desktop after updating a bunch of packages and rebooting. I know I am authenticating successfully but what seems to happen is that after I enter my username and ...
1
vote
1answer
54 views

How can I get file names of opened by a process?

I want to list down all file names opened by init process. I know about /proc/PID/fd directory. But that gives file descriptors only. How can I get file names from list of file descriptors?
1
vote
1answer
78 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 ...
1
vote
2answers
196 views

bash script tells me when new computer joins LAN via smbclient

I'm thinking of creating a script that loops until it finds a new IP on the Network created by the router DHCP Server. I am thinking of using NMAP. nmap 192.168.0.1-254 However I am wondering how I ...
1
vote
1answer
375 views

Mac OSX Mavericks - ZSH can't 'source ~/.zshrc', too many open files

I can't source any changes to my .zshrc (or my .bash_profile for that matter), because I get this error when I try: /Users/ME/.zshrc:source:100: too many open files: /Users/ME/.zshrc I've tried ...
1
vote
0answers
60 views

How do I get `set show-all-if-ambiguous on` in my .inputrc to play nice with the Python interpreter?

I noticed that after I added the set show-all-if-ambiguous on line to my ~/.inputrc, whenever I pressed tab to indent a block, it would show me the bash Display all ... possibilities? (y or n) prompt, ...
1
vote
1answer
597 views

Ubuntu 10.04 using ssh without entering my password

I know questions like this have been asked before, and I have read them all (that I found). The problem I have is that we have an embedded linux device that we can log into for debug purposes by ...
1
vote
3answers
156 views

Linux - Protection from ourselves (Root)

I love Linux and everything she stands for; however, unfortunately I grew up with Windows. Thusly so I have learned very bad practices (such as NT Authority will protect me). I have several Linux ...
1
vote
1answer
255 views

Is there a way to limit maxdepth for ls -Rhal?

Is there a way to limit maxdepth in a ls -Rhal command? I am aware of find . -maxdepth, but I want to be able to get the file information that comes with ls -Rhal.
1
vote
1answer
1k views

Where to store bash scripts that all users may execute on Debian?

I have many bash scripts on my server, that all users may use. but it seems the location /usr/local/sbin is not the best place. I don't want to use the home directory of the users, cause ...
1
vote
4answers
76 views

Catalog of programs listed in bash

In bash (or any other shell), when you type "firefox" or another command, how does bash point it to its actual location (/usr/bin/firefox)? Also, where is the "catalog" for bash autocomplete?
1
vote
1answer
238 views

How do I print a tree with files in Bash for Windows?

I've found this command to show a tree of the directories under the current one: ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/' Which produces: ...
1
vote
1answer
330 views

How to use Pipe Viewer (pv) for measuring compression progress?

I've been trying to track the progress of the data in a pipe, specifically in a large init script for a minecraft server. How would I go about using pv to get an accurate readout of progress? I've ...
1
vote
1answer
1k views

Where can I find bash_profile / bashrc themes?

I've been searching for bash_profile / bashrc themes on google for awhile but I'm not finding any kind of aggregation for themes. Most of them I find are small snippets like: export ...
1
vote
3answers
257 views

Colored PS1 string

Clarification: I want __foo to be executed each time the PS1 string is presented in the terminal, not when the PS1 string is constructed (hence its being in quotes). __foo contains logic that examines ...
1
vote
1answer
885 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 ...
1
vote
2answers
1k views

How can I clear the contents of every file in a subdirectory without changing ownership / permissions?

I can find the list of files using something like: find /path/to/files -type f And I can clear the contents of a single file with any of: > filename echo -n > filename cat /dev/null > ...
1
vote
1answer
364 views

Simulate pgrep using plain grep

How can I do pgrep -U someUserName using just ps and grep? I.e. not count on pgrep being set in a system?
1
vote
3answers
168 views

Piping file to a command that doesn't implement piping

$ cat foo foo bar Now if I do: $ some_program foo It's working. But if I try: $ cat foo | some_program It's not working. I'm looking for a clean way to pipe input to some_program without ...
1
vote
2answers
2k views

how to keep line feed in result returned by bash command

let's say, I can rsh to machine XXX as user foo, then after executing: $result=$(rsh -l foo XXX "ls"); echo $result; I found that the line feed is removed in the result, and I can't see the result ...
1
vote
1answer
836 views

Command line: how to get instantaneous bandwidth on a port

I'm trying to get the instantaneous bandwidth usage of eth0, port 10001. I've looked into using lots of different tools, but most of these seem to have an ncurses type output which isn't suitable for ...
1
vote
2answers
295 views

how can I redefine the interrupt signal to Escape or Delete key?

I've googled for it but failed to found an answer. I would like to remap my interrupt signal key from ^C to or Delete, what would be the code for it? For example: stty intr "ESC code" And back: ...
1
vote
2answers
127 views

Attaching some code to session start and end in Linux

I'm trying to execute some code (let's call it login.java) when I log in and out of my linux machine. Is there any way to do this? I'm looking for perhaps a way to trigger the code? I've thought of ...
1
vote
1answer
155 views

How can I fix a problem with standard error screwing up the output of watch?

Specifically, I am trying to run the following command on both CentOS and Fedora14 (same issue with both) watch sudo jmap -heap 31945 However, there are a few lines of standard error that screw up ...
1
vote
3answers
6k views

How to kill all the processes that have dates older than today?

I issue the command ps -aux | grep tony. It displays the following output tony 10986 0.0 0.0 33532 464 ? S Feb01 0:00 vncconfig -iconic tony 10988 0.0 0.0 86012 512 ? ...
1
vote
3answers
1k views

How can I script making a backup of recently modified files in Bash?

I have written this backup script that looks in a file and copies recent files into a folder. #!/usr/bin/bash # the number of days to do the backup for. days=2; # the files to backup. ...
1
vote
2answers
683 views

Why doesn't my path update *now*?

I recently installed the newest Qt SDK and I went ahead and added it to my PATH inside of my ~/.bash_profile. I don't see the change. I can source ~/.bash_profile but then my path is twice as long, ...
0
votes
1answer
47 views

How to use Console2 with tmux

I am able to start tmux using the mintty terminal included with cygwin. However, when using Console2 (running on 64-bit windows 7 and using C:\cygwin64\bin\bash.exe as the shell), I get the following ...