Tag Info

Hot answers tagged

12

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).


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 ...


7

~/.lo-rcs/common/* matches all the non-hidden files in that directory, if there are no files in that directory or all of them are hidden, the pattern evaluates to itself resulting to your error message. There is no good reason to make those files hidden. - Just rename them and everything works as expected. If you really want those files to be hidden, than ...


7

FILEPATH_WITH_GLOB="/home/user/file_*" Now, FILEPATH_WITH_GLOB contains /home/user/file_* FILENAME=$(basename "$FILEPATH_WITH_GLOB") FILENAME contains file_*. echo $FILENAME #file_1234 $FILENAME being unquoted in list context, that expansion undergoes the split+glob operator, so that's expanded to the list of matching file: ...


5

A POSIX one, can handle file which contain newline in filename: find . -name 'Task.??*.store.log' -exec rm -f {} +


4

Do an experiment! Run echo grep .* newfile What can you conclude from the result? How does the result change when you quote (place in single or double quotes) the first argument to grep? If you want the straight dope on this, read the POSIX spec for Pathname Expansion. Knowing everything about the various expansions will turn you into a shell guru in no ...


4

This seems to me like the most straightforward way to find a file of four bytes: find /tmp -type f -size 4c Edit: to find a file name of four bytes: find /tmp -type f -name '????'


4

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

find . -name 'Task.??*.store.log' | xargs rm -f


3

You need to execute lynx once per file, to produce separate output files. To do something over multiple files in sequence, use a for loop. The pattern *.html matches all files in the current directory whose name ends with .html. for x in *.html; do … done In each run through the loop, the variable x designates the current file name. Use "$x" to refer to ...


3

There's also a perl (5.10 or newer) solution: perl -E 'say for </tmp/????>;' A slightly more flexible version where you can specify the desired length: perl -E 'my $w = "?" x shift; say for </tmp/$w>;' 4


2

In the shell, you need to distinguish filename generation/expansion (aka globbing): a pattern that expands to a list of files from pattern matching. globbing uses pattern matching internally, but it's really before all an operator to generate a list of files based on a pattern. */*.txt is a pattern which matches a sequence of 0 or more characters followed ...


2

"/tmp/" takes 5 characters. That's why there is "9" (5+4) in test for i in /tmp/* ; do [ "${#i}" -eq 9 ] && printf %s\\n "$i"; done or for i in /tmp/* ; do i="${i#/tmp/}"; # to get rid of /tmp/ [[ "${#i}" -eq 4 ]] && printf %s\\n "$i"; # there is 4 in test! done FWIW. It does not fail on newline (@cuonglm), can be easilly ...


2

Assuming you're using bash, you can do the following: shopt -s globstar shopt -s nullglob filearray=(/tmp/**/????) This will put the list of files you want in an array filearray. Newlines (and other exotic characters) in the filename will be handled correctly. Setting globstar enables ** in glob patterns to match across subdirectories, giving the ...


2

The command Forward=*R1*.at.fastq sets the variable Forward to the string *R1*.at.fastq (star, capital R, digit 1, star, dot, lowercase A, etc.). Wildcards are only expanded in contexts that allow multiple words; the right-hand size of a variable assignment expects a single word, so no wildcard expansion occurs. In a command like cat $Forward, the wildcards ...


2

With zsh: setopt extendedglob # if not already in ~/.zshrc rm Task.<10->.store.log To avoid the arguments list too long: autoload zargs # best in ~/.zshrc zargs Task.<10->.store.log -- rm


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


1

( set ./*.html; [ -f "$1" ] || exit printf 'eval "$L;shift" >"${1%%%.0s.*}.txt"\n' "$@" | L=' lynx "$1" --force-html --dump' sh -eCs "$@" ) &



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