Tag Info

New answers tagged

2

You could use another character that cannot appear in a file name: / so once you got your list of files you know that paths are separated by two slashes: // (the second being part of the path as each path starts with a slash but doesn't end with one). You could then use your favourite tool to turn the list into NUL separated paths...


2

An easy and portable way is to insert a file with an empty line in the file arguments: # create file with one empty line echo > emptyline.txt # calling sed: sed -e 's/%%FOO%%/whatever/g' \ -e 's/%%BAR%%/other thing/g \ file1.ldif.template \ emptyline.txt \ file2.ldif.template \ | ... Some shells support also this: sed -e ...


2

Using GNU sed -s (--separate) extension, you can append an empty newline after each filename (line addresses refer to each filename, instead of treating all the input as one longer stream, similar to awk's FNR and NR variables) sed \ -s \ -e '$a\\' \ -e 's/%%FOO%%/whatever/g' \ -e 's/%%BAR%%/other thing/g \ file1.ldif.template \ ...


0

I don't have access to OSX so this is a wild guess... but you can try other techniques to delete files, rather than relying on the shell's globbing to match. Try: find . -not -type d -print -delete or even find . -not -type d -print | perl -nle 'print; unlink'


13

The answer from @ubaid-ashraf is almost there. The way to specify file with no extension, in ksh would be: cp -- !(*.*) /new/path/ so that any file with dot in file name is skipped. For that to work in bash, you need to enable the extglob option (shopt -s extglob) and the kshglob option in zsh (set -o kshglob).


1

You can use find+grep to get only files that have no extension find . -maxdepth 1 -type f | sed 's/^\.\///' | grep -v "\." So your copy command will be cp ` find . -maxdepth 1 -type f | sed 's/^\.\///' | grep -v "\." ` destination_folder


5

You can do something like: cp -- !(*.txt) /path/to/directory The above code will copy all the files without .txt extension. You can also give multiple extension via pipe character. For example: cp -- !(*.txt|*.c|*.py) /path/to/directory


3

It seems that you have made a mistake when editing PATH variable. Backslash character in your PATH output was considered literal, not escaping for space. You need: PATH="/Applications/Racket v6.2/bin:$PATH"; export PATH or: PATH=/Applications/Racket\ v6.2/bin:$PATH; export PATH


0

This problem can be solved handily in python using various iterator building blocks available in the itertools module from os.path import isfile from string import ascii_lowercase from itertools import dropwhile, imap, chain, product, repeat, count next(dropwhile(isfile, imap('file_{}.txt'.format, imap(''.join, chain.from_iterable( ...


1

If you don't really care, on Linux (more precisely, with GNU coreutils): tmpfile=$(TMPDIR=. mktemp --backup=numbered) … # create the content mv --backup=numbered -- "$tmpfile" file.txt This uses the GNU backup name scheme: file.txt, file.txt.~1~, file.txt.~2~, … Another relatively compact way, with numbers that can be placed in a more convenient place, ...


2

When a program opens a file, that file ends up on a file descriptor that's free at the time. By opening a file before the program starts, you're only making one more file descriptor busy, so the file you're interested in might end up on a different descriptor. If you want the program to open a different file, you'll need to modify the open operation when it ...


0

Try: perl -le 'print $ARGV[-1] =~ s/[\da-zA-Z]+(?=\.)/++($i=$&)/er' file*.txt That will give you file_10.txt after file_9.txt, file_g.txt after file_f.txt, file_aa.txt after file_z.txt, but not file_ab.txt after file_aa.txt or file_11.txt after file_10.txt because the file* shell glob will sort file_z.txt after file_aa.txt and file_9.txt after ...


0

This outputs the next sequential filename. The ID can be any length and it can be either numeric or alphabetic. This sample is primed to use an alpha ID, the first ID being a pfix='file_' sfix='.txt' idbase=a # 1st alpha id when no files exist - use a decimal number for numeric id's idpatt='[a-z]' # alpha glob pattern - use '[0-9]' for numeric ...


1

Here's a crude way (no error checking) to do it purely in bash: #helper function to convert a number to the corresponding character chr() { [ "$1" -lt 256 ] || return 1 printf "\\$(printf '%03o' "$1")" } #helper function to convert a character to the corresponding integer ord() { LC_CTYPE=C printf '%d' "'$1" } #increment file fn_incr(){ #first ...


8

The basic format of find is find WHERE WHAT So, in find *, the * is taken as the WHERE. Now, * is a wildcard. It matches everything in the current directory (except, by default, files/directories starting with a .). The Windows equivalent is *.*. This means that * is expanded to all files and directories in your current directory before it is passed to ...


0

First of all kept in mind the syntax of find:- find [-H] [-L] [-P] [-D debugopts] [-Olevel] [path...] [expression] What is the difference between find * and find ~ for searching a file? * is while card which matches everything. Here find * passes the list of files/dirs in the current directory and those as target names to search for. so, it will ...


2

The easy way to act on a file with a difficult-to-type name is to use completion. In this case, since the first few characters of the name are easy to type, type them, and press Tab. $ mv whoTab found.txt If you were unable to determine the first character, you could press Tab after ./, to cycle through all the file names in the current directory. The ...


1

Enclosing the filename in question in quotes is probably the easiest way to remove or rename it. First create a test file: rm " -myfile(1):ok?" If a file simply begins with a hyphen, use "--" to tell the command that no more options exist and that the leading hyphen is a command argument: rm -- -myfile In cases where your file name has unprintable ...


0

The reason the filename gets doubled is that if $fname is [test], then name="${fname%\.*}" extension="${fname#$name}" results in: name=[test] extension=[test] (Explanation below.) Later, when $extension is concatenated to $newname, you'll get test][test]. What you should have used: name=${fname%.*} extension=${fname#"$name"} The quotes around the ...


0

It's even simpler with rename embedded in a two-liner: while rename ] '' *; do true; done while rename [ '' *; do true; done rename replaces the first occurrence of $1 with $2 in filename(s) in $3+ and this block removes any and all brackets in all file-and-directorynames in CWD.


0

As globbing is done by the shell, there is even no need to call ls or find, echo does the trick: $ echo /tmp/???? /tmp/file $ Only thing is, if there is no file whose name is 4 characters long, it will just print /tmp/???? You might want a one-liner bash script that checks this and also prints one file per line: pattern=/tmp/????? ; for f in $pattern ...


1

Solution posted by @juicebyah will only remove the initial bracket. If OP wants to remove both brackets, it is better to use sed in this way: find . -type f -iname "*[*" | \ while IFS= read -r line; \ do mv "$line" "$(printf %s "$line" | sed -re 's/(\[|\])//g')"; done;


0

@Theophrastus has the right idea. According to POSIX "[t]he characters composing the [file] name may be selected from the set of all character values excluding the slash character and the null byte" (my emphasis). In other words, every string between two slashes (except the empty string) is another directory, and you cannot create a file with a name ...


2

i found this one liner and this work : for x in *[*; do mv -- "$x" "${x//[/}"; done this should do the job , just replace left or right bracket each time yu execute this commandl


2

As others have already explained, the problem is that the slashes in your date make touch try to create a directory. Since it can't, it complains. The simplest solution is to change your date format. Instead of this: $ date '+%D %R' 06/07/15 13:47 Use this: $ date '+%F %R' 2015-06-07 13:52 Or, even better, avoid having to deal with spaces and use ...


7

@Theophrastus has the right idea. According to POSIX "[t]he characters composing the [file] name may be selected from the set of all character values excluding the slash character and the null byte" (my emphasis). In other words, every string between two slashes (except the empty string) is another directory, and you cannot create a file with a name ...


2

touch can't make directories. For instance see here I see you have "The directory is there." but you do realize that your date format includes "/" characters which would require more directories, yes?



Top 50 recent answers are included