GithubHelp home page GithubHelp logo

innovations's People

Contributors

samitks avatar

innovations's Issues

How "mv file_name *" works?

Generally, mv command moves the files/directories from SOURCE to DESTINATION. The last argument in mv always considered as DESTINATION.

So, if we use the below command to move one or more files to a directory, it will move those files from the current location to the provided destination.

$ mv file1.txt file2.txt dir1

( file1.txt and file2.txt will be moved to dir1 )

$ mv acp.txt *

Here, the case is little different because in the place of DESTINATION, we have given * (a wildcard character).

In linux, *generally denotes "all" and if we use it in the shell under a directory, it expands to all the files and directories under that folder. See below:

$ echo *
acp.jax acp.txt test1 test2 test4 virt2 virt21
$ 

(Here, acp.jax, acp.txt, virt2 are files and others are directories.)

So, now if I try to run $ mv acp.txt *, the * is getting expanded with the list of all files/directories under the current PWD. Please see below, how a wildcard get expanded here.

$ echo mv acp.txt *
mv acp.txt acp.jax acp.txt test1 test2 test4 virt2 virt21
$ 

Here, we can clearly see the complete command has become like mv acp.txt acp.jax acp.txt test1 test2 test4 virt2 virt21. It means, the directory 'virt21' has become the DESTINATION. Everything should get moved to directory 'virt21'.

$ mv acp.txt *
mv: cannot stat 'acp.txt': No such file or directory
$ ls
virt21
$ ls virt21/
acp.jax  acp.txt  test1  test2  test4  virt2
$  

( In my case, the * is getting expanded in alphabetical. It's output is generally same as ls.)

In case, after the expansion of * the last argument is a file, then the mv command should fail simply without moving any files because for moving multiple files, the destination must be a directory. Check the below command

$ echo mv acp.txt * 
mv acp.txt acp.jax acp.txt test1 test2 test4 virt2 virt21 zebra.txt
$ mv acp.txt * 
mv: target 'zebra.txt' is not a directory
$ ls
acp.jax  acp.txt  test1  test2  test4  virt2  virt21  zebra.txt
$

Hope, the explantion here will be helpful.

Feel free to post comments if you find any mistakes or the other possibilities with mv

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.