please explain the linux command: find /tmp -name core -type f -print | xargs /bin/rm -f [closed]

StackOverflow https://stackoverflow.com/questions/14248516

  •  14-01-2022
  •  | 
  •  

Pergunta

i have been looking all throughout the google for the explanation of such commands

find /tmp -name core -type f -print | xargs /bin/rm -f

well i got the command from the net itself and explanation was also mentioned there.by now i know that this command is used to find a file named 'core' in the directory named 'tmp' and delete the file. i have used and checked this and it is perfectly working.

my problem is that i could not understand the terms used in this command like what does -type f, and xargs do?? also how to generate such commands according to our need(obviously could not unless properly understood), and the biggest problem is what to write in google to get the help regarding this...i mean under what topic may i expect these.

please help

regards.

Foi útil?

Solução

This is a string of unix commands:

 find           // name of command (in this case, "find")

 arguments to 'find':
    /tmp        // where to look
    -name core  // name to look for, "core" (optional argument)
    -type f     // files only (not, eg, directories or files contents) 
                // (optional argument)
    -print      // output the list to standard output (STDOUT)

|               // name of command (otherwise known as
                // 'pipe') this is a little program that
                // takes the output from a previous process
                // (in this case, the output from 'find')
                // and pass it to another process as input  

 xargs          // name of command ('xargs') the program
                // that will accept the output from 'print'
                // as input (directed by 'pipe'). It provides
                // a robust way to process indefinitely
                // long lists by breaking them into smaller
                // lists and passing each sublist through
                // to its command argument

 /bin/rm        // name of command for xargs to execute 
                // on its input list ('rm' = remove)
      -f        // argument to rm, only remove files, not directories.

That's how unix works, it's made up of lots of little single-purpose programs with obscure 2-letter names that are devoted to a single task. You string these together to achieve more complex tasks.

The correct way to find out what any one command does is to use the 'man' command with the command name in question as argument, eg

man find
man xargs
man rm

You will get pages of detailed info describing each input option and output possibilities. A name like 'xargs' is also easy to google but understandably 'find' is not (maybe try 'unix find'). Many of them have Wikipedia pages...

Perhaps you should get a decent into guide to unix ...

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top