I don't understand this command:
find -name "*mp3*" -exec mv {} $HOME \
I know that find is performing a search in all the directories where the files or directories contain mp3 in their name -exec(I think it is executable) mv (to move) {} (I don't 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 addition of tr (I don't understand it very well but I understand that what we put in argument 1 "" will be replaced by argument 2 "" eg: tr "ax" "bz" replaces ax with bz) -dy that the name of the file or directory ends in .txt
I don't know if it is not specified in the command find d(directory) of(file) choose one of the two by default?
This command:
What it does is find all the files whose name contains "mp3". It then moves them to the "$HOME" directory. That is, it moves all the files to the user's personal directory.
This command:
Search for files whose extension is "txt". It then takes the listing and removes the spaces ("d" in the "tr" command refers to "d"elete, i.e. remove). That is, it removes the spaces from the names of the txt files. But it doesn't replace the original name, it just prints it.
No, if you don't specify anything, find will search for all files, directories and whatever.
(I added a
;
missing one at the end)-exec
causes the command that appears after this option (as far as a appears\;
) to be executed for each result found by find. Inside the command it can appear{}
where we want the file name to go. Thus, if one of the results offind
is./una/carpeta/archivo.mp3
, the command would be executedmv ./una/carpeta/archivo.mp3 $HOME
In this case it is a "normal" find that simply writes all the file names it finds to its standard output. The standard output of find is redirected via a "pipe" (
|
) to another command, in this casetr -d " "
The command
tr
reads character strings from its standard input and transforms them into others that it dumps to its standard output. In this case the strings you receive will be the names of the files found by find. The transformation that it does in this case (-d " "
) is to delete the white spaces.