LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-15-2007, 02:22 AM   #1
shipon_97
Member
 
Registered: Oct 2005
Location: Bangladesh
Posts: 484

Rep: Reputation: 30
Need to count contents of a directory


Dear Friends ,

I have the following two questions :

1) I want to know how many contents or files in the /etc path . Using which command I can count it . Not the file name , tne number of files in a directory (Like /etc, /tmp) etc .

2) My Another question is ,
If I want to know the log files of previous two days of my Linux machine of a particular user or root user (I m using RHEL 4), then using which file/files i can get those information ? It can be user's log or system lof etc . Or , is there any particular third party software can be used for this purpose ?
 
Old 08-15-2007, 02:31 AM   #2
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
1) find /etc -type f | wc -l

2) I don't understand what you're asking with #2 and I don't use RHEL.
 
Old 08-15-2007, 02:32 AM   #3
rickh
Senior Member
 
Registered: May 2004
Location: Albuquerque, NM USA
Distribution: Debian-Lenny/Sid 32/64 Desktop: Generic AMD64-EVGA 680i Laptop: Generic Intel SIS-AC97
Posts: 4,250

Rep: Reputation: 61
Sure sounds like homework to me.
 
Old 08-15-2007, 02:35 AM   #4
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
Quote:
Originally Posted by rickh View Post
Sure sounds like homework to me.
Quote:
Originally Posted by shipon_97 View Post
Or , is there any particular third party software can be used for this purpose ?
That doesn't really sound like homework to me, but you may be right.
 
Old 08-16-2007, 02:56 AM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Maybe homework... however ...
1. ls /etc|wc -l
for all files recursively
ls -R /etc|wc -l

2. Individual's actions are not (normally) logged. Need more info.
 
Old 08-16-2007, 05:17 AM   #6
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
Quote:
Originally Posted by chrism01 View Post
Maybe homework... however ...
1. ls /etc|wc -l
for all files recursively
ls -R /etc|wc -l
The first will also include directories, which may be fine depending on what shipon_97 wants, but will miss dotfiles and the second will count directory listings twice and blank lines and will miss dotfiles.
 
Old 08-16-2007, 07:01 AM   #7
lugoteehalt
Senior Member
 
Registered: Sep 2003
Location: UK
Distribution: Debian
Posts: 1,215
Blog Entries: 2

Rep: Reputation: 49
Quote:
Originally Posted by rickh View Post
Sure sounds like homework to me.
Some of us are too stupid to answer anything but homework.
 
Old 08-16-2007, 08:29 AM   #8
xav.vijay
LQ Newbie
 
Registered: Jun 2007
Posts: 15

Rep: Reputation: 0
Well.. for ur second question, I used to view /var/log/messages file... for older dates it wud be messages.1, messages.2....and so on...
The log file is not limited to any single user, it will have all users log details....
Is this what u were looking for?
 
Old 08-16-2007, 09:48 AM   #9
forrestt
Senior Member
 
Registered: Mar 2004
Location: Cary, NC, USA
Distribution: Fedora, Kubuntu, RedHat, CentOS, SuSe
Posts: 1,288

Rep: Reputation: 99
For all the files in a particular directory:

ls -la | grep -v ^d |wc -l

If you want to leave out links:

ls -la |grep -v '^[dl]' | wc -l
 
Old 08-17-2007, 01:31 AM   #10
Andersonian
LQ Newbie
 
Registered: Oct 2006
Location: California / Moldova
Distribution: bunch of Ubuntu flavors
Posts: 29

Rep: Reputation: 15
Quote:
Originally Posted by shipon_97 View Post
2) My Another question is ,
If I want to know the log files of previous two days of my Linux machine of a particular user or root user (I m using RHEL 4), then using which file/files i can get those information ? It can be user's log or system lof etc . Or , is there any particular third party software can be used for this purpose ?
Well, this is a really bad formulation. So I'll give you a half baked answer:
find /var/log -mmin -150000 -name *.log -type f

This returns the list of files with filename *.log in /var/log which have been modified in the last 150000 minutes. Hope that helps?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Count the number of files in a directory and sub-directories within that directory soumyajit.haldar Linux - Software 4 03-20-2007 07:22 AM
list contents of directory without listing contents baddah Linux - Newbie 2 06-12-2006 05:02 AM
how to get count of files in a directory? hongxing Linux - Software 2 11-10-2005 10:06 PM
How to count line numbers recursively in a directory? puzz_1 Linux - General 1 07-01-2004 10:43 AM
mv the contents of one directory to the parent directory warkrime Linux - Newbie 4 07-14-2003 08:03 PM


All times are GMT -5. The time now is 02:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration