or How I Ditched PCManFM and Learned to Love the Command Line
Experience: Beginner and up
Prerequisites: Using LXTerminal as Your File Manager part 1
Now that you have a grasp of
relative paths, using
cd to switch to another location is a breeze. Just type
cd followed by a space and either the
relative path to the directory you want to switch to.
It's worth going back to discussing a little more about some hidden directories that were mentioned earlier. Every directory on a Linux system, even a brand new directory, will contain 2 hidden directories with the unusual names of ”.” and ”..”
”..” is a reference to the directory above the current directory. So, typing
cd .. will move you one directory up in the directory tree.
”.” is a reference to the current directory. This is often useful in executing a command that is not in your
$PATH environmental variable, but that discussion is beyond the scope of this document.
Moving files and/or directories is a simple matter of using the
mv command with the file/directory name and its new location or name as the arguments. For example, to move your resume into my Documents directory, type:
mv resume.odt Documents/
Don't forget to use Tab Completion to make it faster and easier.
mv can also be to rename a file. All it's doing, really, is moving the file/directory to a new name. Suppose you misspelled the name of your resume file when you first saved it. You can fix it with:
mv remuse.odt resume.odt
Note that if you were to do something like this:
mv resume.odt resume.pdf
this will NOT change the format of the file, only the name. To change the format you would have to open the file in an appropriate application and save it in the format you wish.
cp works much the same as
mv, with the difference that
cp will create another instance of the file/directory. Here's an example of making a backup copy of a file you wish to modify:
cp resume.odt resume.odt-orig
This will result in having 2 copies of the file,
You can also use
cp to copy a file to another location:
cp resume.odt Documents/
Notice that you don't need to enter to filename. But if you wish to have the same file with a different name in a different location, just:
cp resume.odt Documents/newresume.odt
To copy a directory and its contents use the
-r argument in addition to the
cp command. To make a backup copy of your Documents directory use:
cp -r Documents Documents.bak
-R) stands for recursive and is a common argument for many commands.
mkdir creates directories. Like so:
You can also make a directory anywhere on the system to using the
relative path name.
DANGEROUS Be careful when using these commands. You will not be asked to confirm that you really want to delete the files/directories. Once you hit Enter, they're gone for good. (Well, there is some recovery methods available, but they are WAY beyond the scope of this document).
rm command is used to remove (delete) files and directories.
rm on a directory, however, will fail because Bash will not “know” what to do with the files inside. Use the recursive argument to overcome this.
rm -r Documents/
More powerful (and more dangerous) is to also add the
-f stands for force and will remove files that you own but don't have
write permissions for. (This sounds like a strange situation, but it does happen. There are circumstances where you may want to set this yourself to protect from accidental deletion.)
rm -rf Documents/
will delete everything in the directory, including non-writable files. Use with caution!
See the “How to use the Trash Can, cli style” article in the Using Bodhi section for a safer way to remove files.
original article by Mark Strawser