Tag Archives: unix

quickie of the day – rm

One thing that bothered me for a long time was when I had to delete files behinning with `-`or `–`.
You can always use slashes and quotes but there is an easier way to go about it.

Add — to rm, and it will stop parsing the command line for flags and options.
So simply try this next time!

rm -- -file

A lot simpler and cleaner than slashes and quotes if you ask me!

Share

oneliner of the day – ps

This is one of my old favourites, that is useful both for verifying what shell you are running and also the $$ variable is very useful for scripting and writing pid files, lock files, statuses etc.

Let’s have a look at it:
ps -p $$

What this does is tell ps to look at the process specified with the -p flag.
And in this case that is $$.
$$ is in turn a shell variable expanding to the pid of the current running process, in our case the shell.

Example output:
%ps -p $$
PID  TT  STAT      TIME COMMAND
47991  p0  Ss     0:00.03 -csh (csh)

$ ps -p $$
PID   TT  STAT      TIME COMMAND
5404 s002  S      0:00.02 ksh

[henrik@character ~]$ ps -p $$
PID TT STAT TIME COMMAND
40668 1 S 0:00.02 bash

henke@3(NXDOMAIN):~> ps -p $$
PID TTY TIME CMD
3152 pts/2 00:00:00 bash

(FreeBSD; Mac OS X, FreeBSD and OpenSuSe respectively)
You get the point.

Share