Tag Info

New answers tagged

2

Like many editors, Sublime saves to a temporary file, then moves that temporary file into place. It's done this way in case the system crashes during the save: it's guaranteed that either the original file or the new version will be present, you don't risk losing the file. SSHFS is built on top of SFTP, which (at least as implemented by OpenSSH) does not ...


7

s=/home/poney/; f=folderfulloffiles; d=/home/unicorn/ sudo mv $s$f $d && sudo chown -R unicorn:unicorn $d$f About the same length as the other answers, and note since they're all using the same library calls under the hood, they're all doing exactly the same thing -- unless, as Gilles notes, this is on the same filesystem and device, in which case ...


9

Per @Kevin in the comments below, the --file - |pipe syntax is redundant. So I've removed it. This can also be done with tar: sudo tar -C${SRC_DIR} --remove-files --group=unicorn --owner=unicorn -c ./* | sudo tar -C${TGT_DIR} -pvx


20

Use rsync(1): rsync \ --remove-source-files \ --chown=unicorn:unicorn \ /home/poney/folderfulloffiles /home/unicorn/


0

Instead mv foo* ~/bar/ you can do cp foo* ~/bar/ rm foo* Simple, readable, vote me :)


1

I'll propose a different workflow (suggested by hasenj): instead of using fdupes to identify duplicate files and perform some post-processing to remove them, you can use Unison to identify and deal with duplicates. You need to run Unison with one of the roots remote, otherwise it doesn't detect identical files. So run unison /home/articles/bibtex.pdf ...


1

In my experience fdupes can be inconsistent in the order that it outputs files (I have had my own problems using the --delete option). This should be fairly robust as it doesn't require the files to be in a specific order (as as long as there are always two dupes in different folders): # note no trailing slash source_dir=/home/articles ...


0

You can use rename for such tasks: ➜ lab ls 1dsfa.file 6033dsfa.file 90843_O\\'ConnorPaul_GeneralManager.jpg 56dsfa.file 90843_O\'ConnorPaul_GeneralManager.jpg ➜ lab rename "s/\'//g" * ➜ lab ls 1dsfa.file 6033dsfa.file ...


-1

Grrr, @Graeme beat me to it, but I'll post anyway ... If you quote the filename with double quotes, like mv -v "90843_O'ConnorPaul_GeneralManager.jpg" 90843_O_ConnorPaul_GeneralManager.jpg, it does the trick; using -v is optional but it'll tell what it did. I believe there's a second way too apart from escaping all the chars, -if- that even is possible. The ...


2

Bash tab completion should be able to do the right thing here if you just type mv 90843_O and press tab. Otherwise, one way to properly escape the name is: mv "90843_O\\\\'ConnorPaul_GeneralManager.jpg" dest.jpg The double quotes remove the need to escape the ', but the two backslash characters still need to be escaped (one extra backslash for each makes ...


0

If you happen to have zsh shell available, then zmv does almost exactly what you want, with very similar syntax: zmv '*.download' '$1.html' Just to point out why your attempt was wrong and dangerous: the wildcards *? are expanded by your shell before the command is even called. So, mv actually receives the entire list of files instead of *.download, but ...


1

mv doesn't work this way. You need another tool like rename or mmv. Please mind that there are two versions of rename around. And, of course, the shell can do that (with mv): for file in *.download; do fbasename="${file%.download}" if [ -e "${fbasename}.html" ]; then echo "${fbasename}.html exists; skipping." echo "${fbasename}.html exists; ...


0

rename 's/download$/html/' *.download should work for you


4

You can only use mv to move multiple files to a single directory in on call. One option here is to use prename (rename is linked to this on most systems, but not all): prename -n 's/download$/html/' -- *.download Remove -n when you are sure this is doing what you want. Another way is simply to use a loop: for file in *.download; do mv -i -- "$file" ...


2

Using prename (rename is a symlink to this by default on many systems): prename -n 's:\..*\.:.:' *.hdf The -n will print the actions that will be taken without doing anything. Once you are sure you have what you want, remove it.


1

Run the below script from the folder where you have all these files. for f in *.hdf; do mv -- "$f" "${f%%.*}".hdf ; done The above script checks for all files with hdf extension inside the current directory and for each file, it removes the characters after the . character and adds the extension as .hdf


3

You could use \ before the character ? so it is consider as a normal character in the name of the file and not a special character to be interpreted. The command would then be: mv Giko\ Suzo\ San\?e\ -\ Ep1.avi 'Giko Suzo Sane - Ep1.avi' EDIT: following discussion in comments, this line did the trick: mv Giko\ Suzo\ Sa*\ -\ Ep1.avi 'Giko Suzo Sane - ...


4

Auto-complete often fixes problems like this: mv Giko<tab> "Giko Suzo San’e - Ep1.avi"


0

You can use the shell parameter expansion constructs ${VAR#PREFIX} and ${VAR%SUFFIX} to obtain the value of a variable with the specified prefix or suffix stripped off. If PREFIX is a pattern, the shortest matching string is stripped; with ## or %%, the longest match is stripped instead. These constructs are available in every sh-type (Bourne/POSIX) shell, ...


1

You need to tell the shell that you mean for the braces and spaces to be part of the file name, instead of being interpreted as shell syntax. You can type file names containing special characters inside single quotes. This works for every character except the single quote itself. This is the easiest method in a script. mv '{{ THEME SANITIZED }}.hacks.css' ...


1

Run the below commands inside /psds directory. for f in ./*; do if [ -d "$f" ] ; then cd "$f" mv *.jpg "$f.jpg" cd .. fi done If you have 3 folders inside /psds directory like below, /psds/folder1/image1.jpg /psds/folder2/image2.jpg /psds/folder3/image3.jpg After you run the above command, the files would be renamed as, ...


1

you can use double quotes to scape or scape with slash like for example: using double quotes: mv "{{ THEME SANITIZED }}.hacks.css" myomega.hacks.css using slash: mv \{\{\ THEME\ SANITIZED\ \}\}.hacks.css myomega.hacks.css something cool that some people doesn't know how to remove ou rename a directory when it's start with dash you can you dash dash :D ...


3

mv "{{ THEME SANITIZED }}.hacks.css" myomega.hacks.css will work.


0

If you find you do this sort of thing a lot, look up "rename.pl". It's a perl script, but allows you to simply feed it perl code (like a s/// expression), and it will do a mass rename based on that expression or code. There's a basic version here: http://stackoverflow.org/wiki/Rename.pl but there are other versions floating around the net. It's been ...


2

You were right to consider rename first. The syntax is a little strange if you're not used to regexes but it's by far the quickest/shortest route once you know what you're doing: rename 's/\d{4}/2503/' file* That simply matches the first 4 numbers and swaps them for the ones you specified. And a test harness (-vn means be verbose but don't do anything) ...


0

ptrn='file[0-9][0-9][0-9][0-9]2014[0-9][0-9][0-9][0-9][0-9].p' path=/dir ( set -- "${path}/"${ptrn} ; for f ; do { echo "mv ${path}/${f} \ ${path}/file25032014${f#2014}" } ; done ) This should do the trick. Note - I'm not in the habit of handing over mass mv commands - as written it's just an echo. You'll have to sort that out before it'll ...


8

This should do the trick: for f in file*; do mv $f ${f/${f:4:8}/25032014}; done It replaces the string beween the 4th and the 12th character with "25032014".


5

Assuming that we're talking of regular files here, in the case of: cp to_do done If done is not writeable, you'll get an error message. Otherwise, the content of to_do will be copied over done. What that means is that done keeps the same inode, permissions, ownership, birth time. The -p (or -a in some implementations) would try and copy some of the ...


6

done will be replaced by the content of to_do You can check with a simple test: $ echo a > done $ echo b > to_do $ cp to_do done $ cat done b and $ echo a > done $ echo b > to_do $ mv to_do done $ cat done b Edit Following the comments some additional info done will not be replaced if either done or to_do are directories. If done is a ...



Top 50 recent answers are included