- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: How to rename all files in bulk.
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2001 11:49 AM
01-25-2001 11:49 AM
How to rename all files in bulk.
[/logs]$>gis1.log
[/logs]$>gis2.log
[/logs]$>gis3.log
.
.
.
Now the following command does not work:
$mv *.log *.bak
Thanks,
Gulam.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2001 11:55 AM
01-25-2001 11:55 AM
Re: How to rename all files in bulk.
do
mv $i $(basname $i .log).bak
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2001 12:20 PM
01-25-2001 12:20 PM
Re: How to rename all files in bulk.
echo *.log |while read i
do
mv $i ${i%log}bak
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2001 12:46 PM
01-25-2001 12:46 PM
Re: How to rename all files in bulk.
ls *.log | sed "s/\(.*\)\.log $/mv '&' '\1.bak'/" | sh
remove the | sh to see what the command would do
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2001 12:59 AM
01-26-2001 12:59 AM
Re: How to rename all files in bulk.
I've been looking for a similar solution. Out of the 3 listed only Carson's appeared to work but be careful to type basename not basname as basname will delete all the *.log files
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2001 02:05 AM
01-26-2001 02:05 AM
Re: How to rename all files in bulk.
I would do like this:
cd DIR
ls -1 *.log | awk -F "." '{system("mv "$0 " "$1".bak")}'
I hope this helps
Federico
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2001 05:54 AM
01-26-2001 05:54 AM
Re: How to rename all files in bulk.
>for NAME in `*.log` ; do
>BASE=`basename ${$} .log`
>NEWNAME="${BASE}.bak"
>echo "Renaming $NAME to $NEWNAME"
>/usr/bin/mv ${NAME} ${NEWNAME}
>sleep 1
>done
If you want to see what is occurring, then use some echo statements in your loop. The sleep will give you 1 second to look at what is happening in the loop.
This will work in Cshell
>foreach NAME (`ls *.log)
>BASE=`basename ${$} .log`
>NEWNAME="${BASE}.bak"
>echo "Renaming $NAME to NEWNAME"
>/usr/bin/mv ${NAME} {NEWNAME}
>sleep 1
>end
In both cases you should first understand the loops in the shell your using. also, understand the primary command being used to derive the new name.
man ksh
man sh
man csh
man basename
It would be recommended as well to get a book or two or three on shells and shell scripting. This is pretty basic shell programing which most admins need to understand.
Regards,
Shannon
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2001 10:20 AM
01-26-2001 10:20 AM
Re: How to rename all files in bulk.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2001 10:37 AM
01-26-2001 10:37 AM
Re: How to rename all files in bulk.
foreach f ( *.log )
mv $f $f:r.bak
end
(The :r modifier strips off the filename extension.)
If sh:
for f in *.log
do
mv $f `basename $f .log`.bak
done
This only works properly if the files are in the current directory.
If that's not the case, change the "mv" line to:
mv $f `dirname $f`/`basename $f .log`.bak