rename all file with blank in directory from home root , please help me


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting rename all file with blank in directory from home root , please help me
# 1  
Old 09-18-2012
rename all file with blank in directory from home root , please help me

hi ,

Smilie

I've in directory home user 3 file with blank space in name file, I would like erase the all character that no have alphanum more dot in namefile from home root , below the script.
If I execute the shell script from directory where stay it's execute well done.But I would like execute the script from home root , like so:
/var/www/html/regia0/temp/f/./ren in this case after execute the sh script erase all file in /var/www/html/regia0/temp/f/ and no rename the files, below the script work well only if I execute from the same directory where is present the hidden script. Please Help me
SmilieSmilieSmilie
Thanks a lot


Code:
#ren.sh
for file in *
do
mv "$file" $(echo "$file" | sed 's/[^A-Za-z0-9.]//g')
done;

---------- Post updated at 11:03 AM ---------- Previous update was at 10:41 AM ----------

ok, I'm solved It's was very simple

Code:
cd /var/www/html/regia0/temp/f  #  here the solution
for file in *
do
mv "$file" $(echo "$file" | sed 's/[^A-Za-z0-9.]//g')
done;

Thanks again at this forum
# 2  
Old 09-18-2012
Code:
 
#!/bin/sh
 
[[ -z "$1" ]] && exit
dir="$1"

for file in ${dir}/*
do
 dr=${file%/*}
 fb=${file##*/}
 fa=${file##*/}
 echo $fa | read fa
 [[ "$file" = "$dr/$fa" ]] || mv "$file" "$dr/$fa"
done;

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

SunOS confusing root directory and user home directory

Hello, I've just started using a Solaris machine with SunOS 5.10. After the machine is turned on, I open a Console window and at the prompt, if I execute a pwd command, it tells me I'm at my home directory (someone configured "myuser" as default user after init). ... (2 Replies)
Discussion started by: egyassun
2 Replies

2. UNIX for Beginners Questions & Answers

Rename the file name from Parent directory

Hi All, Just started learning unix and stuck into below issue. Suppose i have folder structure as below. Dir1/Dir2/Dir3/File1.msg I am looking to rename the file name from File1.msg to File2.msg but from the parent Dir1 From Dir3 i can easily run the command like mv File1.msg... (2 Replies)
Discussion started by: Gurjeet Singh
2 Replies

3. Shell Programming and Scripting

Rename specific file extension in directory with match to another file in bash

I have a specific set (all ending with .bam) of downloaded files in a directory /home/cmccabe/Desktop/NGS/API/2-15-2016. What I am trying to do is use a match to $2 in name to rename the downloaded files. To make things a more involved the date of the folder is unique and in the header of name... (1 Reply)
Discussion started by: cmccabe
1 Replies

4. Shell Programming and Scripting

Find users with root UID or GID or root home

I need to list users in /etc/passwd with root's GID or UID or /root as home directory If we have these entries in /etc/passwd root:x:0:0:root:/root:/bin/bash rootgooduser1:x:100:100::/home/gooduser1:/bin/bash baduser1:x:0:300::/home/baduser1:/bin/bash... (6 Replies)
Discussion started by: anil510
6 Replies

5. Shell Programming and Scripting

Cannot run this .java file from the home directory??

I wrote a simple test.java program in vi. I know it compiles correctly because I went into the directory where test.java was and compiled it and it created a java.class. I then ran test.java by staying in the same directory where it was and it worked great. However, when i backed out of the... (3 Replies)
Discussion started by: syregnar86
3 Replies

6. Shell Programming and Scripting

Looking for config file in home directory first??

hi, i have written a shell script inside which i am using a pgp command to encrypt a file. when pgp command is run , there is a /.pgp/pgp.cfg file in my home directory. i logged into the unix server with my userid, when i run the script from the command prompt, pgp is successful, since i am... (5 Replies)
Discussion started by: Little
5 Replies

7. Shell Programming and Scripting

Rename last directory in a file structure

I have to write a script to rename the every last sub-directory in a directory structure if the last sub-directory name doesn't contain "submitted". eg: given directory path:/u01/home/somedir somedir can have many subdirectories and each subdirectory inturn has many subdirectories. somedir... (3 Replies)
Discussion started by: ramse8pc
3 Replies

8. Shell Programming and Scripting

Rename multiple file names in a directory

I hope some one can help me I have multiple files in a directory with out extension like as below mentioned. But i want to change all the file names along .DDMMYYYYHHMISS format. And all files should have same DDMMYYYYHHMISS. Scenario: direcory name = /vol/best/srcfiles files in a... (4 Replies)
Discussion started by: hari001
4 Replies

9. UNIX for Dummies Questions & Answers

How to get the latest modified file name in /home directory?

I only know how to list all sub-directories or files in specified directory. I don't know how to order them by modified date, furthermore, I don't know how to get the top one file in the sorted list. Wish you can do me a favor. Thanks in advance! (3 Replies)
Discussion started by: crest.boy
3 Replies

10. Solaris

running sshd server from home directory without root access

Hi, I managed to install openssh from source on my home directory on a server I don't have root access to. I had problems with privilege separation because of permissions initially so I disabled it in sshd_config. But when I run sshd from where I installed it by doing ~/local/sbin/sshd, nothing at... (0 Replies)
Discussion started by: sayeo
0 Replies
Login or Register to Ask a Question