coreutils

basename – strip directory and suffix from filenames

A UNIX Command
$basename
basename: missing operand
Try `basename --help' for more information.
$basename /usr/bin/
bin
$basename /usr/
usr
$
$basename /usr/bin/less
less
$basename /usr/include/ma
malloc.h  math.h
$basename /usr/include/math.h
math.h
$basename /usr/include/math.h .
math.h
$basename /usr/include/math.h .h
math
$basename /usr/lib/libgccpp.so.1
libgccpp.so.1
$basename /usr/lib/libgccpp.so.1 .1
libgccpp.so
$

UNIX Explanation
`basename' removes any leading directory components from NAME.
Synopsis:

     basename NAME [SUFFIX]

If SUFFIX  is specified  and is identical  to the  end of
NAME, it is  removed from NAME as well.   Note that since
trailing  slashes are removed  prior to  suffix matching,
SUFFIX   will  do   nothing  if   it   contains  slashes.
`basename' prints the result on standard output.

Together, `basename' and `dirname' are designed such that
if `ls  "$name"' succeeds, then the  command sequence `cd
"$(dirname  "$name")";  ls  "$(basename "$name")"'  will,
too.   This  works   for  everything  except  file  names
containing a trailing newline.

POSIX allows the implementation  to define the results if
NAME  is  empty  or   `//'.   In  the  former  case,  GNU
`basename' returns the empty string.  In the latter case,
the result is `//' on platforms where // is distinct from
/, and `/' on platforms where there is no difference.


truncate – shrink or extend the size of a file to the specified size

A UNIX Command

$cat example.text
hello
$ls -l example.text
-rw-r--r-- 1 jeffrin jeffrin 6 Jun 21 02:32 example.text
$truncate -s 10 example.text
$ls -l example.text
-rw-r--r-- 1 jeffrin jeffrin 10 Jun 21 02:35 example.text
$hexdump example.text
0000000 6568 6c6c 0a6f 0000 0000
000000a
$cat example.text
hello
$truncate -s 9 example.text
$ls -l example.text
-rw-r--r-- 1 jeffrin jeffrin 9 Jun 21 02:36 example.text
$hexdump example.text
0000000 6568 6c6c 0a6f 0000 0000
0000009
$

UNIX Explanation

`truncate' shrinks  or extends the  size of each  FILE to
the specified size.If a FILE is larger than the specified
size, the extra  data is lost.  If a  FILE is shorter, it
is extended and the extended part (or hole) reads as zero
bytes.

touch -c behaves incorrectly (non-POSIX)


http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=439033

POSIX says about 'touch'[*]:

-c
    Do not create a specified file if it does not exist. Do not write
    any diagnostic messages concerning this condition.

[*] http://www.opengroup.org/onlinepubs/009695399/utilities/touch.html

But under some conditions, 'touch' writes a diagnostic message when
the file doesn't exist. For instance:

vin:~> mkdir dir
vin:~> chmod 000 dir
vin:~> /usr/bin/touch -c dir/file
/usr/bin/touch: setting times of `dir/file': Permission denied
zsh: exit 1     /usr/bin/touch -c dir/file
vin:~[1]>

Note that the BSD 'touch' does not have this problem, as shown by the
test below (under Mac OS X):

prunille:~> mkdir dir
prunille:~> chmod 000 dir
prunille:~> /usr/bin/touch -c dir/file
prunille:~>

Also the touch(1) man page doesn't say that no diagnostic messages
are written when the file doesn't exist. Users are not required to
look at the POSIX standard to get the full documentation.

Ditto for the manual (coreutils.info).

coreutils: ls –quoting-style=c and | (pipe) symbol


http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=432945

output of ls --quoting-style=c is incorrect when filename contains |
(pipe) symbol.

Steps:
  mkdir /tmp/bla
  touch "/tmp/bla/filename with | pipe"
  ls --quoting-style=c /tmp/bla

returns:

 "filename with \| pipe"

thanks,
-Mathieu

Ref:
http://groups.google.com/group/comp.lang.c/browse_thread/thread/0db8070def6a4453


coreutils: join outputs wrong field order for -v option


join – join lines of two files on a common field

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=410270

Package: coreutils
Version: 5.97-5
Severity: normal


the join field is incorrect for the -v version.

#08-Thu-20-03-40 /tmp$ cat>|a
#a1,a2,c3,a4,a5
#a21,a22,a33,a44,a55
#08-Thu-20-05-07 /tmp$ cat>|b
#b1,b2,b3,c3,b5
#b21,b22,b33,b44,b55
#08-Thu-20-06-07 /tmp$                 join -t, -i -1 3 -2 4 a b
#c3,a1,a2,a4,a5,b1,b2,b3,b5
#08-Thu-20-06-10 /tmp$                 join -v 2 -t, -i -1 3 -2 4 a b
#b33,b21,b22,b44,b55
#08-Thu-20-06-15 /tmp$

thanks.

-- System Information:
Debian Release: 4.0
Architecture: i386 (i686)
Shell:  /bin/sh linked to /bin/bash
Kernel: Linux 2.6.16nomd
Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968)

comm – compare two sorted files line by line



$comm sorta.txt sortb.txt
d
g
comm: file 1 is not in sorted order
e
s

x
comm: file 2 is not in sorted order
g
s
n

$cat sorta.txt
d
g
e
s

$cat sortb.txt
x
g
s
n

$

$cat sorta.txt
a
b
c
d
$cat sortb.txt
a
f
g
h
$comm sorta.txt sortb.txt
a
b
c
d
f
g
h
$
comm - compare two sorted files line by line

With no options, produce three-column output.
Column one contains lines unique to FILE1, column
two contains lines unique to FILE2, and column three
contains lines common to both files.

Reference/Source :
Debian manual for command "comm".