shell

How to keep a file's format if you use the uniq command (in shell)?

In order to use the uniq command, you have to sort your file first. But in the file I have, the order of the information is important, thus how can I keep the original format of the file but still get rid of duplicate content? ...

What is the actual path of actions happening when I press a key on keyboard and it shows on a shell?

I am using a generic usb keyboard, Linux 2.6.27 with gnome desktop, gnome-terminal and bash shell. I am interested to know what happens in the software. How are special characters from my keyboard interpreted with some encoding to characters and where do the character pictures come from? ...

Append name of parent folders and subfolders to the names of the multiple files

I have folders and subfolders with 10K photos in them. Now I need to put all 10K files into one folder. I want to append the folder and subfolder name with the existing file name so that the file name becomes meaningful to me. I need help ...

A question about command "find"

find . \( -name "_*" -or -newer while2 \) -type f -print In the linux command above , why _* should be quoted ? ...

How to run a bash script from C++ program

Bash scripts are very useful and can save a lot of programming time. So how do you start a bash script in a C++ program? Also if you know how to make user become the super-user that would be nice also. Thanks! ...

Shell script - Two for loops and changing extension of file

Hello all, I have this Shell script and I've managed to muck it up and I was hoping I could be corrected and put on the right path and hopefully add a few things that I am not competent enough to do myself. I have put what I want do as comments in the Shell script below. #!/bin/bash #Get all files from dir "videos" and send to processL...

Why does this bash script require me to press enter to continue?

Hello all, I was kindly helped a few minutes ago by a user named Juliano and the script works fine but it just baffles me why it continues to work when I press enter, if I don't it just sits there untill I have to keep pressing enter. I thought that was the job of the for loop? #!/bin/bash TIMEFORMAT=%6R for file in /home/t...

BASH ^word^replacement^ on all matches?

To clarify, I am looking for a way to perform a global search and replace on the previous command used. ^word^replacement^ only seems to replace the first match. A quick check through a BASH history cheat sheet doesn't reveal anything. Is there some set option that is eluding me? Mainly curious... Thanks ...

How to add a menu item to the shell context menu of a file with a separated line?

I want to add an item to the context menu that appears when I click the right button of the mouse at a selected file in a directory. I don't know how to add it at a specified position of the menu, neither do I know how to separate it with lines above and below it. Do I need to modify the registry? If so, what should I do? ...

Environment variable within variable

I have an environment variable called $TEST which refers to a directory in my bash script I have a variable called $VARTEST which is = $TEST/dir/file now I want to grep the file specified by $VARTEST so I try to do grep somestring $VARTEST but it doesn't translate $TEST into it's directory I've tried different combinations of {}, "" an...

Why doesn't my 'find' work like I expect using -exec?

I'm trying to remove all the .svn directories from a working directory. I thought I would just use find and rm like this: find . -iname .svn -exec 'rm -rf {}' \; But the result is: find: rm -rf ./src/.svn: No such file or directory Obviously the file exists, or find wouldn't find it... What am I missing? ...

How can I follow and fully report on a chain of symlinks?

What are the best tools/programming-techniques for following a complicated nesting of symlinks and completely capturing and reporting on every symlink along the way, including those in the middle of a path (See below for more info). Here's a specific example. Consider the following output from a shell command ls -l /Library/Java/Home...

Find file in directory from command line

Noob question here, trying to wean myself off of IDEs. In editors/ides such as eclipse and textmate, there are shortcuts to quickly find a particular file in a project directory. Is there a similar tool to do full path completion on filenames within a directory (recursively), in bash or other shell? I have projects with alot of direc...

How do you resolve issues with named pipes?

I have a binary program* which takes the contents of a supplied file, processes it, and prints the result on the screen through stdout. For an automation script, I would like to use a named pipe to send data to this program and process the output myself. After trying to get the script to work I realized that there is an issue with the bi...

Bash: select a previous command that matches a pattern

I know about the bash history navigation with the Up and Down arrows. I would like a lazy way to select a previous command that matches some regex (that is shorter than the whole command, so it takes less time to be typed). Is it possible with bash? If not, do other shells have such a feature? ...

Selenium Java process called from c# not starting properly on CCNET build server

Hi, I'm setting up CCNET server to run Selenium tests. In my test code I use the following to start the Selenium RC server if its not running: var proc = new Process(); proc.StartInfo.WorkingDirectory = Path.Combine(Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName, @"..\..\..\..\..\lib\SeleniumRC\selenium-server-1....

What's the most compact version of "match everything but these strings" in the shell or regex?

Linux: I want to list all the files in a directory and within its subdirectories, except some strings. For that, I've been using a combination of find/grep/shell globbing. For instance, I want to list all files except those in the directories ./bin ./lib ./resources I understand this can be done as shown in this question and this othe...

Correct Bash and shell script variable capitalization

I run across many shell scripts with variables in all caps, and I've always thought that there is a severe misunderstanding with that. My understanding is that, by convention (and perhaps by necessity long ago), environment variables are in all-caps. But in modern scripting environments like Bash, I have always prefered the convention ...

Run CMD equivalent in OSX?

I'm using this code to make my Java program open a (visible) CMD window: try { String line; Process p = Runtime.getRuntime().exec("cmd /C start \"Render\" \"" + myPath + "\\punchRender.cmd\""); BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); ...

Write an executable .sh file with Java for OSX

So I am trying to write an .sh file that will be executable, this is how I'm currently writing it: Writer output = null; try { output = new BufferedWriter(new FileWriter(file2)); output.write(shellScriptContent); output.close(); } catch (IOException ex) { Logger.getLogger(PunchGUI.class.getName()).log(Level.SEVERE, null, ex); }...