Home > Articles > Operating Systems, Server > Linux/UNIX/Open Source

  • Print
  • + Share This
This chapter is from the book

Manipulating Files and Folders

You can manipulate files and folders with the following commands.

  • cp: The cp command makes a copy of a file for you. For example, cp file foo makes an exact copy of the file whose name you entered and names the copy foo, but the first file will still exist with its original name.
  • mv: The mv command moves a file to a different location or renames a file. Examples are as follows: mv file foo renames the original file to foo. mv foo ~/Desktop moves the file foo to your desktop directory but does not rename it. You must specify a new filename to rename a file. After you use mv, the original file no longer exists, but after you use cp, as above, that file stays and a new copy is made.
  • To save on typing, you can substitute ~ in place of the home directory, so /home/jono/pictures is the same as ~/pictures.
  • rm: Use this command to remove or delete a file in your directory, as in rm file.txt. It does not work on directories that contain files, which must first be emptied and may then be deleted using the rmdir command. There are some advanced cases where you may use rm to remove directories, but discussing those are beyond the intent of this appendix.
  • ls: The ls command shows you the files in your current directory. Used with certain options, it lets you see file sizes, when files where created, and file permissions. For example, ls ~ shows you the files that are in your home directory.
  • mkdir: The mkdir command allows you to create directories. For example, mkdir music creates a music directory.
  • chmod: The chmod command changes the permissions on the files listed. Permissions are based on a fairly simple model. You can set permissions for user, group, and world, and you can set whether each can read, write, and/or execute the file. For example, if a file had permission to allow everybody to read but only the user could write, the permissions would read rwxr—r—. To add or remove a permission, you append a + or a - in front of the specific permission. For example, to add the capability for the group to edit in the previous example, you could type chmod g+w file.
  • chown: The chown command allows the user to change the user and group ownerships of a file. For example, sudo chown jim file changes the ownership of the file to Jim.
  • + Share This
  • 🔖 Save To Your Account