Skip to main content
added 19 characters in body
Source Link
Chris Davies
  • 128.1k
  • 16
  • 179
  • 324

Aliases don't use or even understand parameters such as "$@", so immediately you will need to use a function or script. Here's one implementation:

lsfc() {
    local x=$(ls -lq -- "$@" );
    local n=$(wc -l <<<"$x");
    printf "%s\nFile count: %d\n" "$x" "$((n-1))"
}

Be aware that the "file" count is actually a count of the lines from ls less one. So if you have a pathological file name that contains a newline ls -l will count twice. Here we did this by including the -q flag (see man ls, GNU versions in particular)

Aliases don't use parameters such as "$@", so immediately you will need to use a function or script. Here's one implementation:

lsfc() {
    local x=$(ls -lq "$@" );
    local n=$(wc -l <<<"$x");
    printf "%s\nFile count: %d\n" "$x" "$((n-1))"
}

Be aware that the "file" count is actually a count of the lines from ls less one. So if you have a pathological file name that contains a newline ls -l will count twice. Here we did this by including the -q flag (see man ls, GNU versions in particular)

Aliases don't use or even understand parameters such as "$@", so immediately you will need to use a function or script. Here's one implementation:

lsfc() {
    local x=$(ls -lq -- "$@" );
    local n=$(wc -l <<<"$x");
    printf "%s\nFile count: %d\n" "$x" "$((n-1))"
}

Be aware that the "file" count is actually a count of the lines from ls less one. So if you have a pathological file name that contains a newline ls -l will count twice. Here we did this by including the -q flag (see man ls, GNU versions in particular)

Source Link
Chris Davies
  • 128.1k
  • 16
  • 179
  • 324

Aliases don't use parameters such as "$@", so immediately you will need to use a function or script. Here's one implementation:

lsfc() {
    local x=$(ls -lq "$@" );
    local n=$(wc -l <<<"$x");
    printf "%s\nFile count: %d\n" "$x" "$((n-1))"
}

Be aware that the "file" count is actually a count of the lines from ls less one. So if you have a pathological file name that contains a newline ls -l will count twice. Here we did this by including the -q flag (see man ls, GNU versions in particular)