Results 1 to 8 of 8
In a Windows command prompt window, I can type DIR and get something like:
D:\Documents and Settings\Edward>dir
Volume in drive D is DISK1_VOL2
Volume Serial Number is C4E6-C9DB
Directory of ...
- 04-05-2008 #1Just Joined!
- Join Date
- Jan 2005
- Posts
- 25
can ls list summary information like DIR?
In a Windows command prompt window, I can type DIR and get something like:
D:\Documents and Settings\Edward>dir
Volume in drive D is DISK1_VOL2
Volume Serial Number is C4E6-C9DB
Directory of D:\Documents and Settings\Edward
04/03/2008 03:09 PM <DIR> .
04/03/2008 03:09 PM <DIR> ..
07/24/2006 06:55 PM <DIR> Contacts
04/03/2008 06:47 AM <DIR> Desktop
03/24/2008 12:02 AM <DIR> Favorites
12/18/2007 12:47 AM <DIR> My Documents
03/29/2008 10:23 AM 12,320,768 NTUSER.bak
04/05/2008 02:39 AM 7,602,176 NTUSER.DAT
04/05/2008 07:59 AM 24,576 ntuser.dat.LOG
02/21/2008 06:40 PM <DIR> Start Menu
03/11/2008 09:27 AM <DIR> Tracing
11/17/2007 01:22 AM <DIR> VSWebCache
3 File(s) 19,947,520 bytes
9 Dir(s) 23,370,150,912 bytes free
Note at the end of output, there is summary information on number of files/dirs and total bytes.
Is there a switch to tell ls to list similar information?
Thanks.
- 04-05-2008 #2
ya sure, you can do a lot more than 'dir'.
do 'ls -lh'.
if there are many files use
'ls -lh | grep less'
using this you can navigate through the output
- 04-05-2008 #3Linux Guru
- Join Date
- Nov 2007
- Location
- Córdoba (Spain)
- Posts
- 1,513
He probably wants "du -sh <dirname>'
- 04-06-2008 #4Just Joined!
- Join Date
- Jan 2005
- Posts
- 25
I think du is what I want. But can ls output similar information at end of file listing?
- 04-06-2008 #5Linux Guru
- Join Date
- Nov 2007
- Location
- Córdoba (Spain)
- Posts
- 1,513
I don't think that ls can do that, but you could always define a shell function in your .bashrc to wrap together ls and du. The problem is that du can take a long time if you include -s for subdirs, so I am not sure that that solution would be ok.
There might be better programs for this, but I really never looked into that... Maybe someone has a better suggestion.
- 04-08-2008 #6Actually, what do you need from ls.But can ls output similar information at end of file listing?
In long listing it shows file size, modified date, and more
If you want detailed you can of course do a 'man ls'.
- 04-08-2008 #7Just Joined!
- Join Date
- Jan 2005
- Posts
- 25
What I want is the summary information at end of listing. The summary information consists of how many files/dirs that have been listed and how many bytes of all the listed files.
Like this:
3 File(s) 19,947,520 bytes
9 Dir(s) 23,370,150,912 bytes free
- 04-08-2008 #8Linux Guru
- Join Date
- Nov 2007
- Location
- Córdoba (Spain)
- Posts
- 1,513
As I said above, I don't know of a way to do so in ls, and I don't know of a standalone tool that will do it. You will have to make a script on your own to join all the pieces. This is a start:
Save it into a file called /usr/bin/dir (for example, or any other directory that's in your path), chmod a+x it, and then run it by typing "dir". This will output something in the lines of:#!/bin/bash
if [ -z "$1" ]
then
var=.
else
var="$1"
fi
ls -l "$var"
echo
echo "$(find "$var" -type f | wc -l) files"
echo "$(find "$var" -type d | wc -l) dirs"
To get the info about free space, you can use df, with grep and sed. To get the info about used space, "du -sh". With the examples in the previous script, doing that should be a child's play. The problem, as I said in another post, is that du -sh will take a bit to complete, and I don't think that's acceptable.....
lrwxrwxrwx 1 i92guboj i92guboj 9 dic 11 03:51 windowmaker -> startx.sh
-rwxr--r-- 1 i92guboj i92guboj 559 sep 12 2007 windows.rat
lrwxrwxrwx 1 i92guboj i92guboj 9 jul 23 2007 wlab -> startx.sh
-rwx------ 1 i92guboj i92guboj 36493 may 28 2007 wmtime
-rw-r--r-- 1 i92guboj i92guboj 896 abr 4 20:58 x
-rwx------ 1 i92guboj i92guboj 3323 jul 15 2007 xaumix
lrwxrwxrwx 1 i92guboj i92guboj 9 ago 28 2007 xfce -> startx.sh
-rwxr-xr-x 1 i92guboj i92guboj 4152728 dic 20 16:05 xmonad
lrwxrwxrwx 1 i92guboj i92guboj 9 ene 8 03:44 xpmroot -> fvwm-root
-rwx------ 1 i92guboj i92guboj 1429 abr 12 2007 xtract
-rwxr--r-- 1 i92guboj i92guboj 33 ago 9 2007 xtreme.sh
-rw-r--r-- 1 i92guboj i92guboj 2818784 dic 17 14:42 ZABBIX Manual v1.4.pdf
57 files
1 dirs
The problem is that the philosophies for the two oses are very different. In msdos the programs had the annoying habit of providing lots of info, while in linux there's a simple program for each separate task.


Reply With Quote
