Hot answers tagged

53

This is a compilation and index of the answers given so far. This post is community wiki, it can be edited by anybody with 100+ reputation and nobody gets reputation from it. Feel free to post your own answer and add a link to it in here (or wait for me to do it). Ideally, this answer should just be a summary (with short entries while individual other ...


13

Do some applications running on Unix-likes —if not the system's API— treat //foo/bar Paths specially? I am aware of Perforce which uses //depot/A/B/C/D Paths to refer to the Depot. Perforce also supports //Client/C/D Paths, when the Client is pointing to //depot/A/B/. Here, local FileSystem may not have these Paths. p4 filelog //depot/A/B/C/D will show ...


12

Several decades ago, Tektronix Utek (BSD 4.2 based Unix, first on National Semiconductors 32016 CPUs then Motorola 68020s) was providing something called DFS (distributed file system) under which //foo/bar was referring to the /bar file on the foo dfs server. It was later obsoleted by Sun's NFS. Unfortunately, I haven't reference yet to back that but I ...


6

Following the lead from this answer. And reading page 2-15 from the manual from Bitsavers (thanks @grawity). Shared Data The second design principle of the Domain/OS distributed file system, sharing by default, implies a global uniform name space. The name space of the distributed file system appears to users like that of a giant timesharing file ...


5

[ "$1" != "${1#/}" ] || return 1 There may be a better way (that's why I asked). This code strips off any leading / in $1 and checks that the result is not the same as $1 itself.


5

Another application: Blender treats a leading // as a reference to the project directory (the directory in which the .blend file is saved). Here's the relevant manual page. This is true for non-Unix-like operating systems (i.e., Windows) as well.


4

In the 1980s, SEL/Gould had a Unix operating system called UTX-32 in which //host/path was equivalent to /net/host/path in Solaris; i.e., remotely access path path on host host.  I can't find any documentation on it, so I don't know whether this was RFS or parallel evolution (or whether AT&T stole acquired it from Gould).


4

I have a vague memory that the //host/path notation was used on AT&T SysV.3 as part of its RFS Remote File Sharing implementation. This was eventually abandoned around the time SysV.4 was released in favour of the simpler but more popular NFS from Sun Microsystems. However, I cannot find any concrete references to the syntax, and the documentation I ...


3

Pattern matching is done with case statements in all Bourne-like shells. is_absolute() { case "$1" in ///* | //) true;; //*) false;; # on some systems, //foo is special and is # not an absolute path. // alone is / /*) true;; *) false esac } Remove the first two entries on systems that don't ...


3

If the filename is in a variable, the canonical way to remove a preffix is: removepre="foo bar " filename="foo bar XXX doo par.jpg" filename="${filename#"$removepre"}" echo "$filename" The problem with the suffix you present is that there is an extension that you want to preserve, so it becomes a bit longer: removesuf=" doo par" filename="foo bar XXX doo ...


3

There is a Perl script written by Daniel S. Sterling available at https://gist.github.com/eqhmcow/5389877 (referenced from IO::Uncompress::Unzip) that looks like it could almost do what you need. Change line 46 to read my $status, $filenumber = 0; Comment lines 52-54 (put # at the beginning of each line) Change line 61 to read my $destfile = "file" . ...


3

POSIX states in the Rationale for A.4.12 Pathname Resolution Paragraphs 9 and 10: In some networked systems the construction /../hostname/ is used to refer to the root directory of another host, and POSIX.1 permits this behavior. Other networked systems use the construct //hostname for the same purpose; that is, a double initial slash is used. ...


2

Just include LOCAL_PATH in pattern part: printf '%s\n' "${LINE//"$LOCAL_PATH"/}" If LINE always start with content of LOCAL_PATH, POSIXly: printf '%s\n' "${LINE#"$LOCAL_PATH"}"


2

With prename: Setup: $ mkdir test && cd test $ > "foo bar XXX doo par.jpg"; > "foo bar YY YY doo par.jpg" Action: $ rename -n 's/^foo bar //; s/ doo par(\.[^.]*)$/$1/' * foo bar XXX doo par.jpg renamed as XXX.jpg foo bar YY YY doo par.jpg renamed as YY YY.jpg (Remove the -n to have those moves actually performed)


2

If by absolute path you mean that it starts with /, and we are talking about bash (as tag suggest): $ var1='/tmp/foo' $ var2='tmp/foo' $ [[ "$var1" =~ ^/ ]] && echo yes || echo no yes $ [[ "$var2" =~ ^/ ]] && echo yes || echo no no


2

An absolute path would begin with / not contain any /../ or /./ not begin with ../ or ./ not end with /.. or /. so you could do this (portably) with a case statement: case "x$1" in (x*/..|x*/../*|x../*|x*/.|x*/./*|x./*) rc=1 ;; (x/*) rc=0 ;; (*) rc=1 ;; esac return $rc This ...


1

This script may help: for file in *-min.png; do echo mv "$file" "${file%-min.png}.png" done Remove the echo to actually execute the command.


1

That depends on your shell. I use zsh, and this is the way I do it: for i in *-min.*; do mv $i "${i%-*}.${i#*.}"; done I advice checking out the manpage of your shell, and checking out a section similar to "parameter expansion" (as it is called in the zsh man page). Similar solutions are available for bash and other shells as well (you did not specify ...


1

Chances are that if you just decode the %XX URI encodings, you'll get UTF-8 encoded characters. In zsh: autoload zmv LC_ALL=C zmv '(**/)(*%*)' '$1${2//(#b)%(??)/${(#):-0x$match}}' If as noted by Gilles, that � substitution character is for a 0xc3 byte (which in iso8859-1 is a letter which would explain why it hasn't been URI-encoded contrary to 0x9c which ...


1

Just check the first character of the string using substring syntax: [[ ${var:0:1} = / ]] || return 1


1

POSIX define absolute path as a pathname beginning with a single or more than two /. There's a utility called pathchk to check pathname, so you can do: [ -z "${1%%/*}" ] && pathchk -pP "$1" -p tells pathchk to perform check for path that: Is longer than 256 bytes (See _POSIX_PATH_MAX) Contains any component longer than 14 bytes (See ...



Only top voted, non community-wiki answers of a minimum length are eligible