Answer the question
In order to leave comments, you need to log in
Is it possible to substitute the filename from ls?
Let's say there is an archive with a long name, can its name be somehow substituted into the current line from the list using ls?
Answer the question
In order to leave comments, you need to log in
the task is not quite clear
you can't copy with the mouse and auto-completion doesn't work?
find out the number of the desired line:
ls -A1 | nl'
if you need only visible (without a dot at the beginning of the name) files, then you can skip the A
key
; print the line by its number:
ls -A1 | awk 'NR==7'
where 7 is an example of the line number with the desired file name issued using the ls command, put your number.
if you wish, you can wrap it in a variable and just insert it where you need it:
f=$(ls -A1 | awk 'NR==7')
then you can already operate on this variable, for example:
rm "$f"
p.s.
if you need more interactive, you can use the skim (sk) utility or fzf
f=$(ls | fzf)
for hidden files, add the -A switch
will make it possible to select the desired file with the keys (top, bottom), and then (Enter) transfer it to a variable.
well, then we already operate with the variable f
#!/bin/bash
FILES="/root/temp/*"
#echo $FILES
for file in $FILES
do
if [ "${file: -4}" == ".zip" ]; then
echo "some string with name of $file"
fi
done
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question