Freedom The Open Source Way Contribute Articles or News to OSForgeOSForge HomeLogout from Forums
Contacting OSForgeOSForge HomeAbout OSForge
  

Root
Contribute News
Learning Corner
Linux Distributions
Linux Common FAQ's
Discussion Forums
Community Gallery
Links Directory
Search OSForge
Networking
Industry Updates
Linux & Open Source
Opinions
Press Release
Programming
Security
Web Development

White Paper
Plat'Home Unveils Winners of “Will Linux Work?” Contest
Zenoss Core Recognized as Best Open Source Network Monitoring Solution
LinMin™ Joins Intel® Certified Software Solutions Program
xTuple™ ERP 3.0 Wins “Best Business Application” At LinuxWorld Conference & Exp
Holland Computing Center - Rocks+Moab Provides Windows/Linux Cluster Solution
LogMeIn Launches Mobile Plug-in for Linux
FuseMail Selects Funambol’s Open Source Push Email and PIM Sync Solution
Zenoss Expands IT Management Solution for Managed Service Providers
Moab Workload Manager Claims Title as World’s First Petaflop Scheduler
Moab Workload Manager Claims Title as World’s First Petaflop Scheduler

View More

Linux Newbie Guide III - Basics

Page: 1/10  [Printable Version]



Filenames
Linux is case-sensitive. For example: myfile, Myfile, and myFILE are three different files. Your password and login name are also case-sensitive. (This follows tradition since both UNIX and the "c" programming language are case-sensitive.)  Naming conventions for files and directories are identical. All the files and directories which I create (for myself, as a user) are lower-case, unless there is a very special reason to make it different. Most of Linux commands are also all lower case.
Filenames under Linux can be up to 256 characters long and they normally contain letters, numbers, "." (dots), "_" (underscores) and  "-" (dashes).  Other characters are possible but not recommended.  In particular, it is not recommended to use special metacharacters: "*" (asterisk), "?" (question mark), " " (space),  "$" (dollar sign),  "&" (ampersand), any brackets, etc. This is because metacharacters have special meaning to the Linux shell (shell is something like COMMAND.COM, the command processor under DOS).  It is possible to have a space in the filename, but we don't recommend it either--we use underscore "_" instead.
It is not possible at all to have '/' (slash) as a part of the filename because  '/' is used to represent the top of the directory tree, and as a separator in the pathnames (the same as '' is in DOS).

Like in DOS, I cannot have a file called . or a file called.. (dot or two dots)--they mean current and parent directory respectively, exactly like in DOS.

Here is the meaning of some metacharacters:
*  = Matches any sequence of zero or more characters, except for  "." (a dot) at the beginning of a filename.
?  = Matches any single character.
[abC1]  = Matches a single character in the enumerated set. In this example the set contains: 'a',  'b',  'C', and '1'.
[a-z] = Matches any lower-case letter.
[A-F] = Matches any upper-case letter from A to F.
[0-9] = Matches any single digit.
[a-zA-Z0-9] = Matches any letter (lower or upper case) or any digit.
Examples. This command will list any filename in the current directory, with the exception of filenames starting with "." (dot):
ls *
An equivalent to this command is to type just ls  or  dir (without the "*").  Files with names starting with "." are not shown because "."  as the first character of a filename is not matched by "*". Think of files with names starting with "." as an equivalent of DOS hidden files.  Use ls -a (list with the option "all") or ls .* to see these  "dot" files.  The dot-files are common in the user home directories and are typically used to contain user-level configurations.
This command will list any file (current directory) that contains a dot:
ls *.*
This command will list any filename that contains two dots:
ls *.*.*
Please note that Linux does not have "filename extensions" the way DOS does, but you can still use them. For example, I can have a file my_text.txt.zip. Some other DOS-kind file-naming features are completely absent ("Micros~1.doc" comes to mind).
This command will find (on the whole filesystem) any file with the extension "htm" optionally followed by any one more character:

locate *.htm?

This command will show all filenames in the current directory that start with "a" or "b", or any capital letter:

ls [abA-Z]*
This command will list any file starting with "a" and ending with "n"

ls a*n

Command line autocompletion.  This is a great command line feature--I use the [Tab] key a lot to save on typing. It makes it brisk to deal with long and complicated filenames. For example using such a filename on the command line is really not a problems, if I use autocompletion:

dir Eurosong 2000 Olson Brothers - Fly on the wings of love (denmark).mp3

I just type

dir Eu[Tab]

and if there are no other files starting with "Eu", the rest of the filename is automatically typed for me. Otherwise, I would have to look at my choices (which are printed for me) and type one or two more characters to make the filename unambiguous.

Problems with weird filenames.  Most of these problems can be solved using autocompletion. Additionally, to manipulate files with names that contain metacharacters, I may use a pair of ' ' (two apostrophes), so that the metacharacters are quoted and therefore the shell does not interpret their meaning. For example, to rename a file my file* (contains space and asterisk), I would issue:

mv 'my file*' filename_without_weird_characters.txt

Please note that I use a pair of ' (apostrophes) for quoting. Quoting with a pair of "  " (quotation marks) is generally weaker than quoting with '  ' . If you use " (quotation marks)  some metacharacters may get interpreted.

Following UNIX tradition, on Linux, one may create files with names contaning almost any character, including non-printable (control) characters. Those are very infrequent, but if you encounter such a file, it can make you feel really weird. I would rename such a file using a carefully positioned metacharacter. I would use ls first to try if my action indeed targets the desired file, and then rename the file:

ls -l myfile*y.html
mv myfile*y.html myfile.html

As an example of the perhaps weirdest problems that you might face when using non-recommended characters in a filename, try creating a file with a name starting with a dash and then remove it--there seems to be no way to do it (because a dash normally introduces command options).  E.g., the command
dir > -junk

will create such a funny file (like in DOS, the symbol ">" redirects the output from the dir command to a file named -junk).  Since the regular way of removing the file -junk does not work, I use:
rm ./-junk
The dot slash at the beginning  means "the current directory" and here just serves the purpose of hiding the leading dash so it is not interpreted as introducing an option to the rm command.  The point here is that I would rather stick to traditional naming conventions than face the occasional complications.
   Next Page >> (2/10) Next Page >>

[ Back to Linux Computing | Sections Index ]

 
Scroll Up

   About | Term of Use | Privacy | Adras | Tell a Friend | Advertise  

OSForge News RSS Feed