Preserve ls colouring after grep’ing

Your grep is probably removing ls‘s color codes because it has its own coloring turned on. You “could” do this: ls -l –color=always | grep –color=never pattern However, it is very important that you understand what exactly you’re grepping here. Not only is grepping ls unnecessary (use a glob instead), this particular case is grepping … Read more

how to `git ls-files` for just one directory level.

(late edit for a feature added in Git 1.8.5, after the question and answer were written:) Git’s pathspecs ordinarily match * with any path substring, including / separators, but you can use shell pathname-matching conventions by adding a magic :(glob) prefix. So to list just the files in the current directory, git ls-files ‘:(glob)*’ # … Read more

Cygwin – command not found

Right click on “My Computer” -> Properties -> Advanced -> Environment Variables Add a new environment variable, called CYGWIN_HOME and set its value to C:\cygwin Edit the PATH environment variable and add %CYGWIN_HOME%\bin to it (usually separated by a ‘;’). Just click okay, exit any command prompts or bash shells (over cygwin) you may have … Read more

How do I capture the output from the ls or find command to store all file names in an array?

To answer your exact question, use the following: arr=( $(find /path/to/toplevel/dir -type f) ) Example $ find . -type f ./test1.txt ./test2.txt ./test3.txt $ arr=( $(find . -type f) ) $ echo ${#arr[@]} 3 $ echo ${arr[@]} ./test1.txt ./test2.txt ./test3.txt $ echo ${arr[0]} ./test1.txt However, if you just want to process files one at a … Read more

How do you determine what bash ls colours mean?

The colors are defined by the $LS_COLORS environment variable. Depending on your distro, it is generated automatically when the shell starts, using ~/.dircolors or /etc/DIR_COLORS. Edit: To list color meanings, use this script: eval $(echo “no:global default;fi:normal file;di:directory;ln:symbolic link;pi:named pipe;so:socket;do:door;bd:block device;cd:character device;or:orphan symlink;mi:missing file;su:set uid;sg:set gid;tw:sticky other writable;ow:other writable;st:sticky;ex:executable;”|sed -e ‘s/:/=”/g; s/\;/”\n/g’) { IFS=: for … Read more

How to `ls` only one level deep?

Try this ls -d H2*/ The -d option is supposed to list “directories only”, but by itself just lists . which I personally find kind of strange. The wildcard is needed to get an actual list of directories. UPDATE: As @Philipp points out, you can do this even more concisely and without leaving bash by … Read more

error code: 521