Jack Wallen continues his Linux 101 collection, with an introduction on methods to copy information and directories from the command line.
Are you new to Linux? If that’s the case, you’ve got in all probability discovered the command line generally is a bit intimidating. Don’t be concerned–it is for everybody at first. That is why I am right here to information you thru the method, and at this time I will present you methods to copy information and folders from the command line.
Why would you might want to copy information and folders this fashion? You may end up on a GUI-less Linux server and must make a backup of a configuration file or copy an information listing.
Belief me, in some unspecified time in the future you are going to want to have the ability to do that. Let’s learn the way.
SEE: Linux: The 7 greatest distributions for brand new customers (free PDF) (TechRepublic)
First we’ll copy a file. For instance you are about to make modifications to the Samba configuration file, smb.conf and also you need a backup copy simply in case one thing goes flawed. To repeat that file, use the cp command to repeat the supply to the vacation spot like so:
cp /and so forth/samba/smb.conf /and so forth/samba/smb.conf.bak
You’ve got in all probability already encountered your first downside. As a result of the smb.conf file is in /and so forth/, you will want to make use of sudo privileges to make the copy. So the right command is:
sudo cp /and so forth/samba/smb.conf /and so forth/samba/smb.conf.bak
On this instance, smb.conf is our supply and smb.conf.bak is our vacation spot. You may need to protect the file attributes (reminiscent of listing and file mode, possession, and timestamps) throughout the copy. For that we use the -a choice as in:
sudo cp -a /and so forth/samba/smb.conf /and so forth/samba/smb.conf.bak
Copying a listing is finished in the identical method, solely you utilize the -R choice, for recursive. For instance you need to make a backup of your complete /and so forth/samba listing and also you need to copy it to your private home listing. That command could be:
sudo cp -R /and so forth/samba ~/samba.bak
To protect the attributes, whereas copying the listing, the command could be:
sudo cp -aR /and so forth/samba ~/samba.bak
And that is all there’s to it. You’ve got simply copied your first information and directories from the Linux command line. Now, exit and have a good time this victory, you’ve got earned it.
Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the most recent tech recommendation for enterprise execs from Jack Wallen.