Tag Info

New answers tagged

1

The multi-line answers above didn't suit my desire for a one-line solution and not modifying the environment. Here is a generic one-liner that may work for you: echo $(ls FOO* 2>/dev/null | wc -w) the /dev/null is because ls throws an error if there's no file. This just ignores ls and counts the number of files found based on the number of "words" ...


2

Thanks to goldilocks for help, using -maxdepth solved my issues. The problem was that I was giving -maxdepth after -path. The following syntax works as expected: find . -maxdepth 1 -path \*/pages/*/index.css


0

Make some fake test files: (only for this example) $ touch filename_{1000000000..1000000099..5}.gz Grab a "time" range of files from ls output and pass this to echo: $ echo $(ls | awk -F'[_,]' '1000000044<=$2 && $2<=1000000066') filename_1000000045.gz filename_1000000050.gz filename_1000000055.gz filename_1000000060.gz ...


0

Not as simple, but my 'weapon of choice' python my_mrjob.py $( for f in {1413324000..1413410400}; do [ -f filename_$f.gz ] && echo $f; done ) PS: IMHO, the python job itself should be modified to allow for range entry, with additional intelligence to skip over non existent files. Will be much faster and simpler. The {a..b} syntax is not a lazy ...


11

shopt -s extglob echo rm foo.!(org) This is "foo." followed by anything NOT "org" ref: https://www.gnu.org/software/bash/manual/bashref.html#Pattern-Matching


1

Use the range operator: echo {1413324000..1413324199}.gz Similarly, $python my_mrjob.py {1413324000..1413324199}.gz If files are not there for every milli second: $python my_mrjob.py $(ls {1413324000..1413324199}.gz 2>/dev/null)


-1

I assume this is done in bash. To keep iterating with files with spaces you need to set IFS variable (see bash man). IFS=\n And iterating with following command will list dot files as well. for file in $(ls -A); do echo $file; done


3

You just need to create a list of glob matching files, separated by space: for file in .* *; do echo "$file"; done Edit The above one can rewrite in different form using brace expansion for file in {.*,*}; do echo "$file"; done or even shorter for file in {.,}*; do echo "$file"; done Adding path for selected files: for file in /path/{.,}*; ...


0

Look for man pages As you are searching commands, instead of matching the names of the command binaries, you could match names of man pages as an alternative; This could make sense because man already provides this feature by default: $ man --sections=1,8 --where --all --regex '^mkdi' /usr/share/man/man1/mkdir.1.gz /usr/share/man/man1/mkdirhier.1.gz ...


1

You should be able to do it like so: $ cp -r /path/to.cms_drupal_PROJ-1-*/html /var/www/. That will enlist a glob using * for the unknown character. You could also use a range like this: $ cp -r cms_drupal_PROJ-1-[0-9]/html var/www/


0

Use zsh and type what comes next. ZSH supports fuzzy auto complete and can deal with it. (Its especially nice with the OH-MY-ZSH plugin.)


1

I don't use fish, but the documentation says that you can enter a Unicode character by prefixing its hex character code with \u (for 16-bit characters) or \U (for 32-bit characters). I think the code for ♫ is 491eb, so you could do: mv \U000491ebabc.mp3 abc.mp3 to rename ♫abc.mp3. Note that you need the leading zeroes, otherwise abc at the end will be ...


4

Rename symlinks One approach to handle file names with special characters - as first characters or elsewhere in the filename is to rename to simpler names. This can be used even if you need to keep the original filenames: Rename a copy of the filenames. That can be done by copying the files, but also by creating symlinks or hardlinks to the files, and ...


1

If you do not wish to change your script you can also use xargs (considering you have it or it's available on your platform) by running it like this: ls *.txt | xargs -L1 ./remove_cc xargs is a utility that takes stdin and transforms it to command parameters on a command to be run. It has the -L flag that limits the amount of input lines to be used in a ...


5

When you type ./remove_cc *, the shell changes it to ./remove_cc file1.txt file2.txt file3.txt etc, and runs your script that way. Your script is only looking at $1, the first parameter (file1.txt). The most general way to do this is to loop over each parameter in turn. "$@" expands to the list of all the parameters, and we can use for to loop over them. ...


6

just use for x in * do ./remove_cc $x done By the way, you can combine all sed in one line sed -i \ -e 's/@r//g' -e 's/@g//g' -e 's/@y//g' -e 's/@b//g' \ -e 's/@m//g' -e 's/@c//g' -e 's/@n//g' -e 's/@R//g' \ -e 's/@G//g' -e 's/@Y//g' -e 's/@B//g' -e 's/@M//g' \ -e 's/@C//g' -e 's/@N//g' -e 's/@W//g' -e 's/@K//g' \ $1 you can ...


1

Use "$@" instead of $1. Or quote the wildcard: $ bash -c 'echo $1' 'some command' '*' file1 file2 $ bash -c 'echo "$@"' 'some command' * file1 file2


0

You didn’t say whether you want to keep these problematic filenames.  One solution might be to “fix” the problem once and for all by renaming (some or all of) your files to names that you can type by running this script: #!/bin/sh for old in * do printf "%s ...? " "$old" if read new && [ "$new" != "" ] then mv -i ...


6

ls has some switches (like --quote-name, --escape, --literal) for dealing with unprintable characters, but in this case it seems the character is "printable" but not "typeable" (at least on my keyboard!), so none of these switches seem to help. Therefore, as a general "brute force" approach to get rid of files with any characters in their names, you can do ...


4

The simplest that occurs to me is ls [^a-zA-Z0-9]* and it does the trick for me, but terdon's answer is better in bringing attention to the extglob shell option or even a shell-independent approach.


5

A similar approach would be to list all files that don't begin with "normal" characters. In bash you can do this with $ shopt -s extglob $ ls !([[:alpha:]]*) However, that does not seem to be available to fish, so you could use find instead: $ find . -type f -not -name '[[:alpha:]]*'


33

If the first character of file name is printable but neither alphanumeric nor whitespace you can use [[:punct:]] glob operator: $ ls *.txt f1.txt f2.txt ♫abc.txt $ ls [[:punct:]]*.txt ♫abc.txt


0

It's possible the problem lies on an improper passing of the path with wildcard character by the duplicity to the rsync. Look at the example below. This is the real example of passing excludes to the rsync by an environment variable within a script: EXCLUDES="--exclude=/etc/blkid.tab --exclude=/root/dir1 --exclude='*.sql'" Notice that quotation marks '' ...


2

If I correctly understand your question the answer is very simple: mv crust.etcMC* /home/out or if etc is not literal string, but for example any three characters then: mv crust.???MC* /home/out



Top 50 recent answers are included