command line arguments

I am a new Python programming user. I am working on user-friendly command-line interfaces, and I want to pass input via the shell args as follows:

./myscript.py filename
./myscript.py in.file output.file
./myscript.py -i in.file -o output.file

How do I pass and parse command-line options and arguments using Python under Unix like operating systems?

{ 7 comments }

I‘m using a Mac OS X and combination of ssh-agent+ssh-add to adds RSA or DSA identities to the authentication agent. ssh-agent provides me a secure way of storing the private key. However, I’d like to expire identities added to the agent within half an hour. How do I set lifetime of identities added to the agent under Unix / Linux / BSD / Apple OS X operating systems?

{ 0 comments }

I am trying to use xargs command using shell pipes and not able to understand how to control and use command line arguments. For example I’d like to find out all *.c file located in 100s of sub-directories and move them to another directory called ~/old.src. How do I use command line args with xargs to achieve the same?

{ 50 comments }

Q. I’ve couple of large tarballs such as www.tar and images.tar. Is it possible to extract a single file or a list of files from a large tarball such as images.tar instead of extracting the entire tarball? How do I extract specific files under Linux / UNIX operating systems?

{ 20 comments }

Q. I’ve backup created using rsync command stored at /disk2/home/tom/ directory. Accidentally, I had deleted files from /home/tom directory. I’d like to restore all file names starting with alpha numeric characters from /disk2/home/tom/ to /home/tom. How do I restore selected files in a batch mode?

{ 0 comments }

I‘m writing a wrapper bash shell script that will get the last argument (a domain name) from the command line into a shell variable called $_domain. I need to find all other parameters before last parameter in $@ and stored in a shell variable called $allargs. So that I can pass them as follows:

/path/to/real/binary “$allargs” “$_domain”

How do I do this using bash shell under Unix like operating systems?

{ 0 comments }