Tag Info

New answers tagged

-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


3

Yes characters can be arranged lexically between 2 and q. Do an ls /bin and you'll see the numerics come before the letters. In fact you can do ls /bin/[2-q]* and see for yourself exactly what happens. Lexical sorting in the "C" locale is by ASCII value, so '2' is 32 decimal, and 'q' is 71. Do a man ascii to see the whole ASCII table. Perhaps you meant to ...


10

Brace expansion will get the job done. man bash and search for Brace Expansion. cp *.{txt,jpg,png} destination/ EDIT: In keeping with the OP's request, the command above was missing the verbose option: cp -v *.{txt,jpg,png} destination/


2

In addition to vinc17's suggestion, you can use --include combined with -r option, something like: grep -r --include \foo some_pattern /path/to/dir/*.


4

This isn't du resolving the symbolic links; it's your shell. * is a shell glob; it is expanded by the shell before running any command. Thus in effect, the command you're running is: du -s /data/ghs/14 /data/ghsb/14 /data/hope/14 /data/rssf/14 /data/roper/14 If your shell is bash, you don't have a way to tell it not to expand symlinks. However you can ...


3

Use zsh. In the zshexpn(1) man page, Section "Recursive Globbing": A pathname component of the form '(foo/)#' matches a path consisting of zero or more directories matching the pattern foo. As a shorthand, '**/' is equivalent to '(*/)#'; note that this therefore matches files in the current directory as well as subdirectories. [...] This ...


0

This works as you expected in these versions of Bash as supplied with the listed distributions: 4.1.2(1) (CentOS 6.5) 4.1.5(1) (Debian 6.0.10) 4.1.10(4) (Cygwin 1.7.31) 4.3.11(1) (Ubuntu 14.04.1) In fact the versions listed above are all that I tested. I.e. I did not find a version of Bash where it does not work. 1. dir/**/*.ext matches dir/file.ext: ...



Top 50 recent answers are included