You searched for articles tagged with Linux.

Perldoc Output Permalink

Perl, Linux Added less than a day ago

If, when you look at the documentation for a core-builtin, like so:

$ perldoc -f system

you get some funny characters in the output (long dashes, 'smart' quotes, etc) - and you wish to remove them (to make copy-pasting of code easier,) then simply:

$ perldoc -tf system

The -t flag avoids any fancy formatting and just outputs plain text.




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.




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?




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.




CTWM Config Permalink

Linux, X Added less than a year ago

I have been using CTWM as my window manager on my Debian VM for a while now, here is the config (.ctwmrc) file. Put it in your home directory and adjust your .xinitrc accordingly.

The setup I have uses 4 workspaces, you can't drag windows off the screen and it has a simple menu mainly for launching xterms in nice places. It is setup for the resolution 1280x800 (my macbook.)

NoGrabServer
NoTitleHighlight
NoIconManagers
DontMoveOff
RestartPreviousState
DecorateTransients
TitleButtonBorderWidth 1
NoHighlight
BorderWidth 2
TitleFont       "-*-helvetica-medium-r-*-*-11-*-*-*-*-*-*-*"
ResizeFont      "-*-helvetica-medium-r-*-*-11-*-*-*-*-*-*-*"
MenuFont        "-*-helvetica-medium-r-*-*-11-*-*-*-*-*-*-*"
IconFont        "-*-helvetica-medium-r-*-*-11-*-*-*-*-*-*-*"
IconManagerFont "-*-helvetica-medium-r-*-*-11-*-*-*-*-*-*-*"
ShowWorkSpaceManager
WorkSpaceManagerGeometry "360x18+458+780" 4
WMgrButtonShadowDepth 0
WMgrHorizButtonIndent 0
WMgrVertButtonIndent 0
BorderWidth 1 
NoTitle { "WorkSpaceManager" "xterm" }

WorkSpaces
{
    ""   {"#5de100" "white" "black" "black" "black"}
    ""   {"#1f1ab2" "white" "black" "black" "black"}
    ""   {"#ffc200" "white" "black" "black" "black"}
    ""   {"#e7003e" "white" "black" "black" "black"}
}


Color
{
    BorderColor         "#ffc201"
    DefaultBackground   "black"
    DefaultForeground   "black"
    TitleBackground     "#ffc201"
    TitleForeground     "white"
    MenuBackground      "black"
    MenuForeground      "#ffc201"
    MenuTitleBackground "#ffc201"
    MenuTitleForeground "black"
    IconBackground      "black"
    IconForeground      "#ffc201"
    IconBorderColor     "black"
}

MoveDelta 3
Function "move-or-lower" { f.move f.deltastop f.lower }
Function "move-or-raise" { f.move f.deltastop f.raise }
Function "move-or-iconify" { f.move f.deltastop f.iconify }

Button1 = : root : f.menu "defops"
Button2 = : root : f.delete
Button1 = m : window|icon : f.function "move-or-lower"
Button2 = m : window|icon : f.iconify
Button3 = m : window|icon : f.function "move-or-raise"

Button1 = : title : f.function "move-or-raise"
Button2 = : title : f.raiselower

Button1 = : icon : f.function "move-or-iconify"
Button2 = : icon : f.iconify

Button1 = : iconmgr : f.iconify
Button2 = : iconmgr : f.iconify

menu "quit" {
    "Quit X?"   f.title
    "quit"    f.quit 
}

menu "defops"
{
"YourHost"     f.title
"(L) xterm"   f.exec "exec xterm -ls -fg gray -bg black -sl 500 +sb -geometry '104x57+0+18' &"
"(R) xterm"   f.exec "exec xterm -ls -fg gray -bg black -sl 500 +sb -geometry '104x57+648+18' &"
"(Big) xterm" f.exec "exec xterm -ls -fg gray -bg black -sl 500 +sb -geometry '212x57+0+18' &"
"gvim"        f.exec "exec gvim &"
#"conky"      f.exec "exec conky &"
"vm tools"    f.exec "exec vmware-toolbox &"
#"iceape"     f.exec "exec iceape &"
#"firefox"    f.exec "exec firefox &"
"kill"        f.destroy
"restart"     f.restart
"quit"        f.menu "quit"
}



Secure HTTP Tunnel Permalink

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

The Stupid Way

(Don't do this, see The Smart Way below)

On a remote machine that you have SSH access to:

remote$ hostname
host.where.proxy.is.running
remote$ # start an HTTP proxy running on port 8887 here

Then, on your local machine:

local$ ssh -qnN -L 8080:localhost:8887 host.where.proxy.is.running.tld &

... and setup your browser to use localhost:8080 as the proxy.

The proxy software I use on my remote host is TinyProxy

The Smart Way

You don't even need to setup a proxy at your remote host if you just create a tunnel like this:

local$ ssh -qnN -D 1080 remotehost &

... that will setup a tunnel from on your local machine from localhost:1080 over to remote, and then use the remote server to just send any requests you make through there... like a relay. So if you set your browser to use the SOCKS proxy on localhost:1080 then you have a tunnel without having to setup any proxy software. Thanks Snare!




BSD Terminal Niggles Permalink

*BSD, Shell, Linux Added less than a year ago

In my BSD VMs (I am using an OpenBSD one at the moment), there are certain display settings that I like to change to emulate the default "terminal" settings on Linux. (I quote "terminal" here because we're not really messing with termcaps or anything hardcore.)

Why doesn't Ctrl-L clear the screen?

I install Bash to do this :-) The default shells for *BSD are often ksh or csh and it seems that Ctrl-L is not set-up to clear the screen on these shells. There is probably a better way to do this but I like Bash anyway, even if it is bloated.

Why doesn't .bashrc get read?

Put your commands/setup code in .bash_profile - or include .bashrc from .bash_profile

Fix your default pager

The default pager on *BSD is often set to more. You want to make it less.

$ export PAGER=less

This will make it so when you look at a man page and you scroll to the bottom of the page using G it doesn't quit back to the shell, it stays in the man page! This annoyed me so much!




SSH Config Permalink

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

Users

If you are on a system as user fredb and you want to ssh to a host where your login is superman, you would normally have to specify the username on the ssh line like so:

fredb@thishost$ ssh superman@otherhost

... but you can save yourself some typing by specifying that a ssh to otherhost should try to login as superman every time by adding some lines to your ~/.ssh/config file:

Host otherhost
    User superman

Now you can simply do this:

fredb@thishost$ ssh otherhost

... and it will ask for superman's password instead of fredb's.

Host Nicknames

You can also use your config file to specify host nicknames. Say you normally connect to longhostname.tld, you can shorten that to lhn if you like:

Host lhn
    Hostname longhostname.tld
    User jsmith

... now you simply:

$ ssh lhn

Identity Files (Keys)

If you have keys set up for your various hosts, and those keys are loaded in your ssh-agent, you might like to specify which key belongs to which host in the config file.

Host lhn
    Hostname longhostname.tld
    User jsmith
    IdentityFile ~/.ssh/id_dsa.longhostname

This is important if you have greater than 6 keys in your agent. Why? Because without this mapping, ssh-agent will iterate through its list of keys until it finds one that works - but the host will hang up after 6 unsuccessful tries! If your key is number seven in the list then it will not work. So, adding the IdentityFile mapping in the config file as above will make ssh-agent try the correct key the very first time.




Linux Groups and Login Permalink

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

Bob was experiencing something funny on Debian:

bob@local $ groups
bob wheel
bob@local $ sudo groups bob
bob wheel www-data othergroup

Turns out that groups are applied to a user on login only, and bob was added to the extra two groups after his last login. So once bob logged-out and back in again:

bob@local $ groups
bob wheel www-data othergroup

... everything was right with the world. Thanks Rendrag!




chmod and umask Gotchas (Got Me Anyway) Permalink

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

Every file in unix has a set of permissions. They are (r)ead, (w)rite, and e(x)ecute for each of these three types of people: (u)ser who owns the file, members of the (g)roup that own the file and (o)ther people on the system.

Mnemonic: RWX = running with scissors (X is a pair of scissors, right???)

$ ls -hl
total 0
-rw-r--r-- 1 frank users 0 2009-02-04 15:47 one
-rw-r--r-- 1 frank users 0 2009-02-04 15:47 three
-rw-r--r-- 1 frank users 0 2009-02-04 15:47 two
d123456789    a      b

Note: e(x)ecute means it's a binary or a script that you can run like this: ./scriptname -or- if the 'file' is a directory it means you can cd into it and look around.

If you are on a shared hosting environment, and you have nothing to do with anyone else on the system, and have heaps of files you don't want publicly visible, you could do one of two things:

Method (1) Use chmod to remove all (o)ther permissions on all your files -or-

Method (2) Use chmod to remove the e(x)ecutable bit of the (o)ther permission on your home directory only

The first option is natural enough, let's walk through it: You are user frank. Another user on your shared hosting environment is user bill. You have three files in your home directory, /home/frank called one, two and three. To make sure all the (o)ther permissions on these files are removed (so that bill can neither (r)ead, (w)rite or e(x)ecute those three files), do something like this:

$ chmod o-rwx one two three

The o means other, the - means remove, the rwx is the list of permissions to remove.

Let's examine the second option:

$ chmod o-x /home/frank

If any directory on the way to a file is o-x then others can not list, view, change or execute that file.

But wait: what if the file one was owned by the user frank and owned by the group users? And let's say that bill is in the group users too... well, bill can still see one until the (g)roup permissions are removed from it or the (g)roup e(x)ecutable is removed from a containing directory. Because in this case, bill is not an (o)ther user - he is a (g)roup user (a user in the same group as that which owns the file.)

Confusing?

A note about method 2: If you are frank, in the group users, and you have a directory in your home directory named htdocs that is owned by apache:apache (and obviously is used to serve web pages) then this method will break your webserver! Why? Because in the chain /home/frank/htdocs there is an o-x (on /home/frank) which means that (o)thers (like apache) can not read the htdocs dir. So this is not a good method if you have a setup like this.

umask is the utility that tells you what permissions a file has when you first create it (and don't specifically chmod it.) Sometimes you'll get a umask like this:

$ umask
  0022

The last three numbers mean what is taken away (subtracted) from 7 from each of the three types, (u) (g) and (o). What has 7 got to do with it? Well:

If a file has all bits set for, say, the (u)ser type then the (u)ser will be able to read, write and execute the file.

So if your umask is 0022 (ignore the first number for this exercise, only take notice of 022) then by default your files are going to be created like this:

But here's the twist: the (x) only takes effect if the 'file' you've just created is a directory. Otherwise ignore it. So with the above umask of 022 it would be ugo = 755 for a newly created dir and ugo = 644 for a newly created file.

Ever seen someone chmod a file with numbers like this?

$ chmod 640 three

They have just made the file named three: (r)eadable and (w)riteable by the (u)ser (r + w = 4 + 2 = 6), (r)eadable by the owning (g)roup (4 = w), and neither (r)eadable, (w)riteable or e(x)ecutable by (o)thers (0 = no permissions.)

A umask of 027 is a better way to go than 022. Set it like this:

$ umask 0027

I will keep re-reading this post to see if there are any errors in it - it is a confusing topic :-)




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