\ Bodhi Linux

Using LXTerminal as Your File Manager part 1

or How I Ditched PCManFM and Learned to Love the Command Line

Experience Level: Beginner and up

Prerequisites: None - Explaining the LXTerminal and bash is useful but not essential

If you've gotten your feet wet with the LXTerminal tutorials, you may not be surprised to realize LXTerminal can be used in place of Bodhi's default file manager, PCManFM. These commands are “terminal agnostic” and will run in any terminal program you choose to install if you don't prefer LXTerminal.

For some tasks, using a terminal to copy, delete or move files can be faster than clicking-and-dragging with a mouse. It definitely givs you more detail about your files faster than a visual file manager.

In the standard “tradition of unix” we will refer to “folders” as “directories” and “files” as “files.” On the command line of the terminal you “cd” or “change directory.” You don't “cf” or “change folder.” Who would know if “f” stood for “folder” or “file”?

The people who implemented these commands had hundreds of small gotchas! like this over forty years ago to consider, long before there was a “desktop” metaphor or a “folder” icon.

People primarily use their file manager to:
view their directories and files
look for directory and file permissions
change from one directory to another
copy directories and files
move directories and files
delete directories and files
make new directories

The commands you do these tasks with are:
ls to “list” directories and files
cd to “change directory” to another location
cp to “copy” a directory or file
mv to “move” a file or folder to another location and/or name
rm to “remove” file or directory
mkdir to “make a directory”

Seeing Your Files

As mentioned, ls is shorthand for list and shows directories and files in your current directory.

Want to view files in another directory? Think you'll have to use the cd command to view files in /usr/share only to cd back to your home directory? Not so!

You can view the contents of almost any directory by simply remaining yourself and using the ls command with the absolute filename path following it.

(The absolute filename path, for those who didn't read “Using the LXTerminal and Bash, Part 1,” means typing the complete pathway of a directory or file, as in: )

ls /usr/share will immediately display the contents of the usr/share directory. ls /bin will display the contents of /bin

In fact, as an ordinary user (and not as sudo), you can access any directory except for /root and /lost+found If you perform ls /root or ls /lost+found the terminal will immediately respond: ls: cannot open directory /root: Permission denied (or /lost+found: Permission denied)

You can even ls the symbolic links /initrd.img and vmlinuz which appear in pale blue when you ls / Not that there is any reason to do so. The issue, however, is that you can.

"l" and "a" : Two Common Options for ls

Using the l option in combination with ls will give you a “long” listing of file information. (These options are usually referred to as “arguments” and that's what we will use from now on). The syntax is for the command is: ls -l. The space and the dash are important, don't forget them! Typical output may be something like this:

  -rwxr--r-- 1 mark mark     363 2011-03-01 21:11 backup.sh
  drwxr-xr-x 8 mark mark    4096 2011-03-23 21:36 bodhi

You will no doubt see many more entries than just 2 that I've used in the example. The output tells you quite a few useful things about the file. From left to right:

  • - the first dash indicates the backup.sh is a regular file, as opposed to a directory. The “d” on the next line indicates bodhi is a directory.
  • The next 9 characters indicate the permissions of the file/directory, 3 characters each for user, group, and other respectively. r indicates read permission (can look at the file contents), w is write permission (can modify the file contents or filename), x is execute permission (can run the file as a program)
  • The next digit indicates how many sub-directories are contained within a directory. backup.sh is not a directory, so simply has a “1”. bodhi has 6 sub-directories, plus 2 “hidden” directories for a total of 8. (More on “hidden” files and directories in a moment).
  • The next 2 entries indicate who the owner of the file/directory and the group it belongs to. In this case both are owned by mark and in the group mark
  • The next number is file size in bytes. Directories are always 4096, regardless of how much content is within them.
  • The date and time show when the file/directory was last modified.
  • Finally, the name of the file/directory.

Linux makes use of “hidden” files and directories, primarily for configuration files. A hidden file or directory name will begin with a ”.” and will not appear using the ls command with no arguments.

To see all the files, type ls -a from your home directory and you will see many more files and directories. You can also combine it with the ”l” argument to see a long listing of all files/directories.

ls -la

Absolute Paths vs. Relative Paths

The distinction between of absolute paths and relative paths in “Using the LXTerminal and Bash, Part 1” bears repeating for those who haven't read it yet.

You can also use ls (and other commands) using a relative path. This means that you will get different output and/or results relative to where you are running the command in the file system. Typing ls Documents/ will show you the contents of /home/<user>/Documents (<user> will be the name of the user you are currently logged in as). Bash Shell makes the assumption that you want to see the contents of the Documents directory that resides in the directly from which you entered the command.

Suppose you have directories in Documents named Work and Personal. Within Work you have the directories named Sales and Marketing. To see the contents of your Marketing directory type ls Documents/Work/Marketing.

This is what is meant by the relative path - commands you type act on directories and/or file relative to where you are located. Note the lack of a leading ”/” in the last command; if you were to use one the ls command would try to start working at the “root” directory and would (probably) fail since there is (probably) no Documents directory there.

Tab Completion

A short digression here to describe the nifty “shortcut” and very useful Bash built-in feature Tab Completion. In the last command, if you type just ls Doc and then hit Tab you will notice that Bash finishes the word Documents/ for you! Continue typing by entering Wo then hit Tab: Bash will complete Work/, and by typing Marke and Tab, Marketing/ will be completed.

Note that in each example above there are a different number of letters typed each time. Bash will complete from any number of letters entered for which it finds a match.

You may ask, how does Bash know which one to choose if there is more than one match? Well, it doesn't. If there is more than one option, hitting Tab a second time will show you a list of possible matches.

Take, for example, a case where you have the directories Desktop, Documents, Downloads, and Dropbox. If you type ls D and hit Tab nothing will happen, but hitting Tab again will display your choices of those 4 directories. If you want to look in Documents, you can next enter o to make the command be ls Do and hit Tab again. Once more, though, nothing will happen until you hit Tab once more. Bash will then show you the options Documents and Downloads. Entering c at this point and hitting Tab will now auto-complete Documents.

Next: Using LXTerminal as Your File Manager Part 2

User Feedback

Did you find this article helpful?
Yes, right on the money!
Somewhat. Needs work.
Not really
Not at all.

If you would like to comment or make further suggestions, please leave a note on our Comments page (you will have to Create an Account if you haven't already).

original article by Mark Strawser

using_lxterminal_as_your_file_manager_part_1.txt · Last modified: 2012/11/07 11:56 (external edit) · [Old revisions]

© Copyright Bodhi Linux 2012. All Rights Reserved - Hosted by vaultnetworks