Continuing the first part, in this second part we will learn about copying and deleting for both file and folder within both your user area and system area. You will learn here how to do copy-paste, cut-paste, create new folder, deleting file and folder, all basic manipulation operations you do with file manager, in Terminal. You will practice how to use cp, mv, rm, and mkdir. Of course, you will learn how to create new file and folder with commands. Also, you will learn how to use sudo to copy to and delete in system area. Happy learning!
Subscribe to UbuntuBuzz Telegram Channel to get article updates directly.
Read also First Part: Navigation of this tutorial series.
The Command Lines Used
Manipulation operations are basically using four commands:
- cp
- mv
- rm
- mkdir
Command 1
$ cd ~
$ pwd
$ ls
$ echo "i am text" > file.txt
$ ls
Command 2
$ ls -d */
$ ls | grep txt
$ cp file.txt Desktop/
$ cp file.txt Documents/
$ cp file.txt Downloads/
$ cp file.txt Pictures/
$ cp file.txt Music/
$ cp file.txt Videos/
$ cp file.txt Public/
$ cp file.txt Templates/
Command 3
$ pwd
$ ls Desktop/
$ ls Documents/
$ ls Downloads/
$ ls Pictures/
$ ls Music/
$ ls Videos/
$ ls Public/
$ ls Templates/
$ ls -R ~
Command 4
$ pwd
$ rm -v Desktop/file.txt
$ rm -v Documents/file.txt
$ rm -v Downloads/file.txt
$ rm -v Pictures/file.txt
$ rm -v Music/file.txt
$ rm -v Videos/file.txt
$ rm -v Public/file.txt
$ rm -v Templates/file.txt
$ ls -R ~
Command 5
$ cd ~
$ pwd
$ ls -d */
$ mkdir myfolder/
$ ls -d */
$ cp -r myfolder/ Desktop/
$ cp -r myfolder/ Documents/
$ cp -r myfolder/ Downloads/
$ cp -r myfolder/ Pictures/
$ cp -r myfolder/ Music/
$ cp -r myfolder/ Videos/
$ cp -r myfolder/ Public/
$ cp -r myfolder/ templates/
$ ls Desktop/
$ ls Documents/
$ ls Downloads/
$ ls Pictures/
$ ls Music/
$ ls Videos/
$ ls Public/
$ ls Templates/
Command 6
Warning: this is deletion so be careful not to type anything incorrect!
$ cd ~
$ pwd
$ ls -d */
$ rm -v -r Desktop/myfolder/
$ rm -v -r Documents/myfolder/
$ rm -v -r Pictures/myfolder/
$ rm -v -r Music/myfolder/
$ rm -v -r Videos/myfolder/
$ rm -v -r Public/myfolder/
$ rm -v -r Templates/myfolder/
$ ls Desktop/
$ ls Documents/
$ ls Downloads/
$ ls Pictures/
$ ls Music/
$ ls Videos/
$ ls Public/
$ ls Templates/
Command 7
Warning: be careful with the deletion!
Keep looking at file manager in the target folder so you see the deletion working.
$ cd ~
$ pwd
$ echo "this is second file" > file2.txt
$ mkdir myfolder2/
$ sudo cp -v -r myfolder2/ /usr/share/fonts/
$ sudo cp -v file2.txt /usr/share/fonts/myfolder2/
$ ls -R /usr/share/fonts/myfolder2/
$ sudo rm -v /usr/share/fonts/myfolder2/file2.txt
$ sudo rm -v -r /usr/share/fonts/myfolder2/
$ ls -R /usr/share/fonts/
Command 8
$ cd ~
$ pwd
$ echo "this is third file" > file3.txt
$ echo "this is fourth file" > file4.txt
$ echo "this is fifth file" > file5.txt
$ echo "this is sixth file" > file6.txt
$ mv -v file3.txt Desktop/
$ mv -v file4.txt Documents/
$ mv -v file5.txt Downloads/
$ mv -v file6.txt Pictures/
$ ls Desktop/
$ ls Documents/
$ ls Downloads/
$ ls Pictures/
Command 9
$ cd ~
$ pwd
$ mkdir myfolder3/
$ mkdir myfolder4/
$ mkdir myfolder5/
$ mkdir myfolder6/
$ mv -v -r myfolder3/ Desktop/
$ mv -v -r myfolder4/ Documents/
$ mv -v -r myfolder5/ Downloads/
$ mv -v -r myfolder6/ Pictures/
Command 10
Warning: again, be careful with the deletion!
$ cd ~
$ pwd
$ sudo mv -v Desktop/file3.txt /usr/share/fonts/myfolder/
$ sudo mv -v Documents/file4.txt /usr/share/fonts/myfolder/
$ sudo mv -v Downloads/file5.txt /usr/share/fonts/myfolder/
$ sudo mv -v Pictures/file6.txt /usr/share/fonts/myfolder/
$ ls /usr/share/fonts/myfolder/
$ sudo mv -v -r Desktop/myfolder3/ /usr/share/fonts/myfolder/
$ sudo mv -v -r Documents/myfolder4/ /usr/share/fonts/myfolder/
$ sudo mv -v -r Downloads/myfolder5/ /usr/share/fonts/myfolder/
$ sudo mv -v -r Pictures/myfolder6/ /usr/share/fonts/myfolder/
$ ls /usr/share/fonts/myfolder/*/
$ sudo rm -v /usr/share/fonts/myfolder/file3.txt
$ sudo rm -v /usr/share/fonts/myfolder/file4.txt
$ sudo rm -v /usr/share/fonts/myfolder/file5.txt
$ sudo rm -v /usr/share/fonts/myfolder/file6.txt
$ sudo rm -v -r /usr/share/fonts/myfolder/myfolder3/
$ sudo rm -v -r /usr/share/fonts/myfolder/myfolder4/
$ sudo rm -v -r /usr/share/fonts/myfolder/myfolder5/
$ sudo rm -v -r /usr/share/fonts/myfolder/myfolder6/
$ ls /usr/share/fonts/myfolder/
Summary
- cp is copy, same as copy-paste in file manager
- mv is move, same as cut-paste in file manager
- rm is remove, same as delete in file manager
- mkdir is make directory, same as create new folder in file manager
Detailed Summary
What you get from practices above are:
- again, a command is usually followed by address or file name
- the option -v is for verbose, to make a command says what it is doing
- the option -r is for recursive, to make cp and rm commands able to manipulate folder
- to create a new file, you use echo "file content" > filename
- to create a new folder, you use mkdir foldername
- to manipulate system folder, you use sudo before the command
- when you use sudo, you enter your password, and have full power to delete anything within the whole system and only limited in 15 minutes
to be continued...
This article is licensed under CC BY-SA 3.0.