Tag Info

New answers tagged

2

The argument to a LS_COLORS directive is a string that is written to the terminal as part of an escape sequence. When displaying a file name, ls writes \e[, then the string associated with the file type, then m, then the file name, then \e[0m (where \e represents an escape character). This is the escape sequence that tells xterm and compatible terminals ...


1

When you type C-a l, this runs ls and displays the output in the current window, regardless of what program is running in the window. If you do this with a shell running in the window and the shell is displaying its prompt, then the output of ls is displayed after the prompt. The shell is not aware of what happened, since ls is executed directly by Screen. ...


0

If you are able to use find and if you are working on a "normal Unix filesystem" (that is, as defined in find(1) under -noleaf option description), then the following command can be used: find . -type d -links 2 Each directory has at least 2 names (hard links): . and its name. Its subdirectories, if any, will have a .. pointing to the parent directory, so ...


1

That is because the output of your ls command is just the list of file names, not their path. The truncate command will, therefore, recreate the same file names as empty files in the current directory. In addition, your approach, even if done correctly, will break on even slightly strange filenames (those that contain a space, for example), let alone more ...


0

This will find all files recursively, and sort them by size. It prints out all file sizes in kb, and rounds down so you may see 0 KB files, but it was close enough for my uses, and works on OSX. find . -type f | xargs ls -la | awk '{print int($5/1000) " KB\t" $9}' | sort -n -r -k1


-1

ls -lrth | tail ls -lrth | tail -n 10 ls -lrth | grep *.gz | tail


0

If performance is not the concern (as in the question that was closed as a duplicate of this one), and you want to list the first n files (as opposed to the first n lines of the output of ls) in the list of files sorted by filenames, with zsh, you can use: ls -ld -- *([1,4]) to list the first 4 files. zsh will still read the full content of the directory ...


1

find . ! -name . -prune -print | grep -c / Should be fairly portable to post-80s systems. That counts all the directory entries except . and .. in the current directory. To count files in subdirectories as well: find .//. ! -name . | grep -c // (that one should be portable even to Unix V6 (1975), since it doesn't need -prune)


-1

ls / has been rendered by your terminal, But When you pipe it to wc command, terminal doesn't exists.


2

As POSIX define, ls will output one entry per line if output is not a terminal, or one of -C, -m, -x was used. When output is terminal, the output format is implementation-defined. OSX ls and FreeBSD ls use -1 as default option when output is not to a terminal


2

For this sort of task, I like to break out the perl. There's a module called File::Find which is core, that is quite good for this: #!/usr/bin/perl use strict; use warnings; use File::Find; my %found; sub collate_users { next if -d; my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks ...


2

Here's a slightly shorter version that uses find: find <path> -printf "%u\n" | sort -u Depending on the complexity of the directory structure, this may or may not be more efficient.


1

You can use piped I/O from a command in awk (at least gawk, I haven't tested this on Solaris): find . -type f | xargs ls -l | awk 'BEGIN { OFS="\t" } { command=sprintf("file \"%s\"", $9); command | getline type; close(command); print type, $3, $4 }' | tr ":" "\t" If your find supports it you can simplify this with find . -type f -ls | awk ... There's a ...


0

There are a few ways to approach this. The first is using bash arrays: shopt -s nullglob if [[ -d $foldername ]]; then files=("$foldername"/*) answer="${#files[@]}" else printf '%s does not exist\n' "$foldername" fi If your shell doesn't support arrays, you can loop at count: count=0 for f in "$foldername"/*; do count=$((count + 1)) done ...


0

Thats easy: first of all: it is an entry in a directory listing (e.g. with ls -l). the first block (-rwxr-xr-x) means that it is an ordinary file (the first -) it is readable, writeable and executable by the user (the first triple rwx) it is readable and executable by the group (the second triple r-x) it is readable and executable by anyone (the third ...


0

find lists all the files in the directory tree. ls -R actually lists fewer files: it omits dot files — you need ls -AR to include them. If you aren't finding the files you need, there are a few possibilities: You missed them in the output. Use a search command (e.g. find … | less and use the / key in less). Keep in mind that the output of find is not ...


0

When you execute ls -R you get as output the directories names in the listing.


4

From Fedora /etc/bashrc: for i in /etc/profile.d/*.sh; do if [ -r "$i" ]; then if [ "$PS1" ]; then . "$i" else . "$i" >/dev/null fi fi done And in /etc/profile.d are files in which are defined aliases. ll is defined in /etc/profile.d/colorls.sh


3

Check out type ll to see :) On Fedora you're likely to get something like ll is an alias for ls -l, which would mean that Fedora just comes preconfigured with the same alias you've mentioned.


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 ...


1

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.



Top 50 recent answers are included