Basic file manipulation and the rm command
Moving on from the first lesson on commands there is a whole host of them dedicated to manipulating files. It is possible to navigate your computer and interact with any files stored on it without ever leaving our terminal window.
- creating/editing
-
- mkdir <foldername> Create a new folder
- touch <filename> Create or update a file
-
- moving/renaming
-
- mv file.txt documents/ Move a file to a folder
- mv <folderName> <foldername2> Move a folder into a folder
- mv filename.txt filename2.txt Rename a file
- mv <foldername>/.. Move a folder up in the hierarchy
-
- copying
-
- cp image.jpg newimage.jpg Copy and rename a file
- cp image.jpg <foldername>/ Copy to a folder
- cp -R folder1/ folder2/ Recursively (-R) copies folder1 and all of its contents into folder2.
-
The command to remove files deserves a section all on its own. Removing files through this command does not just remove them or put them in your trash it nukes them. They will be irretrievable you cannot get them back! The command will generally run without asking for you to double-check and many developers have run into problems of accidentally deleting parts of projects.
- rm <filename> removes files only
- rmdir <foldername> removes folders
- use -r (recursive option) to delete all files and subfolders
For files, there is a safety net! And we would implore you to use them and set them as an alias. Using the interactive flag -i so that you will need to confirm the files you are about to delete. -i acts as a pause button until a decision is made.
Never use rm/rmdir -r * !!
Finally, these shortcuts will help you navigate your command line while typing.