Tag Info

New answers tagged

0

You can use something like this : ls *_$(date +%Y%m%d)_*.txt You don't even need cat, grep, etc...


2

With zsh: $commands[(i)libreoffice?.?] In zsh, $commands is a special associative array whose keys are command names and value their path. i above is an array subscript flag that tells zsh to match the pattern against the array keys and return the first matching key. The elements of the associative array are not in any particular order though, so the ...


0

Here's a simpler alternative: $(compgen -c libreoffice) It assumes bash, and assumes there's only one libreoffice* installed. It emulates what bash tab completion would do if you typed libreofficeTab. If you were deliberately trying to exclude libreoffice without a version number, and want to handle the existence of multiple versions, try: ...


3

Set IFS to : to split the value of PATH on colons. If your find has the -quit action and the -maxdepth primary (e.g. FreeBSD, OSX, GNU), you know the command will exist and you don't care about the command's return code, you can use this one-liner: pattern='libreoffice?.?' IFS=:; find $PATH -maxdepth 1 -type f -name "$pattern" -exec {} \; -quit; unset IFS ...


4

Since you're already using GNU specific syntax (-b): du -abd1 maybehere*/ That way, it's du that lists the files in the maybehere* directories (and it doesn't exclude dot files). -d1 limits the reporting of disk usage to one level down (including non-directories with -a). Otherwise, for globs to include hidden files (except . and ..), each shell has its ...


3

Take advantage of brace expansion: du -b maybehere*/{.??,}* I used ?? to do not match .., i.e. parent directory. Alternatively du -b maybehere*/{.[^.],}* Brace expansion is a mechanism by which you can include more files/strings/whatever to the commandline by writing fewer characters. The syntax is {word1,word2,...}, i.e. it is a list of comma ...


0

If you want to just list hidden directories or operate on hidden directories then as Costas said you can use du -b maybehere*/.* This will allow you to operate on hidden files and directories. If you want only hidden directories then you can specify that with du -b maybehere*/.*/


0

POSIXly, when searching for a $PATH'd executable command, you should use command: command -v Write a string to standard output that indicates the pathname or command that will be used by the shell, in the current shell execution environment (see Shell Execution Environment, to invoke command_name, but do not invoke command_name. ... Otherwise, no output ...


0

You can use the command "find" as follows find ./ -name "libreoffice?.?"


3

With zsh: for d (subdir*(/)) mixb $d/*.(dat|d01)([1]) The bash equivalent would be something like: shopt -s nullglob extglob for d in subdir*/; do [ -L "${d%/}" ] && continue set -- "$d"*.@(dat|d01) [ "$#" -eq 0 ] || mixb "$1" done


0

Simple as: cnt=`ls \*.txt 2>/dev/null | wc -l` if [ "$cnt" != "0" ]; then ./script fi wc -l counts the lines in the expanded wildcard.


3

It is good you tagged the question with zsh, since in that shell you can use extensive glob qualifiers including test done on file names: $ ls -1 AAAA* AAAA_2012-10-03_BBBB AAAA_2014-12-28_BBBB AAAA_2015-01-03_BBBB AAAA_2015-02-03_BBBB AAAA_2015-10-03_BBBB $ d1='2014-12-15' $ d2='2015-02-03' $ print -l *(e:'[[ "${${REPLY#*_}%_*}" > "$d1" && ...


5

This wildcard exists in ksh93, bash ≥4.3 (≥ 4.0 if there are no symbolic link to directories in your tree) and zsh. It's spelled **. In ksh93, it needs to be activated first with set -o globstar. In bash, it needs to be activated first with shopt -o globstar. ls -l src/**/foobar/**/*.java This won't do to make the copy, though. The target of cp is a ...



Top 50 recent answers are included