Sponsored Content
The Lounge What is on Your Mind? Filenames with hyphens - UNIX style? Post 302639173 by jlliagre on Friday 11th of May 2012 09:39:44 AM
Old 05-11-2012
Unix is very permissive in what it accepts but quite restrictive in what it recommends. Your first reply seemed to imply Windows was too permissive while Unix wasn't. The reality is the opposite. Windows has more restrictions and peculiarities like refusing a file to be named null.h or com0.c, having a colon in its name, having a space as its last character and so on, not to mention the way it preserve case but doesn't allow files with the same name but different cases to stay in the same directory.

In any case, your example obviously violates the POSIX recommendations but is still a valid Unix filename. It is obviously unacceptable to Windows and possibly other OSes and defeat non rock-solid scripts.

If your backup software has issues processing this filename, that's a bug or a limitation of the storage format it uses, the OS or the file system. The venerable tar utility has no issues handling it:
Code:
$ touch 'C:\March report - with summary figures'
$ tar cvf foo.tar *es
a C:\March report - with summary figures 0K
a files 8388K
$ tar tvf foo.tar
-rw-r--r-- 60004/60004      0 May 11 17:14 2012 C:\March report - with summary figures
-rw-r--r--   0/0   8589076 Nov  9 16:07 2011 files
$ mkdir extract
$ cd extract
$ tar xvf ../foo.tar
x C:\March report - with summary figures, 0 bytes, 0 tape blocks
x files, 8589076 bytes, 16776 tape blocks
$ ls -l
total 2
-rw-r--r--   1 jlliagre jlliagre       0 May 11 17:14 C:\March report - with summary figures
-rw-r--r--   1 jlliagre jlliagre 8589076 Nov  9  2011 files

About your last request, here are the numbers I got:
  • 0.74% have colons (1242)
  • 0.00% hashes (2 files out of 168522)

Last edited by jlliagre; 05-11-2012 at 10:57 AM..
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Unix History Question: Why are filenames/dirnames case sentsitive in Unix?

I tried looking for the answer online and came up with only a few semi-answers as to why file and directory names are case sensitive in Unix. Right off the bat, I'll say this doesn't bother me. But I run into tons of Windows and OpenVMS admins in my day job who go batty when they have to deal... (3 Replies)
Discussion started by: deckard
3 Replies

2. Shell Programming and Scripting

Unix filenames and spaces

I have files on my unix boxes that users have created with spaces. Example: /tmp/project plan ls -l "/tmp/project plan" works fine. $/tmp>ls -l "/tmp/project plan" -rw-r--r-- 1 root other 0 Jan 31 12:32 /tmp/project plan I created a file called test and put just the... (2 Replies)
Discussion started by: x96riley3
2 Replies

3. Shell Programming and Scripting

[Unix] a dos style rename wont work

Hey guys i'm creating a dos style rename script, so if a user types say q14.* as the 1st param and b14.* as the 2nd and will rename all q14 files to b14 but keep the extensions, so i've developed nearly the full script "i think", if i use echo(echo "if $1 had been renamed it would now be... (3 Replies)
Discussion started by: fblade1987
3 Replies

4. What is on Your Mind?

Looking for a "Motivational Poster" Style unix command?

I am trying to figure out a sort of Motivational line that I could write as a short unix command... I don't know too much but something like Get everything you want in life sudo (get everything) (you want?) (life directory) Any ideas? Thank You very much Brad (4 Replies)
Discussion started by: ridesurf
4 Replies

5. Shell Programming and Scripting

Renaming mutiple files with hyphens in name

I have searched throught a host of threads to figure out how to rename mutiple files at once using a script. I need to convert 200+ files from: fKITLS_120605-0002-00001-000001.hdr to eStroop_001.hdr fKITLS_120605-0002-00002-000002.hdr to eStroop_002.hdr and so forth.... What is... (5 Replies)
Discussion started by: akenne3
5 Replies

6. Shell Programming and Scripting

Using grep with hyphens

This is on a RHEL 6 box with bash 4.1.2 I'm trying to to use grep to only find those lines containing matches that form whole words. The -w option works fantastic unless of course that word has a hyphen. The problem is I will get a hit on "test-group" which is a good thing, but I will also... (3 Replies)
Discussion started by: woodson2
3 Replies

7. Shell Programming and Scripting

Appending date to UNIX Filenames

Hello, I have a file name in the below format and have to append the date as _$currdate. kchik_UK_lo.txt_$currdate. The above should be the format and I dont want to put entire filename as above in the code, but it should give me the output as the above filename.Can anyone please help... (7 Replies)
Discussion started by: harika03
7 Replies

8. Shell Programming and Scripting

Script in Perl or awk to remove multiple hyphens

Dear all, I have a database of compound words. I want to retain only strings with a single hyphen and identify those strings which have more than one hyphen. I am giving an example below test-test test-test-test test-test-test-test-test good-for-nothing The regex/script should remove all... (11 Replies)
Discussion started by: gimley
11 Replies

9. What is on Your Mind?

Coding Style at UNIX.com forums

Hi, as I mentioned in this thread(https://www.unix.com/shell-programming-and-scripting/280737-awk-function-return-permutations-n-items-out-m.html), a helpful coding style may improve overall value and support for people who come here and want to learn things the participants from unix.com have... (2 Replies)
Discussion started by: stomp
2 Replies
tar(n)								 Tar file handling							    tar(n)

__________________________________________________________________________________________________________________________________________________

NAME
tar - Tar file creation, extraction & manipulation SYNOPSIS
package require Tcl 8.4 package require tar ?0.4? ::tar::contents tarball ::tar::stat tarball ?file? ::tar::untar tarball args ::tar::get tarball fileName ::tar::create tarball files args ::tar::add tarball files args ::tar::remove tarball files _________________________________________________________________ DESCRIPTION
::tar::contents tarball Returns a list of the files contained in tarball. The order is not sorted and depends on the order files were stored in the archive. ::tar::stat tarball ?file? Returns a nested dict containing information on the named ?file? in tarball, or all files if none is specified. The top level are pairs of filename and info. The info is a dict with the keys "mode uid gid size mtime type linkname uname gname devmajor devminor % ::tar::stat tarball.tar foo.jpg {mode 0644 uid 1000 gid 0 size 7580 mtime 811903867 type file linkname {} uname user gname wheel devmajor 0 devminor 0} ::tar::untar tarball args Extracts tarball. -file and -glob limit the extraction to files which exactly match or pattern match the given argument. No error is thrown if no files match. Returns a list of filenames extracted and the file size. The size will be null for non regular files. Leading path seperators are stripped so paths will always be relative. -dir dirName Directory to extract to. Uses pwd if none is specified -file fileName Only extract the file with this name. The name is matched against the complete path stored in the archive including directo- ries. -glob pattern Only extract files patching this glob style pattern. The pattern is matched against the complete path stored in the archive. -nooverwrite Dont overwrite files that already exist -nomtime Leave the file modification time as the current time instead of setting it to the value in the archive. -noperms In Unix, leave the file permissions as the current umask instead of setting them to the values in the archive. % foreach {file size} [::tar::untar tarball.tar -glob *.jpg] { puts "Extracted $file ($size bytes)" } ::tar::get tarball fileName Returns the contents of fileName from the tarball % set readme [::tar::get tarball.tar doc/README] { % puts $readme } ::tar::create tarball files args Creates a new tar file containing the files. files must be specified as a single argument which is a proper list of filenames. -dereference Normally create will store links as an actual link pointing at a file that may or may not exist in the archive. Specifying this option will cause the actual file point to by the link to be stored instead. % ::tar::create new.tar [glob -nocomplain file*] % ::tar::contents new.tar file1 file2 file3 ::tar::add tarball files args Appends files to the end of the existing tarball. files must be specified as a single argument which is a proper list of filenames. -dereference Normally add will store links as an actual link pointing at a file that may or may not exist in the archive. Specifying this option will cause the actual file point to by the link to be stored instead. ::tar::remove tarball files Removes files from the tarball. No error will result if the file does not exist in the tarball. Directory write permission and free disk space equivalent to at least the size of the tarball will be needed. % ::tar::remove new.tar {file2 file3} % ::tar::contents new.tar file3 BUGS, IDEAS, FEEDBACK This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category tar of the Tcllib SF Trackers [http://sourceforge.net/tracker/?group_id=12883]. Please also report any ideas for enhancements you may have for either package and/or documentation. KEYWORDS
archive, tape archive, tar tar 0.4 tar(n)
All times are GMT -4. The time now is 12:53 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy