- changing a file's name
- Posted by Xiaoshen Li on January 22nd, 2004
Hi,
I don't how to change the file name on linux. I always do: cp foo
bar[RET], rm foo. It usually works fine. But today, don't know why, bar
was created as an empty file and I have deleted foo before I have
realized that. So I lost my file foo permanently.
BTW, is there a way to rescue a file be deleted by rm?
Thank you very much for your help.
Thank you very much.
Best Regards,
Xiaoshen
- Posted by Jean-David Beyer on January 22nd, 2004
Xiaoshen Li wrote:
It should always work fine.
Unless you are having hardware problems, you may not have reported
_everything_ you did.
Sure, it is very easy. Just restore it from your backup tape.
--
.~. Jean-David Beyer Registered Linux User 85642.
/V\ Registered Machine 73926.
/( )\ Shrewsbury, New Jersey http://counter.li.org
^^-^^ 7:05pm up 16 days, 6:31, 6 users, load average: 2.09, 2.14, 2.15
- Posted by Grant Edwards on January 22nd, 2004
On 2004-01-22, Xiaoshen Li <xli6@gmu.edu> wrote:
mv foo bar
--
Grant Edwards grante Yow! Yow! Am I in
at Milwaukee?
visi.com
- Posted by notbob on January 22nd, 2004
On 2004-01-22, Xiaoshen Li <xli6@gmu.edu> wrote:
man mv
nb
- Posted by Chris F.A. Johnson on January 22nd, 2004
On Thu, 22 Jan 2004 at 18:03 GMT, Xiaoshen Li wrote:
You should check that the cp command completed successfully:
cp foo bar && rm foo || echo copy failed >&2
Or back up the file:
cp -b foo bar
rm foo
Or just use the usual command:
mv foo bar
To be safe, you can back it up at the same time:
mv -b foo bar
Yes, but I've never had to do it. Google for undelete.
--
Chris F.A. Johnson http://cfaj.freeshell.org
================================================== =================
My code (if any) in this post is copyright 2004, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
- Posted by Chris F.A. Johnson on January 22nd, 2004
On Fri, 23 Jan 2004 at 00:29 GMT, Chris F.A. Johnson wrote:
My brain's a little cloudy today; this backs up the destination
file if it exists, not the source file, so you should still check
for successful completion before deleting the source file.
cp -b foo bar && rm foo
See above.
--
Chris F.A. Johnson http://cfaj.freeshell.org
================================================== =================
My code (if any) in this post is copyright 2004, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
- Posted by Ed Murphy on January 23rd, 2004
On Thu, 22 Jan 2004 18:03:43 +0000, Xiaoshen Li wrote:
I strongly recommend you look for a general Linux tutorial; it will
answer lots of these very basic questions, saving you the trouble of
asking each one individually.
Here are the first few sites that Google turns up, searching for
(Linux tutorial):
http://www.tldp.org/LDP/gs/gs.html
http://www.linux-tutorial.info/
http://www.littleigloo.org/tutorial.php3
http://grouchy.cs.indiana.edu/usr/lo...nux/gs/gs.html
- Posted by Steve Holdoway on January 23rd, 2004
On Thu, 22 Jan 2004 18:03:43 +0000, Xiaoshen Li <xli6@gmu.edu> wrote:
copy. Other posters have pointed out the mv command. Note also that mv
will only rewrite the directory contents if the mv is within a single
partition. Otherwise it will transparently perform a cp, rm as you
were doing anyway.
involved. Also, the free blocks table is normally used in a 'last in,
first out' way ( ext2, ext3 ), which means that your file will have
holes in it if any other files have been generated since this one was
deleted. So, if you're really serious about getting it back,
immediately remount the partition in readonly mode!
Steve
- Posted by Xiaoshen Li on January 23rd, 2004
Dear Everybody:
Thank you so much for your kindness to answer my Linux 101 level
questions. I greatly appreciate you guys' patience.
I found that I cannot understand well what "man foo" says. This strongly
limits my linux skill development. I have copied one example below.
Could you please kindly go through what it means? For example,
--backup[=CONTROL], what it means? How should I use it? In your
explanation, please give me concrete examples, like "cp foo bar".
NAME
cp - copy files and directories
SYNOPSIS
cp [OPTION]... SOURCE DEST
cp [OPTION]... SOURCE... DIRECTORY
cp [OPTION]... --target-directory=DIRECTORY SOURCE...
DESCRIPTION
Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.
Mandatory arguments to long options are mandatory for short options too.
-a, --archive
same as -dpR
--backup[=CONTROL]
make a backup of each existing destination file
-b
like --backup but does not accept an argument
Thank you very much.
Best Regards,
Xiaoshen
- Posted by Xiaoshen Li on January 23rd, 2004
Thank you very much for your help. "rename" command is a puzzle to me. I
use Linux 7.3. There is "rename" command available. But "rename old.txt
new text" command does not change it. No error message, either."which
rename" returns "/usr/bin/rename".
mv works fine.
Best Regards,
Xiaoshen
- Posted by Kill Bill on January 23rd, 2004
Ed Murphy wrote:
very basic questions (everybody had a time not knowing their answers),
but indeed a general, basic linux tutorial will save Xiaosheng a lot of
time (and provide more precise and complete answers). Cheers, KB
- Posted by Web Surfer on January 23rd, 2004
[This followup was posted to comp.os.linux.misc]
In article <bupkrm$lp3@portal.gmu.edu>, xli6@gmu.edu says...
Don't know why your "cp" failed, but if your system administrator does
regular backups then you can likely get your file back from the last
backup.
On my Linux Redhat9 system there is a "rename" command.
For systems without a "rename" command you can simply use the "mv"
commnd as follows :
mv old.txt new.txt
- Posted by Lew Pitcher on January 23rd, 2004
Xiaoshen Li wrote:
Primarily, rename doesn't work for you because you aren't using it properly.
The rename(1) manpage explains that...
NAME
rename - Rename files
SYNOPSIS
rename from to file...
DESCRIPTION
rename will rename the specified files by replacing the
first occurrence of from in their name by to.
For example, given the files foo1, ..., foo9, foo10, ...,
foo278, the commands
rename foo foo0 foo?
rename foo foo0 foo??
will turn them into foo001, ..., foo009, foo010, ...,
foo278.
Your use of rename
rename old.txt new text
would look for the file named "text", and change the first occurrance of the
string "old.txt" in that name to the string "new". Since the file named
"text", if it exists, is completely named "text", it's name does not contain
the string "old.txt" in it, and thus will not be renamed.
A good example of the use of rename would be
rename .htm .html *.htm
which would rename all the files that match the "*.htm" regexp such that the
".htm" in the filename is replaced with ".html". For example
pitchl@srdscs05:~/temp$ ls
a.htm b.htm c.Htm d.html
pitchl@srdscs05:~/temp$ rename .htm .html *.htm
pitchl@srdscs05:~/temp$ ls
a.html b.html c.Htm d.html
Note that a.htm became a.html, b.htm became b.html, but c.Htm and d.html did
not change names.
--
Lew Pitcher, IT Consultant, Application Architecture
Enterprise Technology Solutions, TD Bank Financial Group
(Opinions expressed here are my own, not my employer's)
- Posted by John J. Trammell on January 23rd, 2004
On Fri, 23 Jan 2004 09:39:58 +0000, Xiaoshen Li <xli6@gmu.edu> wrote:
RTWFM
Read the *whole* fine manpage. My manpage for 'cp' is only 148
lines long, just about two pages.
If you don't understand what the "--backup" option does, search
that manpage for the string "--backup" and read every section
mentioning it.
This has nothing to do with linux or even computers, just basic
research skills.
It's not obvious that you need to use it at all. I never have.
- Posted by P.T. Breuer on January 23rd, 2004
Xiaoshen Li <xli6@gmu.edu> wrote:
It means that "--backup" is a comamndline switch. Or you can write
"--backup=1" (or whatever is a valid "CONTROL" - see the man page).
This is standard (informal) BNF.
I don't know any concrete examples.
What's the difficulty? Looks plain to me. [OPTION] means
"possibly an option". The ellipsis after it means "repeated" (if you
like).
Well it ought to say what "CONTROL" means. It does, later on:
none, off
never make backups (even if --backup is given)
numbered, t
make numbered backups
existing, nil
numbered if numbered backups exist, simple other
wise
simple, never
always make simple backups
What was the question?
Peter
- Posted by General Schvantzkoph on January 23rd, 2004
On Thu, 22 Jan 2004 18:03:43 +0000, Xiaoshen Li wrote:
Use mv
- Posted by Michael Heiming on January 23rd, 2004
P.T. Breuer <ptb@oboe.it.uc3m.es> wrote:
The OP might like to try our beloved GNU info system, 'info cp'
contains some examples on my box.

[..]
--
Michael Heiming
Remove +SIGNS and www. if you expect an answer, sorry for
inconvenience, but I get tons of SPAM
- Posted by Ed Murphy on January 24th, 2004
On Fri, 23 Jan 2004 09:51:48 +0000, Xiaoshen Li wrote:
Learn to use the 'man' command. It's a cliche because it's true!
'man rename'
'rename foo bar *.html' will go through all files matching *.html,
and replace the first occurrence of 'foo' (if any) with 'bar':
foo.html -> bar.html
foofoo.html -> barfoo.html
xyz.foo -> xyz.bar
foo.txt -> foo.txt