shell

What should a longtime Windows user know when starting to use Linux?

We've finally moved our websites to a decent host, and for the first time we have Shell Access. I know very little about using Linux, I can navigate through the file system, read files with Vim and I'm aware of the man command, and I have been able to work out solutions to problems as they show up (eventually), but I know I'm unaware of...

Linux shell equivalent on IIS

As a LAMP developer considering moving to a .Net IIS platform, one of my concerns is the loss of productivity due to lack of shell... Has anyone else had this experience? Is there possibly a Linux shell equivalent for Windows? ...

Shell scripting input redirection oddities

Can anyone explain this behavior? Running: #!/bin/shecho "hello world" | read var1 var2echo $var1echo $var2 results in nothing being ouput, while: #!/bin/shecho "hello world" > test.fileread var1 var2 < test.fileecho $var1echo $var2 produces the expected output: helloworld Shouldn't the pipe do in one step what the redirection to t...

Better windows command line shells

Is there a better windows command line shell other than cmd which has better copy paste between Windows' windows and console windows? ...

Date arithmetic in Unix shell scripts

I need to do date arithmetic in Unix shell scripts that I use to control the execution of third party programs. I'm using a function to increment a day and another to decrement: IncrementaDia(){echo $1 | awk 'BEGIN { diasDelMes[1] = 31 diasDelMes[2] = 28 diasDelMes[3] = 31 diasDelMes[4] = 30 diasDel...

How to resolve symbolic links in a shell script

Given an absolute or relative path (in a Unix-like system), I would like to determine the full path of the target after resolving any intermediate symlinks. Bonus points for also resolving ~username notation at the same time. If the target is a directory, it might be possible to chdir() into the directory and then call getcwd(), but I r...

How do you use PowerShell?

Windows PowerShell came out last year and got great reviews from many .net bloggers (Hanselman comes to mind). It seemed to be touted as a great new utility that somehow made everything that you would ever do on the command line easier, and integrated with .Net. However, the more I read about it, the more it seems to be a tool that is gr...

Programatically select multiple files in windows explorer

I can display and select a single file in windows explorer like this: explorer.exe /select, "c:\path\to\file.txt" However, I can't work out how to select more than one file. None of the permutations of select I've tried work. Help! Note: I looked at these pages for docs, neither helped. http://support.microsoft.com/kb/314853 http:/...

Opening Explorer shell with admin priveleges on XP (with IE7 installed)

I used to demote my user account so that it had no admin priveleges and used a 'sudo-like' trick where you create a shortcut to IE6 and enabled the 'Run with different credentials' option to open a shell window as local admin so I could install, uninstall things etc. When I upgraded to IE7 this stopped working - IE7 launches Windows Exp...

Why shouldn't I "bet the future of the company" on shell scripts?

I was looking at http://tldp.org/LDP/abs/html/why-shell.html and was struck by: When not to use shell scripts ... Mission-critical applications upon which you are betting the future of the company Why not? ...

Why doesn't **find** find anything?

I'm looking for shell scripts files installed on my system, but find doesn't work: $ find /usr -name *.sh But I know there are a ton of scripts out there. For instance: $ ls /usr/local/lib/*.sh /usr/local/lib/tclConfig.sh /usr/local/lib/tkConfig.sh Why doesn't find work? ...

Is there a Unix utility to prepend timestamps to lines of text?

I ended up writing a quick little script for this in Python, but I was wondering if there was a utility you could feed text into which would prepend each line with some text -- in my specific case, a timestamp. Ideally, the use would be something like: $ cat somefile.txt | prepend-timestamp (Before you answer sed, I tried this: $ ca...

Combining values from different files into one CSV file

I have a couple of files containing a value in each line EDIT: Oops... I figured out the answer to this question while in the midst of writing the post and didn't realize I had posted it by mistake in its incomplete state. I was trying to do: paste -d ',' file1 file2 file 3 file 4 > file5.csv and was getting a weird output. I later ...

Is there any way to prevent find from digging down recursively into subdirectories?

When I do: $ find / It searches the entire system. How do I prevent that? (This question comes from an "answer" to another question.) ...

Unix shell file copy flattening folder structure

On the UNIX bash shell (specifically Mac OS X Leopard) what would be the simplest way to copy every file having a specific extension from a folder hierarchy (including subdirectories) to the same destination folder (without subfolders)? Obviously there is the problem of having duplicates in the source hierarchy. I wouldn't mind if they ...

Parsing XML using unix terminal

Sometimes I need to quickly extract some arbitrary data from XML files to put into a CSV format. What's your best practices for doing this in the Unix terminal? I would love some code examples, so for instance how can I get the following problem solved? Example XML input: <root> <myel name="Foo" /> <myel name="Bar" /> </root> My desi...

How do you use ssh in a shell script?

When I try to use an ssh command in a shell script, the command just sits there. Do you have an example of how to use ssh in a shell script? ...

How to redirect all stderr in bash?

Hey! I'm looking for a way to redirect all the stderr streams in interactive bash (ideally to its calling parent process). I don't want to redirect stderr stream from each individual command, which I could do by appending 2> a_file to each command. By default, these stderr streams are redirected to the stdout of an interactive bash. I...

Where can I find a graphical command shell?

Terminals and shells are very powerful but can be complicated to learn, especially to get the best out of them. Does anyone know of a more GUI based command shell that helps a user or displays answers in a more friendly way? I'm aware of IPython, but even the syntax of that is somewhat convoluted, although it's a step in the right direct...

How to escape os.system() calls in Python?

When using os.system() it's often necessary to escape filenames and other arguments passed as parameters to commands. How can I do this? Preferably something that would work on multiple operating systems/shells but in particular for bash. I'm currently doing the following, but am sure there must be a library function for this, or at l...