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”
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.
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
ls /bin will display the contents of
In fact, as an ordinary user (and not as
sudo), you can access any directory except for
/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
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 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:
backup.shis a regular file, as opposed to a directory. The “d” on the next line indicates
bodhiis a directory.
rindicates read permission (can look at the file contents),
wis write permission (can modify the file contents or filename),
xis execute permission (can run the file as a program)
backup.shis not a directory, so simply has a “1”.
bodhihas 6 sub-directories, plus 2 “hidden” directories for a total of 8. (More on “hidden” files and directories in a moment).
markand in the group
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.
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
Work you have the directories named
Marketing. To see the contents of your Marketing directory type
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.
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
c at this point and hitting Tab will now auto-complete
original article by Mark Strawser