You copied 45,000 of these from your file and pasted them into the bash prompt:
mv ./photos/30401?to?30500/60ccba-9919.jpg photos
mv ./photos/30401?to?30500/60ccba-9920.jpg photos
Each one of those is a move command, so that’s 45,000 commands in all. I was just saying that if you ever have to do that again, you can have bash run the commands in the file by typing “dot filename” instead of copying and pasting to the terminal. Pasting to the terminal makes the output all funky as each line will be shown, then the output from that command.
e.g. pasting these two lines:
echo hello
echo world
looks like this in the terminal:
echo hello
hello
echo world
world
The move command won’t show any output, but it will still show each time it’s pasted, so if any lines gave errors, you’d never see them. They’ll be scrolled off the screen by the rest of the pasted commands. On the other hand, doing the “dot filename” trick will give you no output unless there are errors.
I guess the odds you’ll need to do it again are pretty slim anyway.
Well, I managed to screw up all the permissions on my server… never tell a person who is essentially clueless how to become the root user and change things…
One of the commands up-thread that didn’t work for you involving “mv -t.” wouldn’t have worked because of a typo (that appears corrected later in the thread). It should have been “mv -t .”, where “-t” is the argument that requires a directory name to follow and “.” is that directory name. ("." is an alias that always means “current directory” and “…” means “parent directory”.
For the record, I would have done this like this:
find | grep "jpg" | xargs mv -t .
I generally use the more powerful “find” arguments only when I need them. “find” on its own just dumps to stdout (“standard out”) everything in and beyond the current path. The “grep” command passes only those lines of output that contain the string “jpg”, and the “xargs” command says to pass the output of that to the “mv” command with the destination directory of “.”.
If the number of files is small, a more conventional “mv” command would work on its own:
mv */*.jpg .
If the file list is too long, though, you will see “argument list too long”. That’s exactly what the xargs/mv/-t combo is made for, as the file names become part of the stream (input/output lines) rather than being explicit arguments on the command line.
(In the “argument list too long” case, basically what the shell does when it sees “/.jpg” is it goes through the directories looking for matching filenames, and it then constructs the command you could have typed if you typed all the names out by hand. If the resulting full command is longer than a command line can be (limited by the memory devoted to the so-called shell “environment”), it will complain.)
If you haven’t yet, I recommend embracing the “man” command. “man find”, “man mv”, etc., is a good way to learn how to use different commands. “Man pages” (as they’re called) are terse but (IMHO) in a good way. They say completely and precisely what things do, which leaves little uncertainty at the expense of perhaps a little dense-ness if there are lots of options to wade through.
Also, everywhere in the above where I said “-t foo” I actually use “–target-directory=foo”, which is I think always available. ("-t" isn’t available in all versions of “mv”, but I seem to recall that it is sometimes, as suggested by the above posters’ suggestions to use it.)
Well yeah, but it assumes you have a core understanding that I don’t have…i guess the assumption is that anyone who is messing with this stuff is more of a computer geek than I am. As in:
It’s a good thing I already knew that chmod is for file permissions, because I would never know it from the man page!
And as it is, I find it very intimidating to try and understand. I’m sure it would help enormously if I could get some basic things under my belt, such as an understanding of what
means, in terms of the syntax. How does the above translate to a REAL command? Why the double brackets? When does that apply?
I can get little tiny bits explained in isolation from other things, but then none of it comes together.
There must be some tutorial on how to understand the tutorials! Because certain things are, obviously, consistent: brackets, the minus sign, the fact that some things are capital, others lower case, the symbols… and I need to understand, because it hangs me up ALL the time, how certain symbols can be used - I know that asterisk meas “all” but when/how? In combination with what?
Since it’s very clear to you, maybe its hard for you to understand what I don’t understand, but I’m very English-oriented, so I kinda need to find a way to quite literally and quite EXACTLY translate computer syntax to English syntax. Once I’m able to do that, when I understand what each part does and the way they need to be strung together, I’m in pretty good shape. I’m good at logic puzzles and simpllified scripting - I just need to know how each “word” or symbol behaves.
Like I know that typing “ls -al” will give me a list of files in the directory I’m in and include ownership, permissions, etc… but why? What is that command actually SAYING?
ls = list? and does that always and only mean “list THIS DIRECTORY”? Or can ls be combined with other things - can you say “ls sometoherdirectoryIwilltellyouabout” perhaps by “ls /other/directory/someplace/else”?
I think it’s wonderful you found a simple way to do this by yourself. Yours is the way I do it, though use of wildcard (’*’) may simplify things. The one problem that may arise is different files in different subdirectories that share a name and you don’t want to overwrite (and destroy) the other. (In my case, this worries me so much I have a defined alias ‘dupsindir’ just to check for such duplicates.)
I didn’t check the solutions posted using ‘find’, ‘|’ etc. Overkill.
My machine lacks a Linux driver for my digital camera so I transfer them with the Windows driver, end up with ridiculously long names and paths, reboot into Linux just to do ‘mv’ similar to yours.
chmod has modifiers: -f , -h and -v can be combined and apply in all circumstances. -R is also a modifier (descend subdirectories), and has it’s own three modifiers (-H, -L, -P), only one of which can apply (thus the bar seperator | meaning OR). -E, -C, -N are additional modifiers.
To be fair, I don’t know what system you are working on, my Centos system has a much clearer man page for chmod, and my chmod allows option combining, so all the primary options can be combined (chmod -fR …) works.
Any place a command expects a file/directory name, you can use a file expansion modifier like ***** or ? (any single character). Unix Wildcards
list a directory (if no directory specified, use the current directory, an implied .) with the -l (long listing) and -a (include hidden files starting with a .)
If you want to know what certain options to a command do, try typing “command --help” in a terminal. For example, here is the output of “ls --help” for the particular version of ls that I have on my phone:
*# ls --help
BusyBox v1.16.1androidBTEP (2010-05-05 21:05:13 PDT) multi-call binary.
Usage: ls [-1AacCdeFilnpLRrSsTtuvwxXhk] [FILE]…
List directory contents
Options:
-1 List in a single column
-A Don’t list . and …
-a Don’t hide entries starting with .
-C List by columns
-c With -l: sort by ctime
–color[={always,never,auto}] Control coloring
-d List directory entries instead of contents
-e List full date and time
-F Append indicator (one of */=@|) to entries
-i List inode numbers
-l Long listing format
-n List numeric UIDs and GIDs instead of names
-p Append indicator (one of /=@|) to entries
-L List entries pointed to by symlinks
-R Recurse
-r Sort in reverse order
-S Sort by file size
-s List the size of each file, in blocks
-T N Assume tabstop every N columns
-t With -l: sort by modification time
-u With -l: sort by access time
-v Sort by version
-w N Assume the terminal is N columns wide
-x List by lines
-X Sort by extension
-h List sizes in human readable format (1K 243M 2G)
I was just showing another option. --help is usually a concise list of the different options while man pages can get into some pretty deep territory, even history at times. The man page for rsync is 3342 lines long, for example and no newbie is going to look at that to find out how to do a dry run or something.
That option is probably a GNU extension. Neither form of it exists in the MacOS X or Solaris versions of the “mv” command. Also, it’s not mentioned in the POSIX documentation for “mv”.