Tag Info

New answers tagged

1

In zsh, put setopt extended_glob in your ~/.zshrc. Then you can use the wildcard pattern ^one to exclude the directory called one. ls ^one/*.png If you want to recurse into subdirectories, use **/ for recursive globbing. To exclude the directory called one at the toplevel, as well as the toplevel directory: ls ^one/**/*.png To exclude files in a ...


10

Option 1 - using just ls: With extended bash globbing turned on (shopt -s extglob) you can do: ls !(one*)/*.png Option 2 - combining ls and grep: You can combine ls with grep -v e.g. ls */*.png | grep -v "one/" Option 3 - (the best IMO) but uses find not ls: For recursive searching of all subdirectories using find find . -type f -name "*.png" ...


2

Background reading: Why does my shell script choke on whitespace or other special characters?, Why you shouldn't parse the output of ls Setting IFS to a newline means that only newlines, and not spaces and tabs, will be treated as separators during the expansion of the command substitution. Your method will not support file names that contain newlines; this ...


0

I assume you're refferring to DtTerm. In this case, you're only limited to 16 colors: despite having a nice GUI, DtTerm is inferior feature-wise compared to xterm, rxvt and others. If you want 256 color support in your terminal, pick a recent xterm build (not the one shipped with Solaris). Another option is using gvim with a Motif/Athena/GTK GUI.


1

Do you really mean adding * in filename? Or you mean the output of ls gives filename ending in * if it has execute permission? If only output problem of ls, you could simply solve by: replace ls to \ls, this is to use un-aliased version of ls, which doesn't output *


2

For various reasons related to whitespace issues, etc., it is not advisable to parse the output of ls. An alternative, which uses GNU versions of find, sort, sed: find . -mindepth 1 -maxdepth 1 -printf "%A@ %f\0" | sort -rnz | sed -z 's/^[0-9.]\+ //' find is, of course, much more flexible than ls when it comes to listing and filtering files, but it ...


0

You can use something like this: ls -1Atu | while IFS= read -r entry; do echo "$entry" done With this example, the output is generated once, and the while read entry section causes the output from ls to be parsed line-by-line, which solves the issue with your for example where everything was getting placed in $i in a single round.


3

I think you are looking for the brace expansion {asd,qwe}: $ ls foo.{asd,qwe} foo.asd foo.qwe


2

The globbing pattern would be ls foo.@(asd|qwe). This works out of the box in ksh; in bash also if "extended globbing" is activated with shopt -s extglob; in zsh if ksh-style globs are activated with setopt ksh_glob.


1

The shell will do filename expansion before either command is executed, so the results depends on what is in your current directory. To get what you want, I think you wouldwant to quote the * in the find command. check this example. $# First show all the files $# ~/tmp/stack$ find . . ./dir1 ./dir1/FileA ./dir1/FileB ./dir1/FileC ./dir1/filec ./dir2 ...


0

The findcommand will fail if the initialfilename* expands to more than one files: $ touch initiala initialb $ dir -lrt initial* -rw-rw-rw- 1 user 0 0 2015-04-21 10:17 initialb -rw-rw-rw- 1 user 0 0 2015-04-21 10:17 initiala $ find . -name initial1 find: paths must precede expression: initialb Usage: find [-H] [-L] [-P] [-Olevel] [-D ...


2

The find version will also find files matching that name in subdirectories. Note you should quote or escape the * in the filename pattern; if the pattern matches a file in the local directory it will expand to that name and find will only find exactly that name. If it matches more than one filename then you will get an error because those multiple filenames ...


2

ls -ltr file*: This command just list the contents of the current directory in the long listing format (-l), sorted by modification time (-t) in reverse order (-r) of all files and directories beginning with file*. find ./ -name file*: That command searches trough the whole directory structure under the current working directory and all its subdirectories ...


0

ls -ltr will list the file if it exists in the current directory. find will search for the file recursively (will look for the file in the subdirectories)


0

In addition to Michael Mrozek's answer: On OSX 10.10 (Yosemite) you can have to use these attrx parameters: xattr -l file xattr -w attr_name attr_value file xattr -d attr_name file


0

I had the same question, terdon's answer is nice but I think there is a confusion between dirname and dircolors ? Anyway, after some further research I could change the colors, so I'm sharing my solution here. It may be useful for someone some day ! So, 3 simple steps: First, as terdon said, copy the default colors to a file dircolors -p > ...


1

You cannot parse the output of ls, let alone ls -l because newline, just like space is as valid a character as any in a filename. Also, you'll need to consider symlinks that have an output like ... foo -> bar. Why would you use -l anyway if you only want the file name? Just do: for file in *; do ... done If you want to include dot files, depending ...


1

As others have already noticed, there are two problems with your approach. They have nothing to do with .zip vs .sh files, but with the names and locations of the files. You need to put double quotes around command substitution. Otherwise they break at space characters. See Why does my shell script choke on whitespace or other special characters? for more ...


0

Replace --color with -G when running ls.


1

It's because it depends from where you execute your cp. In your example, ls -tr1 /Users/Me/Whatever will return only website3.zip. If you run your cp from /tmp, then it will try to find the file /tmp/website3.zip. To let ls display the full path, you should use the wildcard *. Depending on what you want, it may be useful to specify -d option to not let ls ...


2

Run this: cp -p "`ls -dtr1 /Users/Me/Documents/Coffi\ Work/FTP\ Backup\ Shell\ Script/Original/* | tail -1`" /Users/Me/Documents/Coffi\ Work/FTP\ Backup\ Shell\ Script/Backup1/ Here we have added -d option os ls to get the absolute path. In your command, as ls is not returning absolute paths, you must run that from the source directory to get the file ...


2

It is the back tick quotes. They tell the shell to run the output of the command. e.g. `echo ls` will run ls. In your case you have asked bash to run the sql files. This is obviously not what you intended, as bash can not do this, the sql will not make sense to bash. Also, even with this fix, the script will not do what you describe. Someone else ...


1

To "loop through a bunch of [.sql] files and get their names" you'd just do: for f in *.sql do do_whatever_with_file "$f" done If you just want to list the files: ls *.sql If you want to test whether there are *.sql files existing, for example: if ls *.sql >/dev/null 2>&1 then echo sql files existing else echo no sql files fi


1

Please take what it follows only as hints to stimulate to your fantasy. You can set up your bash function or alias with one or more of the following ideas. Text B/W As pointed out by mikeserv you can use printf %020d to introduce a big skip before the output of ls. alias Ls0='printf %050d|tr 0 \\n; ls -la' Moreover you can custom it with some ...



Top 50 recent answers are included