Tag Info

New answers tagged

1

This has nothing to do with man pages themselves: it's a description of the syntax of glob patterns, which the man page you're looking at is about. In a glob pattern, brackets delimit a character set. For example [abc] matches any of the characters a, b or c. The pattern fo[abc] matches foa, fob and foc (but not e.g. foo, or fo, or foab). Inside the ...


4

As explained in the beginning of that paragraph in that man page, '-' character, when put between two characters, represents a range of characters, and also, '-' character, when put as first or last character between brackets, has its literal meaning. So, the first dash really means a '-' character, and the second dash is a range specifier. So the whole ...


0

I think you want to search for those files that start with data and then following by any three character (XXX) which is ends with .csv, right? So you can use grep with find command: find . -maxdepth 1 -type f -printf "%f\n" |grep -c '^data...\.csv$' . refer to current directory. -maxdepth 1 looking for files only in current directory(maximum 1 level). ...


0

Using find to test that they are a file (-type f) and match the required pattern ("data*.csv"): find directory/ -type f -name "data*.csv" | wc -l


0

There are probably fancier ways, but what works for me is ls /directory/data* | wc -l


7

rm [0-9][0-9].* will do it for files in the current directory (no quotes — you want to match files). The . doesn't need to be escaped, because this is a shell glob and not a regular expression (if it were a regex, that would be a wildcard). If you are looking to do this recursively, find is probably your best bet.


5

Recursively : find . -type f -name '[0-9][0-9].*' -delete require GNU find, or : find . -type f -name '[0-9][0-9].*' -exec rm {} \;


4

If you have two zip files a.zip and b.zip in your current directory, then $ cp *.zip destination/ expands to $ cp a.zip b.zip destination/ The semantics for cp is to copy both a.zip and b.zip to destination. If you type $ cp \*.zip destination/ it simply "expands" to $ cp '*.zip' destination/ i.e. it will try to copy a single file named "*.zip" ...


2

On the contrary, unzip does too much. cp doesn't need to parse the filenames, all it needs to do is loop over them. Unzip, on the other hand, needs to see if an argument is a wildcard, check the directory listing to see what matches the wildcard and then loop over those. And note that the shell already is capable of matching and expanding wildcards, so ...


3

Assuming file names don't contain newline characters and don't start with ., this should work: ls -d -- *.sas | grep -v '^qc_d[ltf]' List files ending in .sas and filtering all that is NOT qc_dl, qc_dt, qc_df For any filtering needs, grep is your friend.


7

Use find instead? find /my/example/dir -type f -name '*.sas' ! -name 'qc_d[ltf]*'


8

From man bash: If the extglob shell option is enabled using the shopt builtin, several extended pattern matching operators are recognized. In the following description, a pattern-list is a list of one or more patterns separated by a |. Composite patterns may be formed using one or more of the following sub-patterns: ?(pattern-list) ...


2

GNU sort and xargs might do the trick printf '%s\0' ullman*.pbm | sort -z -k2,2n -t'-' | xargs -0 convert First check this works by listing files without calling convert printf '%s\0' ullman*.pbm | sort -z -k2,2n -t'-' | xargs -0 printf '%s\n' ullman-000.pbm ullman-001.pbm ullman-098.pbm ullman-099.pbm ullman-100.pbm ullman-1000.pbm ... Whereas ...


1

One way would be to rename the files that have three digit numbers to four digit ones, padded with a zero. If you have perl-rename (installed by default on Ubuntu) you can try: rename -n 's/-(\d{3}\.)/-0$1/' *.pbm Once you're satisfied with the result, run again without the -n. Or see other options in Padding a number in a filename to a fixed length.


1

Why not just... for log in /var/log/*.[1-5] do whatever to "$log" done You don't need find as far as I can tell - the shell uses the same globs it does in -name. And if all of the files are in a single directory... Of course, if there are subdirectories you're also interested in then find could be beneficial - walking trees in the shell can be a headache. ...


1

If you're writing bash code, judicious use of "set -f" to turn off globbing, and "set +f" to turn globbing on might do what you want: #!/bin/bash for i in a b c do set -f Z=$i/*.txt echo $Z set +f echo echo "Does it expand?" echo $Z done


3

In the first case, dump* is interpreted by the shell, and expanded into matching filenames, and then passed to find. In effect, find sees: find dumpa dumpb ... -type f ... In the second case, no interpretation is done by the shell. find does the filtering. Therefore, considering the recursive nature of find, the second method can locate files which the ...


0

You are not using regular expressions correctly. tes* means te with any number of ss following it, so test-file-1 will be renamed to file 1t-file-1: $ rename -n 's/tes*/file 1/' * test-file-1 renamed as file 1t-file-1 Similarly, ^* will match the empty string appearing at the start, so in effect it's like ^, but with a an inifinite loop: $ rename -n ...



Top 50 recent answers are included