How to Move, Rename, Copy, and Delete Files and Folders via SSH

How to Move, Rename, Copy, and Delete Files and Folders via SSH

  • March 24, 2023
  • in Web Tech
  • by AW Bali Digital
  •  | 124 views

If you’re working on a remote server via SSH, you might need to move, rename, copy, or delete files and folders. These are common operations that you may perform on a regular basis, and it’s important to know how to do them efficiently via SSH. In this post, we’ll explore the commands that allow you to do these tasks easily.

Moving Files and Folders

To move a file or folder via SSH, you’ll use the mv command. The syntax for this command is as follows:

mv [source] [destination]

For example, let’s say you want to move a file named example.txt from your current directory to a directory called docs. Here’s how you would do it:

mv example.txt docs/

If you want to move a folder and all its contents, you’ll need to use the -r flag, which stands for “recursive”. Here’s an example:

mv -r myfolder/ docs/

Renaming Files and Folders

To rename a file or folder via SSH, you’ll use the mv command again, but this time you’ll specify a new name for the file or folder. Here’s the syntax:

mv [old-name] [new-name]

For example, if you want to rename a file named oldname.txt to newname.txt, you would use the following command:

mv oldname.txt newname.txt

Copying Files and Folders

To copy a file or folder via SSH, you’ll use the cp command. The syntax for this command is as follows:

cp [source] [destination]

For example, let’s say you want to copy a file named example.txt from your current directory to a directory called backup. Here’s how you would do it:

cp example.txt backup/

If you want to copy a folder and all its contents, you’ll need to use the -r flag again. Here’s an example:

cp -r myfolder/ backup/

Deleting Files and Folders

To delete a file or folder via SSH, you’ll use the rm command. Be careful when using this command, as it will permanently delete the file or folder without confirmation. Here’s the syntax:

rm [file]

or

rm -r [directory]

For example, if you want to delete a file named example.txt, you would use the following command:

rm example.txt

If you want to delete a folder and all its contents, you’ll need to use the -r flag again. Here’s an example:

rm -r myfolder/

Conclusion

Moving, renaming, copying, and deleting files and folders via SSH is a powerful way to manage your files on a remote server. With these commands, you can quickly and easily perform these common operations without ever leaving your command line interface. Remember to be careful when using the rm command, as it can permanently delete files and folders without confirmation. With a little practice, you’ll soon become proficient at managing your files via SSH.

AW Bali Digital

© 2023 awbalidigital.com by PT BIKIN INOVASI TEKNOLOGI, All Rights Reserved.