Berkeley CSUA MOTD:Entry 32985
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
2025/07/09 [General] UID:1000 Activity:popular
7/9     

2004/8/18 [Computer/SW/Unix] UID:32985 Activity:very high
8/17    How can one match wildcards '*' with files that start with a '.' in
        bash and tcsh?
        \_ .[^.]* works for most cases, but will not match "..foo"
        \_ ls -A1 | grep '^\.'
        \_ ls * .*
        \_ i personally prefer .??* .
        \_ ls `find . -type f -name .\*`
        \_ ls `find . -type f -name .\*`, although it's not using the wildcard
           facility in the shells.
           \_ this will traverse down the directory tree.  this behavior
              would be different from what the others do and may or may not
              be desirable.
              \_ Use this then: echo `find . -type f -name .\* -maxdepth 1`
                 \_ At this point, what do you gain by using find?  It would
                    be better if you were tall enough to use xarg or even
                    -exec.  There would still be no point in using find though.
                    \_ Example without using "find" please?
                       \_ from above, .* or .??*
                          \_ ".*" will always exclude the parent directory
                             because ......?  And ".??*" will still work if
                             there's a file named ".f" because ......?
                             \_ % echo .*
                                . [deleted] .. [deleted]
                                % echo .?*
                                [deleted] .. [deleted]
                                Try it yourself.  Whether you want . depends
                                on what you'd want to do with the results,
                                I'd guess.
                             \_ BTW, ls `find [...]` should choke on file
                                names with a space.  Probably other things too.
                                \_ Yes it does, but as in my -maxdepth example
                                   above I already switched to echo `find ...`.
                                   \_ echo only works because it doesn't use
                                      the result of the find to touch the
                                      file system.  your examply `find [...]`
                                      will fail any time someone tries to do
                                      that, so it's not a complete solution,
                                      as well as being one wasteful of system
                                      resources.  again, i urge you to learn
                                      either xargs or -exec.  preferably xargs,

                                      but like partha likes to say, you have
                                      to be this tall to use xargs.
                                      \_ Your example ".*" will fail even when
                                         no one tries to "touch the file
                                         system."  (By "touch the file system"
                                         I suppose you meant accessing the
                                         files afterwards using the match
                                         result, since expanding filename
                                         wildcards already requires touching
                                         the file system.
                                         \_ % mkdir ".try this"
                                            % ls -d .*
                                            ./  ../  .try this/
                                            you have access to a csh?  show me
                                            where it fails.
                                            \_ Again, . and .. are not files.
                                               \_ again,
                                                  % od .
                                                  % od ..
                                                  \_ % cd /
                                                     % which od
                                                     /usr/local/bin/od
                                                     % od .
                                                     od: .: Is a directory
                                                     0000000
                                                     % od ..
                                                     od: ..: Is a directory
                                                     0000000
                                                     %
                                                     And you point?
                                                     \_ /usr/bin/od
                                                        obtw,
                                                        % ls /usr/local/bin/od
                                                        ls: /usr/local/bin/od:
No such file or directory
                                                        in any case, i have to
                                                        leave for dinner.
                                \_ Indeed.
                                   % touch "try this"
                                   % ls
                                   try this
                                   % ls `find .`
                                   ls: ./try: No such file or directory
                                   ls: this: No such file or directory
                                   .:
                                   try this
                                   Like I said, I wish you were tall enough
                                   to use xargs or -exec.
                                   \_ You being tall enough to use xargs or
                                      -exec didn't help the fact that your
                                      example doesn't even work in any
                                      directory.  So what's the point.
                                      \_ which example?  i merely copied from
                                         solutions above.  .* does work for
                                         all files, including . and .. .
                                         .?* will exclude ., which is perhaps
                                         nice.
                                         \_ Excuse me?  . and .. are not files,
                                            are they?
                                            \_ sure they're not files.
                                               \_ obtw,
                                                  % od .
                                                  % od ..
           \_ also xargs, but you have to be this tall to use it.
        \_ this task is trivial if you use 'set noglob'.
2025/07/09 [General] UID:1000 Activity:popular
7/9     

You may also be interested in these entries...
2012/4/27-6/4 [Computer/SW/Languages/Misc, Computer/SW/Unix] UID:54372 Activity:nil
4/27    I wrote a little shell script to collect iostat data:
        #!/bin/bash
        DATE=`date +%m%d`
        DATADIR=/var/tmp/user
        OUTPUTFILE=$DATADIR/$DATE.out
        while true
	...
2011/10/26-12/6 [Computer/SW/Unix] UID:54202 Activity:nil
10/24  What's an easy way to see if say column 3 of a file matches a list of
       expressions in a file? Basically I want to combine "grep -f <file>"
       to store the patterns and awk's $3 ~ /(AAA|BBB|CCC)/ ... I realize
       I can do this with "egrep -f " and use regexp instead of strings, but
       was wondering if there was some magic way to do this.
       \_ UNIX has no magic. Make a shell script to produce the ask or egrep
	...
2011/3/12-4/20 [Consumer/CellPhone, Computer/HW/Laptop] UID:54057 Activity:nil
3/12    I am curious what others think of tablets like iPad. They don't seem
        useful to me, but I use my computer for more than web browsing,
        Facebook, and Twitter. Why would I buy one instead of a laptop?
        They seem like a disabled laptop to me, but at a higher price.
        \_ You are most likely a coder.  iPad is not for coders.  They are
           what you get your non-technical friends.  Or musicians.  Look at
	...
2011/2/6-19 [Computer/Networking] UID:54028 Activity:nil
2/5     hmm.
$netstat -at | grep LISTEN
tcp        0      0 *:43300                 *:*                     LISTEN
        \_ this is an sshd
tcp        0      0 *:49416                 *:*                     LISTEN
tcp        0      0 *:36201                 *:*                     LISTEN
	...
2009/12/9-2010/1/13 [Computer/SW/Unix] UID:53586 Activity:nil
12/8    Is there a bash equivalent to tcsh's history-search-backward ?
        \_ There's something similar called... history-search-backward. It
           is a bit more limited, in that it only searches for strings and
           not glob patterns. You may find reverse-i-search to be useful also.
	...
2009/10/27-11/3 [Computer/SW/Unix] UID:53475 Activity:nil
10/27   http://www.maxgames.com/play/flash-mind-reader.html
        how does this work?
        \_ sh -c 'for ((i=0;i<10;i++)); do for ((j=0;j<10;j++)); do echo "$i$j-(\
$i+$j)" | bc; done ; done' | uniq
        \_ bash -c 'for ((i=0;i<10;i++)); do for ((j=0;j<10;j++)); do echo "$i$j\
-($i+$j)" | bc; done ; done' | uniq
	...
2009/8/18-9/1 [Computer/SW/Unix] UID:53284 Activity:nil
8/18    Is it possible to truncate your path name in your prompt in tcsh?
        Tsch veterans REPRESENT!  I know this is how to do it in bash:
        # truncate path: returns $1 truncated to $2 chars, prefixed with ...
        truncate_path () {
                if [ -z "$1" -o -z "$2" ]
                then
	...
2009/8/19-9/1 [Computer/SW/Unix] UID:53285 Activity:nil
8/18    Hi again, new freebsd guy here again, in bash I was able to go
        LD_LIBRARY_PATH=/opt/foo/lib ./runmyapp
        I managed to do this in tcsh by using setenv in a shell script
        that setenv's the lib path and then executes $1, just wondering
        if there was a way to do it in 1 line from the cmd line as in bash?
        Thanks, btw %2c or %3c worked.  Freebsd, tcsh and vi forever!
	...
2009/1/25-29 [Computer/SW/Unix] UID:52456 Activity:low
1/23    may the awesome rootstaff please apt-get install:
        colorgcc, colordiff, colormake
        thanks!
        \_ Done.  In the future email such requests to root@csua for
           faster response
           \_ totally, understood.  Altho yeah I do like asking for
	...
2009/1/5-8 [Computer/SW/Unix] UID:52313 Activity:kinda low
1/3     no hurry but do you know of:
        $ chsh
        Password:
        Enter the new value, or press return for the default
         Login Shell [/usr/local/bin/bash]: /bin/zsh
        failed: Insufficient access
	...