Remove part of file names in a directory


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Remove part of file names in a directory
# 1  
Old 10-31-2011
Remove part of file names in a directory

Hi,

i have a directory full of pictures, .jpg files. Half of them begin with "beach_" (for ex beach_123_123456.jpg)
i'm looking for a command to remove the "beach_" from all files in the directory.

thanks
# 2  
Old 10-31-2011
There are several ways you can do it - here is one of them:
Code:
#!/usr/bin/ksh
ls -1 beach_*.jpg | while read mFName; do
  mNewFName=$(echo ${mFName} | sed 's/beach_//')
  echo "Now renaming ${mFName} to ${mNewFName}"
  mv ${mFName} ${mNewFName}
done

This User Gave Thanks to Shell_Life For This Post:
# 3  
Old 10-31-2011
MySQL

thanks! it works perfectly.
# 4  
Old 11-01-2011
Hi,
Can you try with this code . It worked for me

Code:
ls -lrt | sed 's/beach_//g'

Regards,
Haris
# 5  
Old 11-01-2011
one more way ..
Code:
$ ls beach_*.jpg | nawk '{print "mv "$0; sub(/beach_/, "")};1' | paste - - | sh

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove dates from file names

Hi, I'm using a shell script. I have extracted current date files to a directory1 and the date should be removed on both sides of a CSV file. FYI... I'm looking to remove the date from the file name and not inside the CSV file. Directory1 2017-07-12_gmr_tag_log_20170711.csv... (0 Replies)
Discussion started by: shivamayam
0 Replies

2. Shell Programming and Scripting

Remove all files with specific file names in directory

If I have 5 files in a directory, what is the best way to remove specific files in it? For example, snps.ivg probes.ivg Desired output probes.ivg probes.txt all.txt Basically, removing those files with "snp" in the filename regardless of extension. Thank you :). (2 Replies)
Discussion started by: cmccabe
2 Replies

3. Shell Programming and Scripting

Selecting/using part of directory names in script

I'm making a shell script to: -copy directories to a new location -perform conversions on the files within the copied directories -move the newly created files to a new directory Please see my super basic script and notes below... and thank you thank you thank you in advance !! ... (1 Reply)
Discussion started by: kayzee
1 Replies

4. Shell Programming and Scripting

Remove spaces from start of file names

Hi, I have a directory with the following file names 01 - abc hyn 02-def 03-ghi.dir 04 - jhu.dir abc1 kil def bil The last two file names abc1 starts with one space and def starts with double space. I want these files in my directory to be renamed as ABC HYN DEF GHI.dir... (6 Replies)
Discussion started by: jacobs.smith
6 Replies

5. Shell Programming and Scripting

Grepping file names, comparing them to a directory of files, and moving them into a new directory

got it figured out :) (1 Reply)
Discussion started by: sHockz
1 Replies

6. UNIX for Dummies Questions & Answers

Deleting part of file names

My server got messed up and the names of my files were not completely processed. As results I ended up getting a bunch of files with the following names: I need to remove the underscore and everything before it. Thus, the files will be renamed to something like this: Any help will be greatly... (3 Replies)
Discussion started by: Xterra
3 Replies

7. Shell Programming and Scripting

Remove special character ($) from file names

Hello I've searched here and on the 'net for examples of a script or command line function that will remove the $ character from all file names only that can be done within the directory that contains the file names - which are all html files. ie, I have a directory that contains html files... (6 Replies)
Discussion started by: competitions
6 Replies

8. Shell Programming and Scripting

Searching for file names in a directory while ignoring certain file names

Sun Solaris Unix Question Haven't been able to find any solution for this situation. Let's just say the file names listed below exist in a directory. I want the find command to find all files in this directory but at the same time I want to eliminate certain file names or files with certain... (2 Replies)
Discussion started by: 2reperry
2 Replies

9. Shell Programming and Scripting

Remove spaces between file names

Hi All, I have spaces in between file names. "Material Header.txt" "Customer Header.txt" "Vendor Header.txt" And how can I remove spaces between file names like below MaterialHeader.txt CustomerHeader.txt VendorHeader.txt Thanks Srimitta (10 Replies)
Discussion started by: srimitta
10 Replies

10. Shell Programming and Scripting

how to remove files with only numbers as file names?

Hi all, I have a bunch of files that are named like 12543, 467249877, etc all over some directories.These files are named only with numbers, they dont have any letters or special characters in their file names. Could you please help me out and give me some command/script to remove only those... (6 Replies)
Discussion started by: praveen_indramo
6 Replies
Login or Register to Ask a Question