LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-16-2016, 04:34 AM   #1
ddenial
Member
 
Registered: Dec 2016
Distribution: CentOS, Fedora, Ubuntu
Posts: 359

Rep: Reputation: 56
Can we shorten path while renaming files?


Hi

Can we shorten the path while renaming or copying files in terminal?

For example, while in /, if I want to rename a file with very long path, is there a trick so I could avoid/shorten path in <target> argument.

Code:
mv /etc/fonts/infinality/styles.conf.avail/linux/fileA.txt  /etc/fonts/infinality/styles.conf.avail/linux/fileB.txt
I'm new to terminal and I do lot of house keeping job. Its very painful to type very long paths every time I do some file management.

I've heard Linux is very flexible and several tricks can be applied to achieve desired result. I'm hoping for at-least some direction on how to achieve it.

Thanks
 
Old 12-16-2016, 05:02 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,305
Blog Entries: 3

Rep: Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720
If you are using bash, zsh, or ksh, you can use tab-completion. So when you get to a unique part of the path, press tab and the rest of the unique part will get filled in. That saves on a lot of typing.

Code:
mv /etab/fotab/itab/sttab/ltab/fileA.txt  /etab/fotab/itab/sttab/ltab/fileB.txt
Another option, is if you are moving or renaming files inside the same directory, you can cd to that directory and work there.

Code:
cd /etc/fonts/infinality/styles.conf.avail/linux/
mv fileA.txt fileB.txt
 
Old 12-16-2016, 05:27 AM   #3
Jjanel
Member
 
Registered: Jun 2016
Distribution: any&all, in VBox; Ol'UnixCLI; NO GUI resources
Posts: 999
Blog Entries: 12

Rep: Reputation: 363Reputation: 363Reputation: 363Reputation: 363
IF you've already typed/'tabbed' the path, mv long/path/file{A,B}.ext
(test by using echo in place of the mv; good for {,.bak} or ,- )
http://unix.stackexchange.com/questi...directory-path (note lmv fcn)

[UNrelated ?4guru: I wish I knew how to like: `ip {a,r}` &get: ip a;ip r ]

Last edited by Jjanel; 12-16-2016 at 05:42 AM.
 
1 members found this post helpful.
Old 12-16-2016, 05:50 AM   #4
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,570
Blog Entries: 19

Rep: Reputation: 4451Reputation: 4451Reputation: 4451Reputation: 4451Reputation: 4451Reputation: 4451Reputation: 4451Reputation: 4451Reputation: 4451Reputation: 4451Reputation: 4451
Export an environmental variable called PATH and store the path in that. Then just use $PATH/filename.
 
Old 12-16-2016, 06:40 AM   #5
ddenial
Member
 
Registered: Dec 2016
Distribution: CentOS, Fedora, Ubuntu
Posts: 359

Original Poster
Rep: Reputation: 56
Quote:
Originally Posted by Jjanel View Post
IF you've already typed/'tabbed' the path, mv long/path/file{A,B}.ext
(test by using echo in place of the mv; good for {,.bak} or ,- )
http://unix.stackexchange.com/questi...directory-path (note lmv fcn)

[UNrelated ?4guru: I wish I knew how to like: `ip {a,r}` &get: ip a;ip r ]
Super Cool!. This worked-out for me.

Code:
# mv /etc/fonts/infinality/styles.conf.avail/linux/{fileA.txt,fileB.txt}
Thank you very much. You saved a lot keystrokes.
 
Old 12-16-2016, 06:44 AM   #6
fatmac
LQ Guru
 
Registered: Sep 2011
Location: Upper Hale, Surrey/Hants Border, UK
Distribution: Mainly Devuan, antiX, & Void, with Tiny Core, Fatdog, & BSD thrown in.
Posts: 5,484

Rep: Reputation: Disabled
Copy & paste in the terminal.

Highlight the part you want, move to where you want it, middle click.
 
Old 12-16-2016, 06:48 AM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,006

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Generally only have to type in the parts that are different in the braces:
Code:
mv /etc/fonts/infinality/styles.conf.avail/linux/file{A,B}.txt
 
2 members found this post helpful.
Old 12-20-2016, 07:22 AM   #8
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,789

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
If you want to temporarily change directory then you can use the pushd stack. Each popd returns from the last pushd.
Code:
pushd /etc/fonts/infinality/styles.conf.avail/linux/
mv fileA.txt fileB.txt
popd
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Moving files from parent path to multiple child path using bash in efficient way Karthikgv417 Programming 5 05-03-2015 10:05 PM
shorten command prompt current path mrpc_cambodia Linux - Newbie 7 01-05-2012 08:46 AM
[SOLVED] Perforce edits my files when I give a depot path but not if I specify the local path gregorian Linux - Software 1 10-21-2011 11:57 AM
How to shorten current path name cianoz Linux - Newbie 14 03-14-2011 07:50 AM
Converting Shorten files using Linux haystacs Linux - Software 5 05-08-2003 11:47 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration