mv

Is there any shortcut to reference the path of the first argument in a MV command?

倾然丶 夕夏残阳落幕 提交于 2019-11-29 02:01:14
I often find myself using mv to rename a file. E.g. mv app/models/keywords_builder.rb app/models/keywords_generator.rb Doing so I need to write (ok, tab complete) the path for the second parameter. In this example it isn't too bad but sometimes the path is deeply nested and it seems like quite a bit of extra typing. Is there a more efficient way to do this? You can use history expansion like this: mv app/modules/keywords_builder.rb !#^:h/keywords_generator.rb ! introduces history expansion. # refers to the command currently being typed ^ means the first argument :h is a modifier to get the

Use xargs to mv a directory from find results into another directory

旧城冷巷雨未停 提交于 2019-11-28 17:30:52
问题 I have the following command: find . -type d -mtime 0 -exec mv {} /path/to/target-dir \; This will move the directory founded to another directory. How can I use xargs instead of exec to do the same thing. 回答1: If you've got GNU mv (and find and xargs ), you can use the -t option to mv (and -print0 for find and -0 for xargs ): find . -type d -mtime -0 -print0 | xargs -0 mv -t /path/to/target-dir Note that modern versions of find (compatible with POSIX 2008) support + in place of ; and behave

How to use 'mv' command to move files except those in a specific directory?

≡放荡痞女 提交于 2019-11-28 16:26:39
问题 I am wondering - how can I move all the files in a directory except those files in a specific directory (as 'mv' does not have a '--exclude' option)? 回答1: Lets's assume the dir structure is like, |parent |--child1 |--child2 |--grandChild1 |--grandChild2 |--grandChild3 |--grandChild4 |--grandChild5 |--grandChild6 And we need to move files so that it would appear like, |parent |--child1 | |--grandChild1 | |--grandChild2 | |--grandChild3 | |--grandChild4 | |--grandChild5 | |--grandChild6 |-

Is there a way to make mv create the directory to be moved to if it doesn't exist?

谁都会走 提交于 2019-11-28 15:44:58
So, if I'm in my home directory and I want to move foo.c to ~/bar/baz/foo.c , but those directories don't exist, is there some way to have those directories automatically created, so that you would only have to type mv foo.c ~/bar/baz/ and everything would work out? It seems like you could alias mv to a simple bash script that would check if those directories existed and if not would call mkdir and then mv, but I thought I'd check to see if anyone had a better idea. KarstenF How about this one-liner (in bash): mkdir --parents ./some/path/; mv yourfile.txt $_ Breaking that down: mkdir --parents

How to do a git diff on moved/renamed file?

岁酱吖の 提交于 2019-11-28 03:37:26
I moved a file using git mv . Now I would like to do a diff on the new file to compare it with the old file (with the old, now non-existent name). How do I do this? You need to use -M to let git autodetect the moved file when diffing. Using just git diff as knittl mentioned does not work for me. So simply: git diff -M should do it. The documentation for this switch is: -M[<n>], --find-renames[=<n>] Detect renames. If n is specified, it is a threshold on the similarity index (i.e. amount of addition/deletions compared to the file’s size). For example, -M90% means git should consider a delete

Is there a way to make mv create the directory to be moved to if it doesn't exist?

心已入冬 提交于 2019-11-27 19:46:32
问题 So, if I'm in my home directory and I want to move foo.c to ~/bar/baz/foo.c , but those directories don't exist, is there some way to have those directories automatically created, so that you would only have to type mv foo.c ~/bar/baz/ and everything would work out? It seems like you could alias mv to a simple bash script that would check if those directories existed and if not would call mkdir and then mv, but I thought I'd check to see if anyone had a better idea. 回答1: How about this one

Spring mvc Ambiguous mapping found. Cannot map controller bean method

徘徊边缘 提交于 2019-11-27 15:32:52
问题 I am trying to build an app which can list some values from the database and modify, add, delete if necessary using Spring 4 and i receive the following error(only if the "@Controller" annotation is present in both of my controller files, if i delete the annotation from one of the files it works but i get a message in console "no mapping found ... in dispatcherservlet with name ...): INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/edit/

How to move or copy files listed by 'find' command in unix?

跟風遠走 提交于 2019-11-27 11:13:17
I have a list of certain files that I see using the command below, but how can I copy those files listed into another folder, say ~/test? find . -mtime 1 -exec du -hc {} + Ankur Adding to Eric Jablow's answer, here is a possible solution (it worked for me - linux mint 14 /nadia) find /path/to/search/ -type f -name "glob-to-find-files" | xargs cp -t /target/path/ You can refer to " How can I use xargs to copy files that have spaces and quotes in their names? " as well. Thiyagu ATR Actually, you can process the find command output in a copy command in two ways: If the find command's output doesn

How do the UNIX commands mv and rm work with open files?

一世执手 提交于 2019-11-27 08:55:16
If I am reading a file stored on an NTFS filesystem, and I try to move/rename that file while it is still being read, I am prevented from doing so. If I try this on a UNIX filesystem such as EXT3, it succeeds, and the process doing the reading is unaffected. I can even rm the file and reading processes are unaffected. How does this work? Could somebody explain to me why this behaviour is supported under UNIX filesystems but not NTFS? I have a vague feeling it has to do with hard links and inodes, but I would appreciate a good explanation. Unix filesystems use reference counting and a two-layer

How can I rewrite history so that all files, except the ones I already moved, are in a subdirectory?

流过昼夜 提交于 2019-11-27 06:22:45
I have a project under git . One day I moved all project files from current directory to foo/bar/ under the project. I did it using git mv . Then I added some more files and did some changes to already existing files. As a result, now when I look at the history of foo/bar/file.c , I can only see changes that I did after I moved the file. I tried to fix this in various ways ( filter-branch with subdirectory filter, etc), but nothing helped, so I am pretty stacked here. I'll appreciate any help that you can give me. Thanks! Dan Moulding To rewrite the history with the files moved: If you want