You searched for articles tagged with Shell.

Questioning Unix (and Other) File Times Permalink

Shell, Linux Added about two months ago and last edited about two months 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.




rsync Permalink

Shell, rsync Added 77 days ago!!! Woo! 77! and last edited about a month 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.




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?




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"



Learning zsh Permalink

zsh, Shell Added less than a year ago

My initial keybindings:

zsh $ bindkey -v # sets vi mode
zsh $ bindkey '^R' history-incremental-search-backward # like ctrl-R in bash

... and how cool is r?

zsh $ echo "hey dude"
hey dude
zsh $ r dude=guy
echo "hey guy"
hey guy

A sweet cheat-sheet is here.




Splitting Screen in Half Permalink

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

(We're talking about GNU Screen here.)

From this tutorial:

Splitting the screen in half horizontally

To split the screen in two, first create two screen sessions. Then press Ctrl+a S which will split the screen in half, giving you a session on the top that you're already using and a blank session at the bottom.

To move to the bottom half, press Ctrl+a, then the TAB key. This key combination will move the console cursor to the lower half. Once in the blank half, you have to set this bottom half of the screen to use one of the two earlier created sessions. To do this, press Ctrl+a, then " (shift+'). You will be presented with a list of available screen sessions, pick one using the arrow keys (be careful not to pick the one already at the top or you'll have a mirror console), and activate it by pressing Enter. Now type top and switch to the upper half by pressing again Ctrl+a TAB. You should now have a bash prompt waiting for commands in the upper half and system resources monitoring in the bottom half.

What a pain! Luckily I don't find myself needing to do this ;\




Screen Commands Permalink

Shell Added less than a year ago

Within a screen session you can issue any available command by pressing Ctrl-a, then typing :commandhere

For example, to change the current screen session name:

Ctrl-a
:sessionname project



Yesterday's Date Permalink

Shell, Linux Added less than a year ago

Using date you can do some nifty things with human-readable dates:

$ date +%Y%m%d
20090915
$ date -d '1 day ago' +%Y%m%d
20090914

This works with the date that comes with my Slackware distribution (and probably most/all Linux distributions) but not with my Mac OS X date.




Downloading mp3s with wget Permalink

Shell Added less than a year ago

Perhaps you read some blogs that link to mp3s and you'd like to grab all these files in one go. Firstly, populate a file called mp3.txt with a list of the blog URLs you have, separated by new lines. Then run wget like so:

$ wget -r -l1 -H -t1 -nd -N -np -A.mp3 -i mp3.txt

... and wait a while. I just downloaded about 50 mp3s from four different starting sites.




Examine Source of any Perl Module in your Path Permalink

Perl, Shell Added less than a year ago

Perldoc helps out:

$ less `perldoc -l strict`

... gives us a look at strict.pm.




Older Posts ... (Nothing Newer)

Colophon

Django Python 960.gs Git Vim NetBSD Nginx

The Author

The author is a software engineer living in Australia. He sux at guitar, loves camping, doesn't like cake, does like coffee and is a lazy home brewer.

Meta

Help
Latest entries

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

Recent Entries

Perldoc Output
Yum
Possum
Git's Index
Jira Project Keys
The Coffee Shop
Git GUI
It is more important...
Questioning Unix (and Other) File Times
The Frog King Photo
Rain Cloud Photo
rsync
Timezone
utf8 in your Perl
Theatre Ceiling Photo
Some problems are so complex...
Colours in your PAGER
zsh vared
zsh magic-equals and double-star
Funny Tweets

Links

ChoppingBoard, Project365, RageQuit

♥ Actors/Artists/Characters