What do these commands do? I do not understand them very well

2

I have some commands that I basically do not understand quite well and I would like someone with knowledge of OS linux to help me.

find -name "*mp3*" -exec mv {} $HOME \

I know that I find it doing a search in all the directories where the files or directories that contain in their name mp3 -exec (I think it is executable) mv (to move) {} (I do not understand it very well but it is to indicate a pattern) $ HOME (refers to the / home / directory) (I have no idea).

find $HOME -name "*.txt" | tr -d " "

Similar to the previous one but with the aggregation of tr (I do not understand it very well but I understand that what we put in argument 1 "" will be replaced by argument 2 "" ex: tr "ax" "bz" replaces the ax by bz) -and that the name of the file or directory ends in .txt

I do not know if it is not specified in the command find d (directory) or f (file) choose one of the two by default?

My big doubt is that I do not understand very well what they do. If you could help me. Thanks.

    
asked by Sam 16.04.2018 в 00:03
source

1 answer

0
find -name "*mp3*" -exec mv {} $HOME \

find -name "*mp3*" Find all the files that contain the string mp3 in the current directory and its subdirectories and for each -exec mv execute the mv command on the output% argument {} moving it to your $ HOME.

Result : move all the mp3s to your home.

find $HOME -name "*.txt" | tr -d " "

find $HOME -name "*.txt" finds all the files with extension txt in your home directory and its subdirectories , and using a pipe | executes on them the tr -d command that writes a line in where the argument is modified to remove a text string from it. In this case, the string is the space " " .

Result , list all txt without spaces in the names. Do not rename them.

Why is not it useful to do -exec tr -d {} or another variant? Well, because exec operates on the file and tr on a text. By using the pipe | you pass to the following command the output of find which is just the text of the file name.

    
answered by 16.04.2018 в 14:10