-3

The actual homework question is

  1. List all files/directories NOT owned by root and not created in July.

I can't find a way to use

ls

and

grep

to output a file ~/NotOwnedByRoot.txt

find / \! -user root -d -maxdepth 1 -exec ls > ~/NotOwnedByRoot.txt  {} +

I also tried

find / \! -user root -type d -maxdepth 1 > ~/NotOwnedByRoot.txt

I get the error

find: warning: you have specified the -maxdepth option after a non-option argument !, but options are not positional (-maxdepth affects tests specified before it as well as those specified after it). Please specify options before other arguments.

  • does "-d" want to be "-type d"? and by "list users not owned by root" did you mean "list directories not owned by root"? (guessing at the typo-corrections) – Jeff Schaller Mar 6 at 16:51
  • $ find / \! -user root -type d -maxdepth 1 > ~/NotOwnedByRoot.txt find: warning: you have specified the -maxdepth option after a non-option argument !, but options are not positional (-maxdepth affects tests specified before it as well as those specified after it). Please specify options before other arguments. – software is fun Mar 6 at 17:05
  • Your title does not make sense, and does not match the 2nd line of you question. Read up on what a user, file, directory and a process is. – ctrl-alt-delor Mar 6 at 17:36
  • The error is a warning, but do what it says anyway. It will help you understand the command. – ctrl-alt-delor Mar 6 at 17:38
  • Which July? any July, or just this past one? – Jeff Schaller Mar 6 at 17:39
-2

you can use ls and grep together its very easy and with the -v in grep option you can search for words or phrases that are NOT there, so it will output everything which is not in conjunction with your search.

While in the directory you want to do this in try: ls -l | grep -v root || July

The first part ls -l lists all the files in a long listing order

The | symbol is called a pipe and it takes the input of the previous command and uses it as an input in the next command, in this case ls -l would be used as an input into 'grep'.

The second part grep -v root uses grep with the -v option which, with the search term root, the -v option is used to look for all contents that do not have what you searched for, so it will look for everything that does not have 'root'.

Finally the last part || July , the || basically means 'and' in grep so your specifiying two or more search terms, the 'July' is the second search term.***

PS: I DO NOT THINK THE QUESTION IS ASKING YOU TO MAKE A FILE CALLED 'NOTOWNEDBYROOT' INSTEAD ITS ASKING YOU TO SEARCH A DIRETCORY FOR ALL FILES/SUB DIRECTORYS THAT ARE NOT OWNED BY ROOT OR MADE IN JULY

  • Will straight-up fail to work as intended; if grep -v root throws a non-zero exit code, it will attempt to run the command July which is very likely not to be an internal or a binary in the PATH. – DopeGhoti Mar 6 at 18:21
  • If you fix your code, and explanation of | then I will change my -1 to +1 – ctrl-alt-delor Mar 7 at 9:15
  • but thats what a pipe is, it takes the output of a command as an input of a next command.......... – Qasim Mar 7 at 11:07
  • And July is not a command. Things that are not the same, partial list: ||, |. Either way, it's wrong here. – DopeGhoti Mar 8 at 16:18
  • okay, what does | | and | mean then? – Qasim Mar 8 at 20:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.