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.
3 Answers
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.backupwill 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 manor
sudo manThe '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.
3The move command in linux is mv, see mv --help for more info
this moves the directory and all sub dirs
mv -f dir1 /destinationDirThis move files from dir1 to dir2
mv -f dir1/* dir2 1 Adding an answer because this was my first search result in Google and there wasn't many thorough answers on the mv command, and what linking means at any level of detail.
cp - copies. It will make an identical copy by default, taking up identical space, although you can tell cp to make hard links (pointers to each file) using the -l option.
If you want to create a copy of a folder, do this:
cp -a source destWhere -a means an "archive" or identical copy, including folders and links. You could exchange it for -r if you want to copy folders but not links.
If you want to create a copy with links to the original files (changing the original changes the copy as well, and takes up much less space), do this:
cp -l source destln - links. It will make only a link, you can have it point to your destination, and it will only take up the space it takes to point to it.
If you want to create a single link to a folder, just do this:
ln -s source destNOTE: -s means "symbolic" link. Because ln can create hard or soft (most people call this "symbolic") links. Hard links can only point to files and have other restrictions, while symbolic links can point to anything, including folders. For a complete article on differences between hard and soft links see this great article here.
mv - moves files or folders.
To move folders (or files) just do this:
mv source dest 2