New answers tagged filenames
1
Ive been using this for several years now.
# The absolute, canonical ( no ".." ) path to this script
canonical=$(cd -P -- "$(dirname -- "$0")" && printf '%s\n' "$(pwd -P)/$(basename -- "$0")")
1
This should be quite portable:
mypath=$(exec 2>/dev/null;cd $(dirname $0);unset PWD;/usr/bin/pwd||/bin/pwd||pwd)
1
Assuming you really meant the absolute path, i.e. a path from the root directory:
case $0 in
/*) mypath=$0;;
*) mypath=$PWD/$0;;
esac
This works in any Bourne-style shell, by the way.
If you meant a path with all symbolic links resolved, that's a different matter. readlink -f works on Linux (excluding some stripped-down BusyBox systems), FreeBSD and ...
1
My version of Solaris doesn't support ls -v (grrr). And the sort solution provided above 1) requires knowledge of the position of digits in the filename, and 2) doesn't handle things like multi-part version numbers.
The approach below is Solaris-compatible, doesn't require foreknowledge of the digit positions, and handles version numbers with 2, 3 or 4 ...
-2
The spaces in the values can be avoided by as simple for loop construct
for CHECK_STR in `ls -l /root/somedir`
do
echo "CHECKSTR $CHECK_STR"
done
ls -l root/somedir contains
my file with spaces
Output of above
my
file
with
spaces
to avoid this output, simple solution (notice the double quotes)
for CHECK_STR in "`ls -l /root/somedir`"
do
echo ...
1
With the zsh shell, you could do:
cd /data/db/OX || exit
setopt extendedglob
latest_two=(<->_<->(N/nOn[1,2])
(($#latest_two == 2)) || exit
cp -p $latest_two[2]/pt.* $latest_two[1]/
POSIXly assuming filenames don't contain newline characters:
cd /data/db/OX || exit
set -- $(ls -F |
grep -xE '[0-9]+_[0-9]+/' |
sort -rnt_ -k1,1 -k2,2 |
...
1
On Unix, a file name can contain any character except '\0' (NUL) and '/' (directory separator). All current Linux/Unix native filessytems have to handle this. Foreign filesystems might have their own restrictions (for example, MS-DOS FAT can have only filenames in the 8+3 format, with exactly one '.', probably ':' and '\' are forbidden too; VFAT presumabably ...
2
The limiting factor is more the OS than the FS. For example, the only forbidden character in ext4 is '\0' (NULL), which is also forbidden in unix, but unix and linux have one other forbidden character, '/'.
1
This wasn't available back then but with more recent versions of split one can use:
--additional-suffix=SUFFIX
append an additional SUFFIX to file names.
so adding
--additional-suffix=.txt
to the command means the resulting files will automatically have .txt extension.
split -dl 10000 --additional-suffix=.txt words wrd
Top 50 recent answers are included

