Hot answers tagged

110

Since you have set a password for root, use su and busybox, installed by default in Ubuntu. All of su's required libraries are in /lib. Busybox is a collection of utilities that's statically linked, so missing libraries shouldn't be a problem. Do: su -c '/bin/busybox mv /usr_bak /usr' (While Busybox itself also has a su applet, the /bin/busybox binary is ...


106

If your shell supported Brace Expansion (works with csh, tcsh, ksh, zsh, bash, mksh, lksh, pdksh, yash with brace-expand enabled by calling yash --brace-expand or set in interative shell with set -o brace-expand, or fish): mv ~/folder/subfolder/file.{txt,sh}


96

With GNU mv: find path_A -name '*AAA*' -exec mv -t path_B {} + That will use find's -exec option which replaces the {} with each find result in turn and runs the command you give it. As explained in man find: -exec command ; Execute command; true if 0 status is returned. All following arguments to find are taken to be arguments ...


91

There's a new tool called progress that can find any descriptor related to a running command and show progress and speed: available here progress -w outputs the stats for all running cp,mv etc. operations


88

When moving files between filesystems, mv doesn't delete a file before it's finished copying it, and it processes files sequentially (I initially said it copies then deletes each file in turn, but that's not guaranteed — at least GNU mv copies then deletes each command-line argument in turn, and POSIX specifies this behaviour). So you should have at most one ...


87

xargs is the tool for the job. That, or find with -exec … {} +. These tools run a command several times, with as many arguments as can be passed in one go. Both methods are easier to carry out when the variable argument list is at the end, which isn't the case here: the final argument to mv is the destination. With GNU utilities (i.e. on non-embedded Linux ...


82

To replace # by somethingelse for filenames in the current directory (not recursive) you can use the GNU rename utility: rename 's/#/somethingelse/' * Characters like - must be escaped with a \. For your case, you would want to use rename 's/#U00a9/safe/g' * Note that if you only want to operate on a certain selection of files, e.g., only *.jpg, adjust ...


71

mv -vn file1 file2. This command will do what you want. You can skip -v if you want. -v makes it verbose - mv will tell you that it moved file if it moves it(useful, since there is possibility that file will not be moved) -n moves only if file2 does not exist. Please note however, that this is not POSIX as mentioned by ThomasDickey.


71

Changing the name on a folder is safe, if it stays within the same file system. If it is a mount point (/data kinda looks like it could be a mount point to me, check this with mount), then you need to do something other than just a simple mv since mv /data /BD_FILES would move the data to the root partition (which may not be what you want to happen). You ...


64

If a directory is moved within the same filesystem (the same partition), then all that is needed is to rename the file path of the directory. No data apart from the directory entry for the directory itself has to be altered. When copying directories, the data for each and every file needs to be duplicated. This involves reading all the source data and ...


63

mv is the wrong tool for this job; you want cp and then rm. Since you're moving the file to another filesystem this is exactly what mv is doing behind the scenes anyway, except that mv is also trying to preserve file permission bits and owner/group information. This is because mv would preserve that information if it were moving a file within the same ...


55

Use the update flag: -u Example: zip -ur existing.zip myFolder This command will compress and add myFolder (and it's contents) to the existing.zip. Advanced Usage: The update flag actually compares the incoming files against the existing ones and will either add new files, or update existing ones. Therefore, if you want to add/update a specific ...


52

Are you looking for this? $ mv file dir/ mv: cannot stat ‘file’: No such file or directory $ mv file dir/ 2>/dev/null # <---- Silent ----->


52

You can't rename a file to . or .. because all directories already contain entries for those two names. (Those entries point to directories, and you can't rename a file to a directory.) mv detects the case where the destination is an existing directory, and interprets it as a request to move the file into that directory (using its current name). ...


50

Adding a slash at the end of the destination path /opt/alfresco/archived/2020-01-07 would have made the mv command error out, as the 2020-01-07 directory evidently does not exist. This would have saved your files. They would also have been saved if /opt/alfresco/archived/2020-01-07 had been an existing directory (regardless of whether the destination path ...


46

Forget about trying to reinvent rsync, and use rsync. sudo rsync -av /location/to/drive1/ /location/to/drive2/ Make sure you use a trailing slash on the source, otherwise it would copy to /location/to/drive2/drive1. Double-check that the command succeeded, then run rm -rf /location/to/drive1/. The command above will overwrite any preexisting file from ...


43

You have renamed your file to myuser@mywebsite.org.Try renaming it back: mv myuser@mywebsite.org sqlreport.php


41

The usage of -f is more clearly described in the man page from 4BSD, which was where the -f and -i options were added: If file2 already exists, it is removed before file1 is moved. If file2 has a mode which forbids writing, mv prints the mode and reads the standard input to obtain a line; if the line begins with y, the move takes place; if not, mv exits. ...


37

You can append a / to the destination if you want to move files to a directory. In case the directory does not exist you'll receive an error: mv somefile somedir/ mv: cannot move ‘somefile’ to ‘somedir/’: Not a directory In case the directory exists, it moves the file into that directory.


36

As long as you don't move the file across file-system borders, the operation should be safe. This is due to the mechanism, how »moving« actually is done. If you mv a file on the same file-system, the file isn't actually touched, but only the file-system entry is changed. $ mv foo bar actually does something like $ ln foo bar $ rm foo This would create ...


36

On Linux (and on most other systems, though POSIX doesn't give you that guarantee unless the move was across file systems), that would have updated their ctime, so assuming none of the other ones in /usr/bin have been touched in the last 24 hours, you should be able to move them back with: find /usr/bin/. ! -name . -prune -ctime -1 -exec sh -c ' echo mv -...


36

Your file will be fine. Renaming a file will not alter the file's contents in any way whatsoever. In fact, you would still be able to successfully extract the contents of your compressed tar archive using tar -xvz -f opt where opt is the name you accidentally gave the file. Renaming it to its original name would obviously be of help to you for knowing ...


35

If you still have a root shell open, run cd / /.bin/mv .bin bin Your shell can’t find mv because it’s no longer on the path; giving the full path to it will allow it to run. (As a general rule, it’s best not to rename directories outside of your home directory — they are managed by the package manager, and you are likely to confuse it and prevent updates ...


34

In addition to muru's answer: you could have used some rescue boot USB key to repair your system; e.g. if your system is some Debian or Ubuntu, boot the installation USB key in rescue mode, and do the appropriate mount and mv and umount. to be able to repair more easily such mistakes, I generally also install a static shell with several builtin commands (...


33

I know this doesn't answer your question, but in case you were looking for another way to rename the files compared to your work-around loop, why not use find? I have used this command many times to replace file extensions in large directories with hundreds of thousands of files in it. This should work on any POSIX-compliant system: find . -name "*....


30

Use this with bash: find $1 -name "* *.xml" -type f -print0 | \ while read -d $'\0' f; do mv -v "$f" "${f// /_}"; done find will search for files with a space in the name. The filenames will be printed with a nullbyte (-print0) as delimiter to also cope with special filenames. Then the read builtin reads the filenames delimited by the nullbyte and ...


28

find the list of files and then replace keyword. below is example find . -name '*jpg' -exec bash -c ' mv $0 ${0/\#U00a9NBC/safeNBC}' {} \;


28

The fatal error message indicates you’re working from somewhere that’s not a clone of your git repository. So let’s start by cloning the git repository first: git clone https://github.com/benqzq/ulcwe.git Then enter it: cd ulcwe and rename the directory: git mv local xyz For the change to be shareable, you need to commit it: git commit -m "Rename ...


25

.. is not special, it is just that it already exists. On Unix, Dos and MS-Windows every directory has a directory . it links back to itself, and a directory .. it links to its parent directory (or self if root directory). If .. and . are special it is only because you can not remove them (actually you can, you just remove the directory that contains them)....


25

You could do something like below as well. find path_A -name "*AAA*" -print0 | xargs -0 -I {} mv {} path_B Where, -0 If there are blank spaces or characters (including newlines) many commands will not work. This option take cares of file names with blank space. -I Replace occurrences of replace-str in the initial-arguments with names read from standard ...


Only top voted, non community-wiki answers of a minimum length are eligible