This question already has an answer here:
In the directory
/home/username/data I have both files and directories. Some of these filenames end in
.txt (to which I'll refer as text files), others don't. The same happens in the subdirectories.
One of the subdirectories is called
other_files (its full path is
I'd like to move all the files not ending with
.txt in the root of
I could possibly do it with a loop, but that's not what I want. I want to use commands and piping. I believe this is easy, I'm just not seeing it. A combination of
xargs should do it, I'm just not sure how.
So I'm stuck in trying to match the text files (to then think of way to match everything except them). In the following, assume my current directory is
First I went for
find . | grep -E "*\.txt", but this matches all text files, including the ones in the subdirectories.
So I tried
find . | grep -E "\./*\.txt" just to see if I would get the same matches to then work my way towards my goal, but this doesn't match anything and this is where I'm stuck.
How do I go about doing what I described at the beginning of the question?