List sub-directories with ls
This should help:
ls -d */
*/
will only match directories under the current dir. The output directory names will probably contain the trailing '/' though.
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)
How to ls all the files in the subdirectories using wildcard?
3 solutions :
Simple glob
ls */*.pdb
Recursive using bash
shopt -s globstar
ls **/*.pdb
Recursive using find
find . -type f -name '*.pdb'
How do I list all the files in a directory and subdirectories in reverse chronological order?
Try this one:
find . -type f -printf "%T@ %p\n" | sort -nr | cut -d\ -f2-
List of All Folders and Sub-folders
You can use find
find . -type d > output.txt
or tree
tree -d > output.txt
tree
, If not installed on your system.
If you are using ubuntu
sudo apt-get install tree
If you are using mac os
.
brew install tree
ls -lR * lists all the files in current and subdirectories , but ls -lR *filename* does not list files in subdirectories
According to the man page ls lists information about the filenames specified. The shell (bash, sh, zsh etc) expands the * to a list of filenames, so the command being execute is
ls -lR filename1 filename2 filename3 ...
If one of those filenames is a directory then ls will list it recursively.
In your second case
ls -lR filename
If that filename is the name of a directory, ls will list the contents of the directory recusively, otherwise it will give you details of the file.
To do what you want you will need to do
ls -lR | grep filename
Or use find as you say
How to show subdirectories using SFTP ls command
If there is only one subdirectory I get nothing.
You should only get nothing if the only one subdirectory is empty, because ls
if given a single directory argument lists its contents. With the normal ls
we could solve this problem simply by means of the option -d
, but unfortunately sftp
's ls
doesn't have that option. The only way coming to my mind is to filter the desired directories from a long listing:
echo "ls -l /path/to/folder" | sftp -i /path/to/key user@host | awk '/^d/{print "/path/to/folder/"$NF}'
Related Topics
How to Read the Mouse Button State from /Dev/Input/Mice
How to Return Exit Code 0 from a Failed Command
Using Named Pipes with Bash - Problem with Data Loss
How to Check Hz in the Terminal
Why Can't I Access Xampp's PHPmyadmin on Localhost? Access Is Forbidden
Xampp: Another Web Server Daemon Is Already Running
Sharing Devices (Webcam, Usb Drives, etc) with Docker
Advice Regarding Installing Arm Toolchain on Ubuntu Vm (64Bit)
How Is the Init Process Started in the Linux Kernel
How to Specify Non-Capturing Groups in Sed
Capture Both Exit Status and Output from a System Call in R
Find String Inside a Gzipped File in a Folder
Unzip a Bunch of Zips into Their Own Directories
Bash: Head & Tail Behavior with Bash Script
How to Write One Script That Runs in Bash/Shell and Powershell
Ldd Says "Not Found" Even Though Library Is in My Ld_Library_Path