LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 01-04-2016, 02:34 PM   #1
JockVSJock
Senior Member
 
Registered: Jan 2004
Location: SATX
Distribution: RHEL/CentOS
Posts: 1,301
Blog Entries: 4

Rep: Reputation: 148Reputation: 148
Possible to run multiple commands from User-Defined Actions with the Find Command?


So I'm trying to accomplish two things with a command or script Vs doing this manually:

1. Trying to get a count of files in directories (wc -l)

2. Trying to see the last time any of these files where accessed (find -mtime and searching back 30, 60, 90, 180 and 360 days back)

Code:
find /data/svn -exec ls -asR '{}' ';'
The command line above works.

However if I run the next one:

Code:
find /data/svn -exec ls -asR : wc -l '{}' ';'
I get the following output

Code:
ls: wc: No such file or directory.
I'm not sure if there is a way to combine the two commands or say write a bash script that will do what I'm needing to be done?
 
Old 01-04-2016, 03:21 PM   #2
Sefyir
Member
 
Registered: Mar 2015
Distribution: Linux Mint
Posts: 607

Rep: Reputation: 301Reputation: 301Reputation: 301Reputation: 301
Pipe the whole find command to wc -l?

Code:
$ find foo/ | wc -l
1902
You can have find do multiple commands on each found item however. The below will echo the found file and then run a du -h on it.

Code:
find foo/ -exec echo {} \; -exec du -h {} \;
 
1 members found this post helpful.
Old 01-05-2016, 01:50 PM   #3
JockVSJock
Senior Member
 
Registered: Jan 2004
Location: SATX
Distribution: RHEL/CentOS
Posts: 1,301

Original Poster
Blog Entries: 4

Rep: Reputation: 148Reputation: 148
So this commands seems to be successful:

Code:
find /data/svn echo {} \; -exec ls -asR {} \; -exec wc -l \;
 
Old 01-13-2016, 12:56 PM   #4
JockVSJock
Senior Member
 
Registered: Jan 2004
Location: SATX
Distribution: RHEL/CentOS
Posts: 1,301

Original Poster
Blog Entries: 4

Rep: Reputation: 148Reputation: 148
Quick update.

When I run the find with multiple -exec Vs just going to the cmd line and running ls -al | wc -l I'm getting different count of files.

For example:

Code:
find /data/svn echo {} \; -exec ls –asR {} \; -exec wc –l \;
Returned this

Code:
/data/svn/dir/subdir/subdir1/subdir2/0
total 8032
However if I manually go to that same directory and run

Code:
# pwd
/data/svn/dir/subdir/subdir1/subdir2/0
# ls -al | wc -l 
1003
I get a different total.

Looking at the man page for wc, it describes the -l as a newline count, so it is counting a new line as it outputs or just the total number of items it finds in that directory?

Again, I'm trying to automate this Vs going into each directory and running wc -l manually...

thanks
 
Old 01-13-2016, 01:17 PM   #5
Sefyir
Member
 
Registered: Mar 2015
Distribution: Linux Mint
Posts: 607

Rep: Reputation: 301Reputation: 301Reputation: 301Reputation: 301
How about going this another way, using a while loop to run through each found directory and running ls $folder | wc -l on each one?

Change ~/foobar to directory you want to search
Code:
while read folder; do echo $(ls -l "$folder" | wc -l) "$folder"; done <<<"$(find ~/foobar -type d)"
 
  


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
[SOLVED] Single command to run multiple commands on ssh knspradeep Linux - Enterprise 5 10-14-2013 08:40 AM
User defined linux commands in a user defined shell Sushma05 Linux - Newbie 3 09-13-2013 08:21 AM
run a user-defined command without sudo anurupr Programming 13 03-19-2013 12:28 PM
run a linux command in user defined terminal davender84 Linux - General 1 12-04-2009 07:43 AM
using multiple -exec commands in a single find command? Bluemilk Linux - Newbie 4 03-19-2006 11:46 AM

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

All times are GMT -5. The time now is 10:14 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration