![]() ![]() Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the latest tech advice for business pros from Jack Wallen. Now, go out and celebrate this victory, you’ve earned it. You’ve just copied your first files and directories from the Linux command line. This command can also copy directories (folders). To preserve the attributes, while copying the directory, the command would be: sudo cp -aR /etc/samba ~/samba.bakĪnd that’s all there is to it. You use the cp command for copying files from one location to another. ![]() That command would be: sudo cp -R /etc/samba ~/samba.bak Let’s say you want to make a backup of the entire /etc/samba directory and you want to copy it to your home directory. For that we use the -a option as in: sudo cp -a /etc/samba/smb.conf /etc/samba/Ĭopying a directory is done in the same way, only you use the -R option, for recursive. You might want to preserve the file attributes (such as directory and file mode, ownership, and timestamps) during the copy. In this example, smb.conf is our source and is our destination. So the correct command is: sudo cp /etc/samba/smb.conf /etc/samba/ This command also allows you to move multiple files and folders at. Because the smb.conf file is in /etc/, you’ll need to use sudo privileges to make the copy. The cp command in Linux is used to copy files and directories by using the command line. ![]() Using the -v option to view what the cp command is doing in the background. In the example below, we’ll show you how to use the syntax in your Linux terminal to get this output. You’ve probably already encountered your first problem. Using the -v option, we can get the cp command to tell us what it is doing in the background so we can see it in action. To copy that file, use the cp command to copy the source to the destination like so: cp /etc/samba/smb.conf /etc/samba/ Let’s say you’re about to make changes to the Samba configuration file, smb.conf and you want a backup copy just in case something goes wrong. SEE: Linux: The 7 best distributions for new users (free PDF) (TechRepublic)įirst we’ll copy a file. Trust me, at some point you’re going to need to be able to do this. It is common practice to use the cp command to copy files and rsync to copy directories. Why would you need to copy files and folders this way? You might find yourself on a GUI-less Linux server and need to make a backup of a configuration file or copy a data directory. How to Copy Files in Linux using CP Command. That’s why I’m here to guide you through the process, and today I’m going to show you how to copy files and folders from the command line. The above mentioned error also hints that you missed the -r option. Don’t worry–it is for everyone at the beginning. Copy directory in Linux command line You can definitely use the same cp command but with the recursive option -r to copy a folder with its content to another folder. 6 Best Linux project management software in 2023Ħ best open-source kanban boards for managing projects in 2023Ħ Best Free Alternatives to Microsoft Word (2023 Update)Īre you new to Linux? If so, you’ve probably found the command line can be a bit intimidating. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |