Any Reason for Using "*/" in Command "Ls -D */" to List Directories

Any reason for using */ in command ls -d */ to list directories?

Adding the -d flag simply instructs ls to simply list directory entries rather than their contents. The * given to ls is expanded to all the entries in the current directory, both files and dirs. So ls -d * will list all entries in this directory, without expanding the subdirectories. But if you use */, then bash expands this to only include the directories in this directory. But with just ls */, all the directories will be expanded. Adding the -d flag prevents that, and you get just the directories in this directory.

Listing only directories using ls in Bash?

*/ is a pattern that matches all of the subdirectories in the current directory (* would match all files and subdirectories; the / restricts it to directories). Similarly, to list all subdirectories under /home/alice/Documents, use ls -d /home/alice/Documents/*/

Using ls to list directories and their total sizes

Try something like:

du -sh *

short version of:

du --summarize --human-readable *

Explanation:

du: Disk Usage

-s: Display a summary for each specified file. (Equivalent to -d 0)

-h: "Human-readable" output. Use unit suffixes: Byte, Kibibyte (KiB), Mebibyte (MiB), Gibibyte (GiB), Tebibyte (TiB) and Pebibyte (PiB). (BASE2)

Need Assistance Understanding ls -d command in linux

The things to understand are:

  • ls lists the current directory, otherwise known as ., by default.
  • ls -d makes ls show the directory it's listing, not that contents of that directory.

The behaviors you describe all follow from that:

  • ls -d showing . is showing the directory you're in -- the default target of ls with no arguments given.
  • ls -d */ tells your shell to run ls with each directory under the current one passed as an argument; ls -d then shows the entries for each of its arguments, behaving as you report.
  • ls -d * tells your shell to run ls with each entry in the current directory passed as an argument. ls then lists one entry for each such argument, not showing the contents of each argument which is a directory name as it otherwise would.

No such file or directory but it exists

This error can mean that ./arm-mingw32ce-g++ doesn't exist (but it does), or that it exists and is a dynamically linked executable recognized by the kernel but whose dynamic loader is not available. You can see what dynamic loader is required by running ldd /arm-mingw32ce-g++; anything marked not found is the dynamic loader or a library that you need to install.

If you're trying to run a 32-bit binary on an amd64 installation:

  • Up to Ubuntu 11.04, install the package ia32-libs.
  • On Ubuntu 11.10, install ia32-libs-multiarch.
  • Starting with 12.04, install ia32-libs-multiarch, or select a reasonable set of :i386 packages in addition to the :amd64 packages.

Linux command to print directory structure in the form of a tree

Is this what you're looking for tree? It should be in most distributions (maybe as an optional install).

~> tree -d /proc/self/
/proc/self/
|-- attr
|-- cwd -> /proc
|-- fd
| `-- 3 -> /proc/15589/fd
|-- fdinfo
|-- net
| |-- dev_snmp6
| |-- netfilter
| |-- rpc
| | |-- auth.rpcsec.context
| | |-- auth.rpcsec.init
| | |-- auth.unix.gid
| | |-- auth.unix.ip
| | |-- nfs4.idtoname
| | |-- nfs4.nametoid
| | |-- nfsd.export
| | `-- nfsd.fh
| `-- stat
|-- root -> /
`-- task
`-- 15589
|-- attr
|-- cwd -> /proc
|-- fd
| `-- 3 -> /proc/15589/task/15589/fd
|-- fdinfo
`-- root -> /

27 directories

sample taken from maintainer's web page.

You can add the option -L # where # is replaced by a number, to specify the max recursion depth.

Remove -d to display also files.

Find all files with name containing string

Use find:

find . -maxdepth 1 -name "*string*" -print

It will find all files in the current directory (delete maxdepth 1 if you want it recursive) containing "string" and will print it on the screen.

If you want to avoid file containing ':', you can type:

find . -maxdepth 1 -name "*string*" ! -name "*:*" -print

If you want to use grep (but I think it's not necessary as far as you don't want to check file content) you can use:

ls | grep touch

But, I repeat, find is a better and cleaner solution for your task.

How can I list only directory names, with no trailing /?

There are several options. You can use the tree command with the options:

# d: list only directories
# i: no print of indention line
# L: max display depth of the directory tree
tree -di -L 1 "$(pwd)"

Or you can also use the grep command to get the directories and the command awk:

# F: input field separator
# $9: print the ninth column of the output
ls -l | grep "^d" | awk -F" " '{print $9}'

Or you can use the sed command to remove the slash:

# structure: s|regexp|replacement|flags
# g: apply the replacement to all matches to the regexp, not just the first
ls -d */ | sed 's|[/]||g'

I found this solutions in this post.



Related Topics



Leave a reply



Submit