Moving directories
Solution 1
cp
copies files. If you specify a directory (I've never tested this) it would probably copy the contents of this directory, and place them all (including the original folder) into the destination directory. Yes, it will create two copies of the target file(s) and yes, it will probably disturb a number of things like that.
You can drag and drop files easily in Nautilus to move them naturally, without the negative effects on hard drive optimization. The mv
command in terminal will do the same thing. It's similar in usability to the cp command:
mv </oldlocation/target> </newlocation/destination/>
Where the target is a file, or a directory, and the destination is a directory.
NOTE: If you use mv </location/filenameA> <location/filenameB>
it will rename the file.
For example,
mv /etc/x11/xorg.conf /etc/x11/xorg.conf.backup
will rename the xorg.conf
text file to xorg.conf.backup
. Try doing a google search of useful linux command line tools.
Another neat trick in command line is using the 'man' option. For example
mv man
or
sudo man
The 'man' stands for manual. Every terminal application has a manual detailing the nature of the application, all of it's options, and definitions for everything. You can run the man option with any terminal command you install.
Solution 2
The move command in linux is mv
, see mv --help
for more info
this moves the directory and all sub dirs
mv -f dir1 /destinationDir
This move files from dir1 to dir2
mv -f dir1/* dir2
Related videos on Youtube
Comments
-
RyanGC over 1 year
If I use the
cp
command to copy a directory A to the inside of directory B, will it double the amount of space that it takes up (directory A + copied version of directory A)? I can't imagine that would be the case, but would it disturb the look up time on disk for the files in that directory?I am a beginner so I'm sorry if this question doesn't really make sense.
-
RyanGC almost 11 yearsRight, but I want to have the exact same directory in another directory.
-
RyanGC almost 11 yearsRight, I understand that, I guess the way I should have framed the question is that if I copy a directory, is that just going to create another pointer to where those files are stored (I am assuming sequentially on disk) or will actually burn another directory A sized space on disk, or screw with the way it does the look up in a bad way. Like I said, I'm very noob, and maybe this is too complicated a question for me to understand the answer without doing alot more research.
-
Alex almost 11 yearsLook up some videos or articles on google/youtube about how the linux filesystem works. It's VERY different than in Windows, it's actually fascinating. Linux writes files the HDD physically at the very beginning of every HDD stripe, and continues with the next encoding if there is any space left, and adds the remainder onto the next stripe, and so on. It's much faster at file access than Windows because of this. It also maps files digitally rather than physically. Files aren't moved stripes like in Windows. You never have to defrag in Linux.
-
thomasrutter over 5 yearsIf you use
cp
to copy a directory, it will emit a notice telling you it is ignoring the directory, and do nothing. You need to use-r
(or better,-a
to preserve some other attributes), to copy a directory, as it turns on recursion (entering a directory to copy its contents). -
thomasrutter over 5 yearsIt may be worth mentioning that without
-r
or-a
,cp
will only copy files (that is,source
must be a file), and will ignore directories. -
WinEunuuchs2Unix over 5 years
cp -a
also preserves owner and group ID's I think.