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 12-18-2017, 12:16 PM   #1
JockVSJock
Senior Member
 
Registered: Jan 2004
Location: SATX
Distribution: RHEL/CentOS
Posts: 1,301
Blog Entries: 4

Rep: Reputation: 148Reputation: 148
find command fails with the following error: paths must precede expression: sort


I'm automating a number of things that person was doing manually who has left the organization.

That person was running the following daily to a log file to show what files have been created by a piece of software.

Code:
find /path/to/data -mtime -1 -type f -exec stat -c "%n %y" {} \; sort >> /home/user/log.txt &
When I run the whole find, -exec and sort command, from the CLI first, I' getting the error message:

Code:
find:  paths must precede expressions:  sort
When I back it off, the find and -exec will run correctly, there is something with the sort that is causing the issue

Code:
find /path/to/data -mtime -1 -type f
find /path/to/data -mtime -1 -type f -exec stat -c "%n %y" {} \;
Took the error message and a couple of hits in the search engine (Stack Exchange) shows that an argument needs to be quoted with single quotes, except I'm not sure what needs to be quoted. I tried to single quote the sort part, however that didn't work. Not sure what the issue is.

thanks

Last edited by JockVSJock; 12-18-2017 at 12:29 PM.
 
Old 12-18-2017, 12:30 PM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,230

Rep: Reputation: 724Reputation: 724Reputation: 724Reputation: 724Reputation: 724Reputation: 724Reputation: 724
Why not just pipe find output to sort?
Code:
find .... | sort
 
2 members found this post helpful.
Old 12-18-2017, 12:34 PM   #3
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 13,514

Rep: Reputation: 4318Reputation: 4318Reputation: 4318Reputation: 4318Reputation: 4318Reputation: 4318Reputation: 4318Reputation: 4318Reputation: 4318Reputation: 4318Reputation: 4318
there is no such argument (sort), therefore it is taken as path. But paths must precede expressions...
I assume sort is used to sort the result of find, therefore post #2 is the right solution. Looks like the original command you posted is incorrect.
 
Old 12-18-2017, 02:34 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
Quote:
Originally Posted by keefaz View Post
Why not just pipe find output to sort?
Code:
find .... | sort
Ya, I missed the | . Once I put that in, it fixed the issue.
 
  


Reply

Tags
find sort -exec


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
find: paths must precede expression lead2gold Linux - General 11 02-27-2014 08:06 AM
[SOLVED] Bash Issue with Find Script: find paths must precede expression: *.txt JockVSJock Programming 4 01-06-2014 10:03 PM
find: paths must precede expression: ls HELP! wdtunstall Linux - General 2 07-24-2013 12:22 PM
[GNU find version 4.2.27] find: paths must precede expression mechagojira Linux - Newbie 3 07-06-2011 06:34 AM
Problem with find: paths must precede expression troelskn Programming 11 07-29-2009 03:48 AM

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

All times are GMT -5. The time now is 03:23 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