Relocate a file or directory, but keep it accessible on the old location throug a simlink.

mv $1 $2 && ln -s $2/$(basename $1) $(dirname $1)
Used for moving stuff around on a fileserver

18
By: svg
2009-05-25 08:54:36

What Others Think

sweet. i've made it a function in all my .bash_profiles. function lmv(){ [ -e $1 -a -e $2 ] && mv $1 $2 && ln -s $2/$(basename $1) $(dirname $1); }
thebillywayne · 714 weeks and 3 days ago
It only works, if $2 is a directory, though.
jxy · 714 weeks and 3 days ago
Also does not play nice with files that have spaces or meta-characters in the names.
TheMightyBuzzard · 714 weeks and 2 days ago
Always _quote_ the variables!
jxy · 714 weeks and 2 days ago
from AlvinaSimpson over on lifehacker.com: lmv() { [ -e "$1" -a -e "$2" ] && mv "$1" "$2" && ln -s "$2"/"$(basename "$1")" "$(dirname "$1")"; } Me, I'd add one more bit and say go from [ -e "$1" -a -e "$2" ] to [ -e "$1" -a -d "$2" ] and from mv "$1" "$2" to mv "$1" "$2"/ That should take care of any accidental file overwrites from trying to use wildcards with this command as it requires $2 be a directory and appends a trailing / so we don't accidentally try to overwrite the directory $2
TheMightyBuzzard · 714 weeks and 2 days ago
By default, you shouldn't be trying to symlink when you do this; you only need to use symlinks when you're going from one physical drive to another. The files that we see in the filesystem are pointers to the actual data on the drive. By creating a hard link, we have two real pointers to the same data; if one is removed, the other exists still, and the data is still "found" by the filesystem. If the original hardlink disappears but the symlink still exists, the symlink won't work. When trying to do a "safe move" using links, hard links is what you should use.
adamskinner · 714 weeks and 1 day ago
great suggestions for improving the function! i love this place!
thebillywayne · 714 weeks and 1 day ago
Any recommendations to make this usable on directories with spaces or special characters? I want to use it to relocate bittorrent files regularly to another disk and they rarely have proper filenames. by recommendations I mean a simpler way than writing/stealing code to escape all the special characters. I'm lazy and slow!
awoodby · 711 weeks and 6 days ago
lmv(){for a in ${@:1:$(expr $#-1)};do [ -e "$a" -a -e "${@:$#:1}" ] && mv "$a";"${@:$#:1}" && ln -s "${@:$#:1}"/"$(basename "$a")";"$(dirname "$a")";done} for multiple folders (e.g. lmv files/* newfolder would move file/* to newfolder while symlinking them)
matthewbauer · 684 weeks and 5 days ago
lmv(){for a in ${@:1:$(expr $#-1)};do [ -e "$a" -a -e "${@:$#}" ] && mv "$a";"${@:$#}" && ln -s "${@:$#}"/"$(basename "$a")";"$(dirname "$a")";done}
matthewbauer · 684 weeks and 5 days ago
I like it very much, and I am looking forward to Hearing from your next. I recommend you to visit my site on Touch Typing Practice for wpm test online. One of the new methods of typing that has become ground in recent times is touch typing. This is a faster and more efficient way of typing and is better than the traditional ‘hunt and peck method. You can also check your touch typing speed with the wpm test tool free of cost online. Click here : http://why-touch-typing-practice-is-important.launchrock.com
AddieHolt · 85 weeks and 5 days ago
Dropbox is awesome. It makes file syncing (and sharing) easier and more reliable. But sometimes, you may want to sync a local directory to your Dropbox for some reasons (privacy, security. To check this https://techflog.com/advantage-of-online-casino-free-spins/ and get more things about gaming. Normally it's not possible, you can only sync files/directories in your Dropbox folder to your computer... until Dropbox enabled
Michael001 · 36 weeks and 5 days ago
Relocating a file or directory is easy with a Simulink. In this article we will look at relocating shared data across a network and keeping it accessible to collages at the old location. Also you can check https://programminginsider.com/how-to-choose-a-reputable-uk-casino-site/ and get some new things about the casino game. We will also go over some of the dos and don'ts of simlinking, so you can employ this process without accidentally breaking your SharePoint farm!
NoahM012 · 32 weeks and 2 days ago
Pug Puppies for Sale Near Me pugs puppies for sale teacup pugs for sale pug puppies for sale by owner pug puppies ohio PUG PUPPY FOR SALE NEAR ME PUG PUPPIES FOR SALE pug puppies for sale in kentucky Pug Puppies for Sale Under $500 Near Me pug puppies for sale in texas pug puppies for sale $200 pugs for sale near me under $500 pugs for sale under $400 near me pugs for sale near me puppies for sale near me under $500 pug puppies for sale under $1,000 near me pug for sale pug puppies for sale under $300 Brindle Pug Pitbull Pug Mix Pugs for sale cheap Cheap pug affordable pug puppies for sale near me black pugs for sale near me White Pugs for sale pug dog for sale free pug puppies pug puppies for sale in my area mn pug breeders pug puppies indiana pugs for sale michigan PUG PUPPY ADOPTION Pug puppies for sale Pug puppies for sale near me Pug puppies near me Pug Puppies for Sale Under $500 Near Me Cute Pug Puppies Black pug puppies Black pug puppies for sale pug puppies for adoption black pug puppies for sale near me chihuahua pug mix puppies how much is a pug puppy teacup pug puppies baby pug puppies pictures of pug puppies pug puppies for sale in Ohio pug puppies price pug mix puppies teacup pug puppies for sale best food for pug puppy newborn pug puppies pug puppies craigslist pug puppies for sale craigslist adorable pug puppies how much does a pug puppy cost Pitbull pug mix puppies pug pit mix puppy pug puppies for sale $200 pug puppies for sale in NJ Pug puppies for sale in Wisconsin pug puppy cost pug puppy food royal canin pug puppy royal canin pug puppy food fawn pug puppy pug puppies for sale florida pug puppies for sale in Indiana pug puppies for sale in KY pug puppies for sale in NC pug dog puppy AKC Registered Pug Puppies For sale cheap pug puppies for sale near me cheap pug puppies for sale in California cheap pug puppies for sale in nj Black Pug Puppies for sale pugs puppies for sale pug puppies indiana Amazing! This blog looks just like my old one! It's on a completely different subject but it has pretty much the same layout and design. Wonderful choice of colors!
rahimhh21 · 21 weeks and 3 days ago
Since 2008, Perfect House Pug Puppies has been the leading Pug puppy breeder in the US, providing premium Pug puppies for sale. Each puppy exhibits the professionalism and knowledge that have set Perfect House Pug puppies apart from other pug puppy breeders. The professionals at Perfect House Pug Puppies are dedicated about finding their puppies loving, beloved homes where they can enjoy long, healthy lives. A companion that has been produced for quality, health, and temperament that satisfies the breed standard is guaranteed by Perfect House Pug puppies, the pug breeder that has set the benchmark for exceptional customer satisfaction. If you are looking to buy a baby pug, Black and white pugs, Mini pug puppies for sale, Black and tan pug for sale, Teacup pug puppies for sale, Female pug puppies, pug puppies for sale, pug puppies for sale near me, pug puppies for sale under $500 near me. Pug Puppies for Sale Near Me pugs puppies for sale teacup pugs for sale pug puppies for sale by owner pug puppies ohio PUG PUPPY FOR SALE NEAR ME PUG PUPPIES FOR SALE pug puppies for sale in kentucky Pug Puppies for Sale Under $500 Near Me pug puppies for sale in texas pug puppies for sale $200 pugs for sale near me under $500 pugs for sale under $400 near me pugs for sale near me puppies for sale near me under $500 pug puppies for sale under $1,000 near me pug for sale pug puppies for sale under $300 Brindle Pug Pitbull Pug Mix Pugs for sale cheap Cheap pug affordable pug puppies for sale near me black pugs for sale near me White Pugs for sale pug dog for sale free pug puppies pug puppies for sale in my area mn pug breeders pug puppies indiana pugs for sale michigan PUG PUPPY ADOPTION Pug puppies for sale Pug puppies for sale near me Pug puppies near me Pug Puppies for Sale Under $500 Near Me Cute Pug Puppies Black pug puppies Black pug puppies for sale pug puppies for adoption black pug puppies for sale near me chihuahua pug mix puppies how much is a pug puppy teacup pug puppies baby pug puppies baby pug puppies for sale pictures of pug puppies pug puppies for sale in Ohio pug puppies price pug mix puppies teacup pug puppies for sale best food for pug puppy newborn pug puppies pug puppies craigslist pug puppies for sale craigslist adorable pug puppies how much does a pug puppy cost Pitbull pug mix puppies pug pit mix puppy pug puppies for sale $200 pug puppies for sale in NJ Pug puppies for sale in Wisconsin pug puppy cost pug puppy food royal canin pug puppy royal canin pug puppy food fawn pug puppy pug puppies for sale florida pug puppies for sale in Indiana pug puppies for sale in KY pug puppies for sale in NC pug dog puppy AKC Registered Pug Puppies For sale cheap pug puppies for sale near me cheap pug puppies for sale in California cheap pug puppies for sale in nj Black Pug Puppies for sale pugs puppies for sale
Perfecthomepugs · 13 weeks and 2 days ago
Manchester City will host Brentford at the Etihad Stadium in Week 16 of the 2022/2023 Premier League. This Premier League match ended bitterly for City. They lost to the guest with a score of 1-2. Ivan Toney put Brentford ahead in the 16th minute, then Phil Foden equalized for City in the 45+5 minutes. City were forced to bite their fingers after Ivan Toney scored the second goal for Brentford in this match in the 90+8 minute. City still has 32 points in second place. If standings leader Arsenal (34 points) later wins over host Wolverhampton, then the point difference between them will be five. This is the last Premier League match before the 2022 World Cup break. Clubs will compete again starting in December 2022. Manchester City Falls at Home Brentford surprisingly took the initiative to attack. After several times pounding City's back line in the early minutes, Brentford was even able to steal the first goal. Ivan Toney, who was recently left out of England's squad for the 2022 World Cup, fired Brentford ahead at the reigning champions with a header. City, of course, did not remain silent. However, City could only equalize at the end of the first half. Starting from Kevin De Bruyne's corner, which first hit Manuel Akanji's head, Foden equalized the score with his left foot. black panther wakanda forever streaming vf one piece red pelicula completa ".' Premier League Premier League After a draw in the first half, the match went tough in the second half. Citu dominated and created more chances, but their finishing was not optimal. Erling Haaland performed well below his best standards. Throughout the match, the Premier League's temporary top scorer was recorded as only releasing one shot, and that too was off target. City actually get disastrous in injury time. From Josh Dasilva's assist, Brentford scored the second goal as well as the decisive goal. That goal was scored by the same player who scored the opener, Ivan Toney. Ivan Toney's brace also made The Citizens fall at the Etihad Stadium. Starting XI and Match Statistics Manchester City (4-3-3): Ederson; John Stones, Manuel Akanji, Aymeric Laporte, Joao Cancelo; Kevin De Bruyne, Rodri, Ilkay Gundogan; Phil Foden, Erling Haaland, Bernardo Silva. Coach: Josep Guardiola. Brentford (3-5-2): David Raya; Zanka, Ben Mee, Ethan Pinnock; Mads Roerslev, Frank Onyeka, Vitaly Janelt, Mathias Jensen, Rico Henry; Bryan Mbeumo, Ivan Toney.
masdani233 · 11 weeks and 5 days ago
. . . . . . . . . . on22.123movie-hd.com . . . . . . . . . . . . . . . . . . . . . . . . .
gerybara45 · 11 weeks and 3 days ago
# # # # # # # # # # EggragBagreg # # # # # # # # # # # # #
gerybara45 · 10 weeks and 1 day ago
'*' '*' '*' '*' '*' '*' '*' '*' '*' '*' '*' YouTube Chanel '*' '*' '*' '*' '*' '*' '*' '*' '*' '*' '*' '*' '*' '*' '*' '*' '*' '*' '*' '*' '*' '*' '*' '*'
gerybara45 · 9 weeks and 4 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: