LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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 02-02-2017, 12:21 AM   #1
K3rm1tTh3Fr0g
LQ Newbie
 
Registered: Feb 2017
Posts: 1

Rep: Reputation: Disabled
Commandline Help Please


Hello,
Just a heads up I'm using CentOS. So I need to find the number of files and directories in another directory and I need that to be outputted in this format "The number of files and directories in /etc on Thu Oct 16 17:18:16 PDT 2014 is 6162". So far I used the command find /etc -type f | wc -l | awk '{ print strftime(), $0; fflush() }' >output.txt but it just gives me the date and number of files and directories. I need to get it worded correctly. Please help.
 
Old 02-02-2017, 12:35 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,923

Rep: Reputation: 7319Reputation: 7319Reputation: 7319Reputation: 7319Reputation: 7319Reputation: 7319Reputation: 7319Reputation: 7319Reputation: 7319Reputation: 7319Reputation: 7319
I would suggest you to use something like this:
Code:
awk '{ printf("The number of files and directories in %s on %s", $0, strftime()) } '
(not tested)
see how printf works https://www.gnu.org/software/gawk/ma...-Examples.html http://www.math.utah.edu/docs/info/gawk_7.html.
fflush is not required.
 
Old 02-02-2017, 12:53 AM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,328
Blog Entries: 3

Rep: Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726
With the line as given, the correct wording for the printf function should leave out naming directories because they are not included in the search:

Code:
"The number of files in %s on %s \n"
If the number of directories is to be included, the search should include them with a logical or:

Code:
find /etc/ \( -type f -o -type d \) -print
 
Old 02-02-2017, 03:00 AM   #4
aragorn2101
Member
 
Registered: Dec 2012
Location: Mauritius
Distribution: Slackware
Posts: 567

Rep: Reputation: 301Reputation: 301Reputation: 301Reputation: 301
Hi,

this can be easily done with standard shell syntax, no need for awk. Give this a try:

Code:
echo "The number of files in /etc on $(date +"%a %b %d %T %Z %Y") is $(find /etc -type f 2>/dev/null | wc -l)."
 
  


Reply



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
CommandLine of NanoPi M3 jiatang Linux - Embedded & Single-board computer 1 08-15-2016 10:08 AM
[SOLVED] echo commandline ktfreak Linux - Newbie 6 01-22-2012 11:03 AM
VLC - Only commandline? worldgnat Linux - Software 3 05-20-2006 12:06 AM
commandline help needed soldan Linux - Newbie 2 03-19-2006 11:42 AM
Commandline in SUSE Aiza Sarah Linux - Newbie 2 09-27-2004 05:29 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:05 PM.

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
Open Source Consulting | Domain Registration