How to use the result of the ls command to the mv command?

Looking for a way not to use the mouse when renaming files.
This is usually done like this:
ls *.txt
mv somelongfilename.txt shortname.txt

The name of the file that you want to copy by highlighting with the mouse the output of ls.
PS About the existence of Tab I know. Want to combine mv and ls into one command.
July 2nd 19 at 14:21
4 answers
July 2nd 19 at 14:23
Solution
The file name does not have to copy, you just dial from the keyboard.
But for a mass rename in Linux there is a command rename.
If the file is only one:
mv `ls -1 old_mask` new_name
Long names are awkward to type. We are talking about renaming a single file. - rhianna_Yost commented on July 2nd 19 at 14:26
: *.txt already implies that can be an arbitrary number of files. Thus this list as it is necessary to select. Then it is easier to start typing the file name and use the Tab key to autocomplete the name. - Kenyatta commented on July 2nd 19 at 14:29
: *.txt naturally given as the example and assumes that directory is one file with this extension. Tab not quite what I stated in the question. - rhianna_Yost commented on July 2nd 19 at 14:32
If a file is only one, then
mv `ls -1 old_name` new_name - Kenyatta commented on July 2nd 19 at 14:35
: Yes, this is exactly what you need. Please take in response, but instead old_name write mask such as *.txt.
Another question, where can I read why the team is framed by apostrophes, and not quotes? - rhianna_Yost commented on July 2nd 19 at 14:38
: Back quotes - substitution result enclosed in these teams in line. - Kenyatta commented on July 2nd 19 at 14:41
:
mv `ls -1 old_name` new_name

And what for you put a unit there? How many files would be there any need to apply head.
[guest@localhost sh]$ echo "`ls *.sh`"
iters_meth.sh
t.sh
[guest@localhost sh]$ echo "`ls *.sh | head -1`"
iters_meth.sh
[guest@localhost sh]$
- Ramon.Stracke commented on July 2nd 19 at 14:44
: -1 is one file per line. Without this key, all the files are in a single row to be.
$ echo `ls *`
1.cpp 1.lex 1.man 1.php 1.pl 1.t 1.txt 1.x 2 2.pl 2c2bV2_3_769_392T20150407175221.z a Junk INBOX.find out ham lex.yy.c test.c
- Kenyatta commented on July 2nd 19 at 14:47
: can using /bin/ls to check, does head -1 single file. I have take. Why /bin/ls because the systems often aliased ls to ls -1. - Ramon.Stracke commented on July 2nd 19 at 14:50
: Yes, you have it in one row only displays because there are no double quotes. echo without double quotes will be newlines to spaces to convert. - Ramon.Stracke commented on July 2nd 19 at 14:53
July 2nd 19 at 14:25
why did you do the ls?Write a small bash script and all
To view the name of the file that was downloaded. - rhianna_Yost commented on July 2nd 19 at 14:28
July 2nd 19 at 14:27
for i in `ls`;do mv $i 123${i}; done
will add all files in a directory 123 in the name
July 2nd 19 at 14:29
I don't know how this option is simpler, but comfortable 100% https://github.com/mooz/percol

Find more questions by tags Linuxbash