You searched for articles tagged with Shell.

[ #235 ] Converting ssh2 public keys to openssh Permalink

SSH, Shell Added about three weeks ago

Sometimes you will have to convert a public key generated by PuttyGen for use on *nix. Just use ssh-keygen:

ssh-keygen -i -f sshv2.pub > id_dsa.pub



[ #229 ] Using shell variables in AWK Permalink

Shell Added about a month ago and last edited about a month ago

If you have a shell variable that has been exported (i.e. an environment variable), you can access it in awk like so:

awk 'BEGIN { print ENVIRON["HOME"] }'

However, say you have a non-exported variable like so:

X=wassup

... and you want to use your X variable in an awk script, you need to do some fancy quoting like so:

awk 'BEGIN { print "'$X'" }'

Also, here is an alternative that doesn't involve crazy quoting:

awk -v X=$X 'BEGIN { print X }'



[ #228 ] Linux - Too many open files Permalink

Linux, Shell Added about a month ago

If you get the error:

Too many open files

Then your file-max limit is probably set too low. Edit /etc/sysctl.conf to ensure:

fs.file-max = 102400

... (or whatever larger number you want) and then run:

# sysctl -p

to apply the changes.




[ #220 ] Force detach a screen session Permalink

Shell Added about two months ago

If you accidentally left your screen session attached at work and you want to force detach then reattach at home, do this:

$ screen -D -r



[ #219 ] Modify sudo's use of environment variables Permalink

Shell Added about two months ago and last edited about two months ago

When I:

$ sudo -s

... I want to have the same environment variables set/unset as the user I currently am.

To achieve this, add this line to /etc/sudoers (using the visudo command please!) like so:

Defaults    !env_reset

... and remove any env_keep stuff.

When I want to have the env vars set like root, I just:

$ sudo -i



[ #218 ] Install all Perl modules Permalink

Perl, Shell, apt Added about two months ago and last edited about two months ago

In Debian or Ubuntu you can install all apt provided Perl modules like so:

apt-cache search "\-perl" | grep -e '^lib' | awk '{ print $1 }' | xargs sudo apt-get install

If, before running that command, you just want to check what it would install, run this:

apt-cache search "\-perl" | grep -e '^lib' | awk '{ print $1 }'



[ #194 ] Questioning Unix (and Other) File Times Permalink

Shell, Linux Added less than a year ago and last edited less than a year ago

stat displays three times:

atime is fairly obvious, where do the others differ? This article tells us that mtime and ctime change when you alter the file's contents - but ctime alone changes when you alter the file's permissions or owner.

What about file creation time? Historically, Unix did not store file creation time.

How do I find the creation time of a file? You can't - it isn't stored anywhere.

Why doesn't old Unix store creation time too? The linked article suggests that creation time is a human concept not a system one - it raises this question: when does file creation time get set when file operations that completely remove, create links to, create copies of, or replace the file in question occur?

To explain that last paragraph with an example, consider these two files:

10:00PM $ echo "hi" > yourfile
10:05PM $ echo "hello" > yourfile

10:00PM $ echo "hi" > myfile
10:05PM $ rm myfile
10:05PM $ echo "hello" > myfile

The two sets of commands both initially create a file at 10:00PM, and at 10:05PM they are both in the same state - but one has been completely removed and re-added. When was it created? Some human interpretation is needed. (See the full email for other shell commands/programs that the poster is concerned as to the interpretation of.)

So does that mean creation time is meaningless and can not be measured? Nope.

More recently certain file systems have started storing file creation time. Consider the UFS2 under FreeBSD.

What about Mac OSX? Yep, the Finder knows about these three file times:

... and if you use stat you will find four values listed: atime, mtime, ctime and birthtime (creation time). Do a man 2 stat and look for the section on st_birthtime which does store the file 'creation time'... if it is available on the current filesystem!

If you are on Windows you will note that NTFS stores:

file times when applications create, access, and write to files.

... so ... I suppose that these filesystems etc have some rules for creation time that the Unix guys couldn't fathom? Let's try things out in the Finder:

% date && echo "hi" > yourfile
Sat  9 Jan 2010 00:39:15 EST
% # I check the Finder and it says creation time is: Today 12:39 AM
% # ... now i wait a minute ...
% date && echo "hello" > yourfile
Sat  9 Jan 2010 00:40:33 EST
% # I check the Finder and it says creation time is still: Today 12:39 AM
% # (but the modified time is 12:40)

% date && echo "hi" > myfile
Sat  9 Jan 2010 00:42:42 EST
% # I check the Finder and it says creation time is: Today 12:42 AM
% rm myfile
% date && echo "hello" > myfile
Sat  9 Jan 2010 00:43:56 EST
% # I check the Finder and it says creation time is: Today 12:43 AM

So, despite the file getting completely blatted both times with new content, only the time when it was rm'ed first caused the Finder to reset its creation time.

I think that makes sense. Consider what happens when you rm:

the directory entry is set to point at 0 instead of the inode it did point at, and the link count for the inode is decremented by one. If the link count has reached 0, and no process has the file open, then the inode itself is marked us unused, and the disk blocks that the file used are returned to the free list.

So, at this point, your data is still there until some other process needs disk blocks and these happen to get reused.

So the inode is still there... with the data... but the inode has been marked as being unused - this is when a file's creation time is lost.

What is my conclusion? I guess I don't know why the old Unix guys thought creation time was immeasurable - perhaps I'm misunderstanding their stance. But I do know that modern filesystems keep the creation time... perhaps I should do a full experiment on all these commands, comparing the file creation times over systems that do store them.




[ #191 ] rsync Permalink

Shell, rsync Added less than a year ago and last edited less than a year ago

When I have 90% common files on my laptop and desktop, and I want to sync the remaining files without accidentally deleting anything, I run these commands:

$ rsync -pogz -urave ssh ~/localdir remote.computer:~/
$ rsync -pogz -urave ssh remote.computer:~/localdir ~/

Then, as you are sure you are now up-to-date on both machines, you can start deleting files on one, and then sync those deletions to the other with:

$ rsync --delete -pogz -urave ssh ~/localdir remote.computer:~/

Note:

rsync doesn't seem very good at moved files. It will try to copy the whole file across again if it has moved into another dir... check out the fuzzy option... and also this thread for further info.




[ #190 ] Timezone Permalink

Shell, Linux Added less than a year ago

If you have a *nix box, you can set the timezone of the box by making /etc/localtime a symlink to the appropriate /usr/share/zoneinfo/ file.

But what if different people on your box have different timezones? Each user can manually set his own timezone simply by doing this:

$ export TZ=Australia/Hobart

... why not put that in your .bashrc?




[ #186 ] Colours in your PAGER Permalink

Perl, Shell Added less than a year ago

Seeing escape codes when you run perldoc?

Set your $PAGER environment variable up correctly:

export PAGER="less -R"



Older Posts ... (Nothing Newer)

Colophon

Django Python 960.gs Git Vim NetBSD Nginx

The Author

This is the blog of Brad Willis, a software engineer living in Brisbane.

Meta

Help
Latest entries

*BSD Agile Apache Apple apt Athletics Best-Practice Censorship Comedy Cool Crosswords Deployment Django English Exim Firefox Git Hardcore Health irssi Javascript Jira Languages Linux Makefile Mathematics Mobile Broadband Mutt MySQL NetBSD nginx Nokia OpenVZ OSX Perl Privacy Python Rant Requirements rsync Ruby Shell Slackware SQL SQLite SSH Standards Subversion Television Testing ThisBlog Vim VMWare (Fusion) VPN X zsh

Recent Entries

Checking for exceptions in doctests
Homer's Curling Speech
retry in Python
Vim Makefile tabs
Centos (or RH) IPTables
Converting ssh2 public keys to openssh
Vim comment hints
Context managers in Perl
Dish rotation
Git - fixing commit user
apt stuff
Using shell variables in AWK
Linux - Too many open files
Tell gvim to save and quit... remotely
Vim - automatically remove whitespace at EOL
Python - relative paths from within modules
TV Aspect Ratios
Git - Which commits are in your branch only?
Subversion setup cheat sheet
Force detach a screen session
Modify sudo's use of environment variables
Install all Perl modules
Mutt - delete old messages
OpenVZ VPS and swap space
fail2ban on NetBSD for ssh
NetBSD - Using sup
Python - testing for a sys.exit
Python Best Practice Link Dump
Python script names
Perl - Using an expensive module
Speed of git clone
Perl Modules with Custom Prefix
Perl: tr vs. s
Brilliant sysadmin Reference
Why is GRUB better than LILO?
Why is swap space important?
Perldoc Output
Git's Index
Jira Project Keys
Git GUI

Links

ChoppingBoard, DaveMisc, Project365, RageQuit