Python Command Line Arguments Examples

in Categories , , last updated March 7, 2016

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:

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

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

OpenSSH: ssh-add / ssh-agent Command Set Maximum Lifetime In Seconds

in Categories , last updated April 6, 2012

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?

xargs: How To Control and Use Command Line Arguments

in Categories , , , , , , , , , , last updated September 2, 2010

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?

Tar Extract a Single File(s) From a Large Tarball

in Categories , , , , , , , , , , , , , last updated December 6, 2008

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?

Restore Selected Files From Secondary Backup Hard Disk

in Categories , , , last updated March 26, 2008

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?
Continue reading “Restore Selected Files From Secondary Backup Hard Disk”

Bash Get All Command Line Arguments Before Last Parameter In $@

in Categories last updated June 19, 2012

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?