Jack Wallen continues his Linux 101 sequence, with an introduction on the way to copy information and directories from the command line.
Are you new to Linux? If that’s the case, you have most likely discovered the command line to be a little bit intimidating. Don’t be concerned, it is for everybody in the beginning. That is why I am right here to stroll you thru the method, and in the present day I will present you the way to copy information and folders from the command line.
Why would you must copy information and folders this manner? You would possibly find yourself on a Linux server with no GUI and have to again up a configuration file or copy an information listing.
Consider me, in some unspecified time in the future you will want to have the ability to do that. Let’s examine how.
SEE: Linux: The 7 Finest Distributions for New Customers (Free PDF) (TechRepublic)
We’ll first copy a file. As an example you are about to make modifications to Samba’s configuration file, smb.conf, and also you need a backup copy simply in case one thing goes flawed. To repeat this file, use the cp command to repeat supply to vacation spot like this:
cp /and many others/samba/smb.conf /and many others/samba/smb.conf.bak
You have most likely already encountered your first downside. Because the smb.conf file is positioned in / and many others /, you will want to make use of sudo privileges to carry out the copy. The proper command is subsequently:
sudo cp /and many others/samba/smb.conf /and many others/samba/smb.conf.bak
On this instance, smb.conf is our supply and smb.conf.bak is our vacation spot. It’s possible you’ll wish to retain file attributes (similar to listing and file mode, possession, and timestamps) whereas copying. For this we use the -a choice as in:
sudo cp -a /and many others/samba/smb.conf /and many others/samba/smb.conf.bak
Copying a listing is finished the identical approach, solely you utilize the -R choice, for recursive. As an example you wish to make a backup of the entire / and many others / samba listing and also you wish to copy it to your house listing. This command could be:
sudo cp -R /and many others/samba ~/samba.bak
To maintain the attributes, when copying the listing, the command could be:
sudo cp -aR /and many others/samba ~/samba.bak
And that is all there may be to it. You’ve simply copied your first information and directories from the Linux command line. Now go on the market and have a good time this victory, you’ve gotten earned it.
Subscribe to TechRepublic How one can Make Expertise Work on YouTube for all the most recent technical recommendation for professionals from Jack Wallen.