Skip to main content
added 42 characters in body
Source Link

I use this one, few examples:

ls -Ap directory01/directory02 | grep -v /$ | wc -l ls -Ap directory01/directory02/exampl* | grep -v /$ | wc -l ls -Ap /home/directory01/directory02 | grep -v /$ | wc -l 

It works like this:

  • -p with ls adds / at the end of the directory names.
  • -A with ls lists all the files and directories, including hidden files but excluding . and .. directories.
  • grep -v /$ only shows the lines that do not match (-v option) lines that end with /. (directories)
  • wc -l counts the number of lines.

Either I use for example mix of these:

ls -Ap directory01/directory02 | grep -v /$ | wc -l ; / ls -Ap directory01/directory02/exampl* | grep -v /$ | wc -l; / ls -Ap /home/directory01/directory02 | grep -v /$ | wc -l 

So, for example from the:

$ tree . ├── directory01 │   ├── directory02 │   ├── directory03 │   ├── Screenshot from 2022-04-19 15-12-55.png │   └── Screenshot from 2022-04-19 16-05-05.png │   └── directory04 

I will get count [plain files]

$ ls -Ap directory01/directory03 | grep -v /$ | wc -l 2 

It will be counted both

│ ├── Screenshot from 2022-04-19 15-12-55.png │ └── Screenshot from 2022-04-19 16-05-05.png 

but no [not a plain file]

directory04 

I use this one, few examples:

ls -Ap directory01/directory02 | grep -v /$ | wc -l ls -Ap directory01/directory02/exampl* | grep -v /$ | wc -l ls -Ap /home/directory01/directory02 | grep -v /$ | wc -l 

It works like this:

  • -p with ls adds / at the end of the directory names.
  • -A with ls lists all the files and directories, including hidden files but excluding . and .. directories.
  • grep -v /$ only shows the lines that do not match (-v option) lines that end with /. (directories)
  • wc -l counts the number of lines.

Either I use for example mix of these:

ls -Ap directory01/directory02 | grep -v /$ | wc -l ; / ls -Ap directory01/directory02/exampl* | grep -v /$ | wc -l; / ls -Ap /home/directory01/directory02 | grep -v /$ | wc -l 

So, for example from the:

$ tree . ├── directory01 │   ├── directory02 │   ├── directory03 │   ├── Screenshot from 2022-04-19 15-12-55.png │   └── Screenshot from 2022-04-19 16-05-05.png │   └── directory04 

I will get count

$ ls -Ap directory01/directory03 | grep -v /$ | wc -l 2 

It will be counted both

│ ├── Screenshot from 2022-04-19 15-12-55.png │ └── Screenshot from 2022-04-19 16-05-05.png 

but no

directory04 

I use this one, few examples:

ls -Ap directory01/directory02 | grep -v /$ | wc -l ls -Ap directory01/directory02/exampl* | grep -v /$ | wc -l ls -Ap /home/directory01/directory02 | grep -v /$ | wc -l 

It works like this:

  • -p with ls adds / at the end of the directory names.
  • -A with ls lists all the files and directories, including hidden files but excluding . and .. directories.
  • grep -v /$ only shows the lines that do not match (-v option) lines that end with /. (directories)
  • wc -l counts the number of lines.

Either I use for example mix of these:

ls -Ap directory01/directory02 | grep -v /$ | wc -l ; / ls -Ap directory01/directory02/exampl* | grep -v /$ | wc -l; / ls -Ap /home/directory01/directory02 | grep -v /$ | wc -l 

So, for example from the:

$ tree . ├── directory01 │   ├── directory02 │   ├── directory03 │   ├── Screenshot from 2022-04-19 15-12-55.png │   └── Screenshot from 2022-04-19 16-05-05.png │   └── directory04 

I will get count [plain files]

$ ls -Ap directory01/directory03 | grep -v /$ | wc -l 2 

It will be counted both

│ ├── Screenshot from 2022-04-19 15-12-55.png │ └── Screenshot from 2022-04-19 16-05-05.png 

but no [not a plain file]

directory04 
Formatting
Source Link
AdminBee
  • 23.6k
  • 25
  • 56
  • 77

I use this one, few examples:

ls -Ap directory01/directory02 | grep -v /$ | wc -l   ls -Ap directory01/directory02/exampl* | grep -v /$ | wc -l   ls -Ap /home/directory01/directory02 | grep -v /$ | wc -l 

It works like this: -p with ls adds / at the end of the directory names. -A with ls lists all the files and directories, INCLUDING hidden files but EXCLUDING . and .. directories. grep -v /$ only shows the lines that do NOT match ( -v option) lines that end with /. (directories) wc -l counts the number of lines.

  • -p with ls adds / at the end of the directory names.
  • -A with ls lists all the files and directories, including hidden files but excluding . and .. directories.
  • grep -v /$ only shows the lines that do not match (-v option) lines that end with /. (directories)
  • wc -l counts the number of lines.

Either I use for example mix of these:

ls -Ap directory01/directory02 | grep -v /$ | wc -l ; / ls -Ap directory01/directory02/exampl* | grep -v /$ | wc -l; / ls -Ap /home/directory01/directory02 | grep -v /$ | wc -l 

So, for example from the:

$ tree . ├── directory01 │   ├── directory02 │   ├── directory03 │   ├── Screenshot from 2022-04-19 15-12-55.png │   └── Screenshot from 2022-04-19 16-05-05.png │   └── directory04 

I will get count

$ ls -Ap directory01/directory03 | grep -v /$ | wc -l 2 

It will be counted both

│ ├── Screenshot from 2022-04-19 15-12-55.png │ └── Screenshot from 2022-04-19 16-05-05.png 

but no

directory04 

I use this one, few examples:

ls -Ap directory01/directory02 | grep -v /$ | wc -l   ls -Ap directory01/directory02/exampl* | grep -v /$ | wc -l   ls -Ap /home/directory01/directory02 | grep -v /$ | wc -l 

It works like this: -p with ls adds / at the end of the directory names. -A with ls lists all the files and directories, INCLUDING hidden files but EXCLUDING . and .. directories. grep -v /$ only shows the lines that do NOT match ( -v option) lines that end with /. (directories) wc -l counts the number of lines.

Either I use for example mix of these:

ls -Ap directory01/directory02 | grep -v /$ | wc -l ; / ls -Ap directory01/directory02/exampl* | grep -v /$ | wc -l; / ls -Ap /home/directory01/directory02 | grep -v /$ | wc -l 

So, for example from the:

$ tree . ├── directory01 │   ├── directory02 │   ├── directory03 │   ├── Screenshot from 2022-04-19 15-12-55.png │   └── Screenshot from 2022-04-19 16-05-05.png │   └── directory04 

I will get count

$ ls -Ap directory01/directory03 | grep -v /$ | wc -l 2 

It will be counted both

│ ├── Screenshot from 2022-04-19 15-12-55.png │ └── Screenshot from 2022-04-19 16-05-05.png 

but no

directory04 

I use this one, few examples:

ls -Ap directory01/directory02 | grep -v /$ | wc -l ls -Ap directory01/directory02/exampl* | grep -v /$ | wc -l ls -Ap /home/directory01/directory02 | grep -v /$ | wc -l 

It works like this:

  • -p with ls adds / at the end of the directory names.
  • -A with ls lists all the files and directories, including hidden files but excluding . and .. directories.
  • grep -v /$ only shows the lines that do not match (-v option) lines that end with /. (directories)
  • wc -l counts the number of lines.

Either I use for example mix of these:

ls -Ap directory01/directory02 | grep -v /$ | wc -l ; / ls -Ap directory01/directory02/exampl* | grep -v /$ | wc -l; / ls -Ap /home/directory01/directory02 | grep -v /$ | wc -l 

So, for example from the:

$ tree . ├── directory01 │   ├── directory02 │   ├── directory03 │   ├── Screenshot from 2022-04-19 15-12-55.png │   └── Screenshot from 2022-04-19 16-05-05.png │   └── directory04 

I will get count

$ ls -Ap directory01/directory03 | grep -v /$ | wc -l 2 

It will be counted both

│ ├── Screenshot from 2022-04-19 15-12-55.png │ └── Screenshot from 2022-04-19 16-05-05.png 

but no

directory04 
Source Link

I use this one, few examples:

ls -Ap directory01/directory02 | grep -v /$ | wc -l ls -Ap directory01/directory02/exampl* | grep -v /$ | wc -l ls -Ap /home/directory01/directory02 | grep -v /$ | wc -l 

It works like this: -p with ls adds / at the end of the directory names. -A with ls lists all the files and directories, INCLUDING hidden files but EXCLUDING . and .. directories. grep -v /$ only shows the lines that do NOT match ( -v option) lines that end with /. (directories) wc -l counts the number of lines.

Either I use for example mix of these:

ls -Ap directory01/directory02 | grep -v /$ | wc -l ; / ls -Ap directory01/directory02/exampl* | grep -v /$ | wc -l; / ls -Ap /home/directory01/directory02 | grep -v /$ | wc -l 

So, for example from the:

$ tree . ├── directory01 │   ├── directory02 │   ├── directory03 │   ├── Screenshot from 2022-04-19 15-12-55.png │   └── Screenshot from 2022-04-19 16-05-05.png │   └── directory04 

I will get count

$ ls -Ap directory01/directory03 | grep -v /$ | wc -l 2 

It will be counted both

│ ├── Screenshot from 2022-04-19 15-12-55.png │ └── Screenshot from 2022-04-19 16-05-05.png 

but no

directory04