Rename the file name from Parent directory

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Rename the file name from Parent directory
# 1  
Old 05-07-2017
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.

Code:
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

Code:
mv File1.msg File2.msg

.


But can i can run from parent directory if i already know the directory Path.

Any help would be much appreciated

Thanks
Gurjeet

Last edited by Scrutinizer; 05-07-2017 at 04:47 PM..
# 2  
Old 05-07-2017
Code:
mv -v Dir2/Dir3/File1.msg Dir2/Dir3/File2.msg

or if supported by your shell

Code:
mv -v Dir2/Dir3/File{1,2}.msg

# 3  
Old 05-07-2017
Even a temporary cd is possible - in a sub shell
Code:
(cd Dir2/Dir3 && mv File1.msg File2.msg)

The current directory in the main shell is not affected.
The sub shell can mean a little overhead because it is a copy of the main shell.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Sourcing file from parent directory bash

"Debian 9 64x - LXDE" I try to source a file from my parent directory: #!/bin/bash #source.bash . ../links.bash but i get "file not found". I tried . "../links.bash" and . '../links.bash'. I got on all methods the same result. If i use the absolute path it works, but i don't want to... (4 Replies)
Discussion started by: int3g3r
4 Replies

2. 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

3. Shell Programming and Scripting

Parent Child directory and file details

Kindly help below command details in UNIX. 1.What is the Unix command to see parent and child directory details starting from root directory in tree structure using LS-LRT or any other way 2.What is the Unix command to see parent and child directory details starting from root directory in... (2 Replies)
Discussion started by: skp
2 Replies

4. 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

5. Shell Programming and Scripting

Traverse file structure from top and rename the immediate parent

Hello All, I am trying to write a script to:- 1. Traverse entire file system, look for directories which has .git directory in it 2. Rename the immediate parent directory to <orignal_name.git> 3. Traverse new file structure and look for all directories with <original_name>.git 4. cd to... (2 Replies)
Discussion started by: sahil_jammu
2 Replies

6. 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

7. AIX

Parent directory seems to disappear if child fails rename

If I have a file/folder that a user does not have permission to and I try to rename it, it removes the entire parent folder. At that point it is only visible in a ls. (Not a ls -l, file, more, cd). It happens on every filesystem. This is Aix 5.3 $ cd test $ ls -la total 0 drwxr-xr-x 2 root ... (4 Replies)
Discussion started by: scriptr2be
4 Replies

8. Shell Programming and Scripting

Get parent directory of a file

In shell how would I get the parent directory of a file. E.g. I feed this in: /path/to/textfile.txt And get just: /path/to Thanks (2 Replies)
Discussion started by: pcwiz
2 Replies

9. Shell Programming and Scripting

Rename a file after the name of its parent dir

Started a thread in beginners but I thought someone from this forum may have an idea as well. Thanks! EDITED BY REBORG (3 Replies)
Discussion started by: robotsbite
3 Replies

10. Shell Programming and Scripting

full path of a file situated either in parent's dir. or parent's parent dir. so on...

hi experts(novice people can stay away as it is no child's game), i am developing a script which works like recycle bin of windows. the problem i am facing is that when ever i am trying to delete a file which is situated in parent directory or parent's parent directory i am unable to... (1 Reply)
Discussion started by: yahoo!
1 Replies
Login or Register to Ask a Question