Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I often need to move file from one location to other, but it requires copying and pasting huge part of the command. For example:
mv ~/Projects/foo/bar/baz.img ~/Projects/foo/bar/fiz.dmg
Is it possible after entering ~/Projects/foo/bar/baz.iso part of above command to use some shortcut that duplicates it so I can change the very end to fiz.dmg?
You don’t need this:
mv ~/Projects/foo/bar/baz.img ~/Projects/foo/bar/fiz.dmg
easily turns into
mv ~/Projects/foo/bar/{baz,fiz}.img
. Note: zsh completion is still available when you write { (unless you have a habit of writing closing } right away) if you want it.
I actually discovered one possible solution. Just press:
Ctrl+W few times and then Ctrl+Y two times (and space between pastes).
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 1 year ago.
Improve this question
Intention:
cp /path/to/code.{c,h} .
Concise version:
cp /path/to/code.* .
Re-occurring typo:
cp /path/to/code.*
In the typo case the second file is overwritten by the first.
This has bitten me repeatedly and I'm not optimistic there's a solution outside of re-writing my neural circuits, but one can dream.
Asking for confirmation every time or some visual indication of danger would both be solutions.
Defaulting to --no-clobber or some such is not a solution because I am usually clobbering something in the intended destination.
As suggested, you could create an alias
alias cp='cp -i'
such that you will always be prompted when invoking cp from the command line. Note that this will not affect scripts.
The man page for cp has this to say:
-i, --interactive
prompt before overwrite (overrides a previous -n option)
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Let's say as an example that I wanted to write a script file that not only kept count of how many times it's been called, but would average the time that it has been called since the first time. and to do this without relying on environmental variables or secondary files. And report the number of lapsed days as well. This would mean that it would have to be self-modifying. Now when a script is loaded and executed, the saved version on disk can be changed without effecting the copy in memory, so that works, or should. Just change the copy on file.
But making it happen can be a bit tricky. So what is your best solution?
Sounds a bit weird, but a bash script is just text, so you can always edit it IF you have permission:
Take this example:
#!/bin/bash
VAR=1
let VAR=VAR+1
echo Set to $VAR
perl -pi -e 's/^VAR=\d+/VAR='$VAR'/' $0
Trying it out:
$ /tmp/foo.sh
Set to 9
$ /tmp/foo.sh
Set to 10
$ /tmp/foo.sh
Set to 11
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
I'm running a script on terminal and it is supposed to produce a long output, but for some reason the terminal is just showing me the end of the result and I cannot scroll up to see the complete result. Is there a way to save all the terminal instructions and results until I type clear.
The script I'm using has a loop so I need to add the output of the loop if Ill be redirecting the output to a file.
Depending on your system, the size of the terminal buffer may be fixed and hence you may not be able to scroll far enough to see the full output.
A good alternative would be to output your program/script to a text file using:
user#terminal # ./nameofprogram > text_file.txt
Otherwise you will have to find a way to increase the number of lines. In some terminal applications you can go to edit>profiles>edit>scrolling tab and adjust your settings.
You can either redirect the output of your script in a file:
script > file
(Be careful to choose a file that does not exist otherwise the content will be erased)
Or you can buffer the output with less:
script | less
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I'm very new to shell scripting. I have a basic doubt of what is the use of & in shell scripting? That is doing something like this :
commands arg &
Waits to give more input. But what is its exact use? How should I use it in real world?
As you have used it there, it runs commands arg in the background, disconnected from your keyboard, and the shell immediately asks you for its next command.
As for the real world, I use it when I have a command that will take some significant time to run but does not require any input from me and will put all of its output into a file, for example
# walk through the whole filesystem looking for a particular filename
find / -name 'obscure.filename' -print > /tmp/found-it &
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
How to exit from the long output of a terminal command or a git command like git log or git branch -a?
How to avoid that I have to press enter untill the output of the command is complete?
git log uses more or less for paging the output.
You can press q to stop more/less and drop the remaining output.
Ctrl-C is the entire answer, though it's too short to go in this field.