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 11 years ago.
Improve this question
I am working on linux scripts , Assume that the directory is consisting of these following scripts .
ls *.sh
test.sh
MyScripts.sh
My question is , before making any modifications to test.sh script , i want to keep a backup copy of it , so that if anything messes up , i will be not screwed up .
please tell me how can i keep a copy of test.sh in the same directory ?? before making any modifications to the actual file test.sh .
Thank you very much .
Consider using revision control, such as git or Subversion.
You can make a copy before your work too:
cp test.sh test.sh.orig
The usual approach is to
cp test.sh test.sh~
(or test.sh.bck or whatever naming convention). In fact, any decent editor should have an option to do this automatically for you. Vim does it by default (saves a backup name filename~ on modification)
May I heartily suggest a version control solution for this purpose instead?
Good 'starter' options include:
bazaar
mercurial
I personally vouch for git.
I took care to name (D)VCS methods that have ample interoperability options so as to prevent data lockin.
cp test.sh test.sh.`date +"%m_%d_%Y"`
Will make a timestamped backup named test.sh.10_10_2011
Related
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 8 years ago.
Improve this question
I'm in of need of help.
How do i write a shell script program using Apache Tika as the converter to help me execute .pdf files in one directory and save them in another directory in a different format (json, xml, etc).
A rough example, using JSON:
outdir=../out.d
mkdir -p "$outdir"
for f in *.pdf; do
java -jar tika-app.jar --json "$f" >"$outdir/${f%.pdf}.json" \
|| rm -- "$outdir/${f%.pdf}.json"
done
Obviously, this expects tika-app.jar to be in the current directory; adjust to taste. Similarly, see http://tika.apache.org/1.6/gettingstarted.html for full command-line usage.
To understand the ${f%.pdf} shell syntax, see BashFAQ #73.
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 do I change shell in a remote PC? I am logged into a cluster with a Bash and the output I see is
elan#l01:~ $ chsh
chsh: can only change local entries; use ypchsh instead.
elan#l01:~ $ ypchsh
-bash: ypchsh: command not found
Since I have no root privilege there, I can not install ypchsh in the cluster. Is there any other way to change shell without invoking ypchsh?
Note 1:
Browsing, it looks like another user who installed the same software (currently not available for questioning) has .cshrc in his directory, with the right settings. His .bashrc is minimal and has no redirections.
The /etc/passwd has no entry for either of us.
getent passwd
shows entry for both of us, but shows only /bin/bash for both.
Note 2:
The sofware has been developed with autotools, and using bash instead of tcsh is known to have created wrong builds. (I am not changing shell because I fancy it.)
Thank you,
Elan
In your .bashrc, put exec tcsh last.
Once you're in bash in the cluster, why don't you just type tcsh? And if that works, why not just add it as the last line of .bashrc?
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 11 years ago.
Improve this question
My development machine is a linux host.
I have a complicated directory structure (like most of you, I assume), and I would like to move easily from one directory to the other, from within the shell. Specifically, welcomed features would be:
autocompletion (something like ido-mode in emacs)
regular expression directory / file matching
suggestion of recently visited directories (stack).
Possibilty to push/pop to the stack, get a listing of recently visited directories, ...
good integration of those features
console based
Do you know any tool which can satisfy those requirements?
In bash you can set CDPATH to a colon-separated directories that bash will search for when the argument to the cd does not exist.
$ man bash|grep -A3 '^\s\+CDPATH '
CDPATH The search path for the cd command. This is a colon-
separated list of directories in which the shell looks
for destination directories specified by the cd com‐
mand. A sample value is ".:~:/usr".
Once set, autocomplete will just work the way you'd expect it:
$ export CDPATH=dir1:dir2
$ cd somedir<tab>
Besides the current directory, bash will look into the directories in $CDPATH for the possible values.
Umm, any interactive shell(say, bash) already has nearly all of these features:
Press Tab once to auto-complete, and twice to show a list of possible completions.
find | grep reg.exp can be used for file matching, or find -exec grep reg.exp -H '{}' ';' to match contents
You can switch to the previous directory with cd -
pushd and popd can be used to push and pop directories
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 11 years ago.
Improve this question
In linux terminal, I accidentally mistyped
sudo mv myfile.zip /~
My purpose was to move under the home folder but it was not there.
Although I tried to find it by both
sudo find / -name 'myfile.zip'
and
sudo locate myfile.zip
could not find it. Where it can be?
Thanks in advance.
You might be surprised to find a file named ~ right under /.
It's called /~. That's a perfectly valid filename (remember, shell only expands ~ at the * beginning* of a path and you typed it in the middle, so the shell left it at that).
You moved it to /~ --- it is at root and named ~.
Your file is now no longer named myfile.zip, but ~. You should find it exactly where you told it to go, at: /~
It will be under / and its name will be ~.
You'll be surprised that unlike Windows, Unix-like systems can take a lot of things very literally, you can even create a file with the name *.* if you quote properly. The system won't complain about it, and it will even work.
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 11 years ago.
Improve this question
I've got a bunch of tar and tar.gz files that I would like to unzip. Inside these files, most of them have the same folder structure zipped up inside (although with different files).
If I were to do this manually by right-clicking and selecting "Extract Here," it'd would create a new folder for me with the original file name and dump the files there.
However, when I do this via the command line, the behavior isn't always the same. Sometimes it'd create the desired new folder and other times it wouldn't, causing it to overwrite the extraction of others.
Using the -C option seems to require the folder already existing. How can I mimic the behavior of the manual "Extract Here" in the command line?
Thanks.
You could create a bash function like this;
function untarhere() {
(mkdir -P $1; cd $1; tar xzf $2)
}
and then call it like
untarhere /your/destination/directory /your/tar/file.tar