Tag Info

New answers tagged

0

Regex aren't involved here. Wildcards in bash (like most other shells) only match files based on the file names, not based on the file type or other characteristics. There is one way to match by type: adding / at the end of the pattern makes it only match directories or symbolic links to directories. This way, you can move directories, then move what's left, ...


3

You could use something like find . -maxdepth 1 \( ! -type d \) -exec sh -c 'mv "$@" MYDIR' _ {} \; First we use find to look only within the current directoy, then we ignore directories by using ! -type d finally we execute sh and move everything to the destination dir. You might try {} + at the end which will be faster.


0

Maybe it can get shorter exts=( *.jpg *.png *.gif ); printf "There are ${#exts[@]}" extensions;


4

I'd suggest a different approach, avoiding the possible word-splitting issues of ls #!/bin/bash shopt -s nullglob for ext in jpg png gif; do files=( *."$ext" ) printf 'number of %s files: %d\n' "$ext" "${#files[@]}" # now we can loop over all the files having the current extension for f in "${files[@]}"; do # anything else you like with ...


2

My approach would be: List all files in the directory Extract their extension Sort the result Count the occurrences of each extension Sort of like this: ls | awk -F . '{print $NF}' | sort | uniq -c | awk '{print $2,$1}'


2

If I understand right, you want to process files with other extension, instead of only jpg. So you can try: for a in *.{jpg,JPG,png,PNG,bmp,BMP} do echo $a # do your stuff here done {...} is bash feature called brace expansion.


1

While Michael Homer already wrote what happened, here's why it happened (given your comment on his answer I think you already know, but others coming across this question might not). The command you issued was ls -al /usr/lib/*valgrind* The stars are interpreted by the shell even before ls is executed, by replacing it with a list of filenames matching ...


7

This output: $ ls -al /usr/lib/*valgrind* drwxr-xr-x 2 root root 4096 Sep 30 00:01 . drwxr-xr-x 24 root root 12288 Sep 30 00:00 .. -rwxr-xr-x 1 root root 1816444 Jun 6 2014 cachegrind-x86-linux indicates that there is a directory named /usr/lib/*valgrind* (most likely just /usr/lib/valgrind) which you're ...


0

I think the only thing you're missing is to initially include all directories leading to the archive dirs, ie. also --include='*/'. This is because excluding a directory (with '*') excludes everything below it rsync --include='*/' --include='**archive/***' --exclude='*' -avzh /xx/inbound/ /yy/inbound Apart from that, you shouldn't need 2 sets of '-avzh'


-1

You could do this: http://www.projectik.eu/index.php/programovanie/linux/item/243-linux-kopirovanie-suborov-vo-vlakne Here is example


2

My suggestion: GLOBIGNORE=$(echo */) # create list of directories with globbing GLOBIGNORE=${GLOBIGNORE//:/\\:} # escape possible ":" with "\" to allow # the separator ":" in directory names GLOBIGNORE=${GLOBIGNORE//\/ /:} # replace "/ " with separator ":" GLOBIGNORE=${GLOBIGNORE%/} # remove trailing "/" ...


2

This should really be a comment, but I don't have enough points. That said - I'm not sure which of the 2 options to you want to achieve - bash globing that excludes based on filesystem attributes, or a way to display only files in a directory? If the first, I'm not sure that's possible. Globing just expands, and filenames are a base in any directory - bash ...


5

The reason */ matches directories is that the final / restricts matches to directories. This effect is only triggered when the / is after a pattern, you can't use / inside parentheses in !(*/). There's no feature built into bash to do what you want. You can make a loop over all files and build an array. non_directories=() for x in *; do [ -d "$x" ] || ...


6

find . -maxdepth 1 ! -type d Details: -maxdepth 1 restricts the search to the current directory ! -type d eliminates directories


3

Sort of long winded, but: for f in *; do if [ ! -d "$f" ]; then echo "$f"; fi; done -d is a file test operator to check if the argument is a directory. The above could also be shortened to for f in *; do [ ! -d "$f" ] && echo "$f"; done


3

you could use: find . -type f ! -name "*.*" the ! negates the following expression, here a filename that contains a '.' you can also use the -maxdepth option to reduce the search depth.


1

You can try to use find -D tree . [expr..] to understand what find does with your original command. You must understand that the -type f and also the -exec ls .. expressions are and'ed to the rest of the expressions with higher precedence than the ors. So your original command will get parsed into something like this: (-type f AND -name *.c) OR -name *.h OR ...


2

With GNU find, you can use -regex option: find . -type f -regex '.*\.\(c\|h\|cpp\)' -exec ls {} \;


2

Try adding the expressions into parentheses as stated in the man page: find . -type f \( -name '*.c' -or -name '*.h' -or -name '*.cpp' \) -exec ls {} \; should work.


1

Another way: $ noglob rsync server:/var/log/foo/2014-07-06-*.log . From zsh man page: noglob Filename generation (globbing) is not performed on any of the words.


2

You need to escape the special characters, e.g. $ rsync server:/var/log/foo/2014-07-06-\*.log . or $ rsync 'server:/var/log/foo/2014-07-06-*.log' . Or better, install url-quote-magic, e.g. autoload -Uz url-quote-magic zle -N self-insert url-quote-magic zstyle ':urlglobber' url-other-schema http https ftp mailto so that zsh will automatically do this ...



Top 50 recent answers are included