Score:0

How can I copy all files which starts with a letter and ends with another to a specific folder?

np flag

I’m using Ubuntu-Linux terminal. I want to move from one directory to another the files that begin with the letter “T” and end with “-AN”. Besides, only “.txt” files. I want to do it in the same command. Any suggestions?

24601 avatar
in flag
[edit] your question wit the exact command you used in terminal
in flag
This sounds like a homework question. While I am not opposed to helping people learn things, it's generally better to *guide* someone to a solution rather than simply provide one
mook765 avatar
cn flag
If a filename ends with `AN`, it cannot end with `.txt`. My conclusion: no files to move, homework done...
Raffa avatar
jp flag
`*` will match any number of characters ... So `cp dir1/T*-AN.txt dir2/` :-)
Raffa avatar
jp flag
@mook765 :-D ... I guess OP meant the part of the filename before the `.txt` part
mook765 avatar
cn flag
@Raffa OP should not let us guess what is meant, a question has to be clear.
Raffa avatar
jp flag
@mook765 Sure, can't argue with that :-)
Score:3
jp flag

First, a file name actually refers to everything(including the file extension) ... So you might want to pay attention to that when asking/explaining in the future.

Second, it appears that you want to match all files that start with the character T(case matters here) and followed by zero or more characters then followed by -AN.txt(case matters here as well) ... For that you can make use of what is called shell globbing(AKA wildcard matching) using the *(asterisk or star) character which matches zero or more of any character.

Third, you use the word (copy) in the title and the word (move) in the body of your question interchangeably ... but they are not the same ... So to copy you use cp like so:

cp -- dir1/T*-AN.txt dir2/

and to move, you use mv like so:

mv -- dir1/T*-AN.txt dir2/

Where dir1/ is the source directory and dir2/ is the destination directory.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.