How can I delete files in terminal fluently?
For example, I do
cd Music
dir
and get
123456789.mp3
qweerkrtrkgljdjfkdjfdkf.mp3
a.mp3
b.mp3
blabla.mp3
how do I delete, say, files qweerkrtrkgljdjfkdjfdkf.mp3 and blabla.mp3 with least effort?
UPD: Key idea is that file names can be long so I actually dont want to type them.
Solution 1:
Try this:
rm -f 2.mp3 blabla.mp3
rm
removes files, and -f
forces it to (so that it wont stop, asking you if you want to delete the file). If this not in your home directory, prepend sudo
. Here is another way that might require less typing (a bit harder to read though)
rm -f {2,blabla}.mp3
This expands to 2.mp3 blabla.mp3
. If you want to use larger filenames, you can use the wildcard character (*
), which will return all items starting/ending with the filename you chose. For example:
rm -f bla*
will remove all files starting with bla
. If you used this:
rm -f *.mp3
It will remove all files ending with .mp3
. If you used this:
rm -f bla*.mp3
It will remove all files starting with bla
and ending with .mp3
. Possibilities are nearly endless with the *
character :P
Solution 2:
Just as everyone says, rm -f <file>
is the way to go, however, as stonedsquirrel said, you can type the first few letters and hit <TAB>
and it will autofill the file name.