Linux/UNIX: Rules for naming file and directory names

Following are general rules for both Linux. BSD, Unix like systems:

* File names are case sensitive. So filename vivek.txt Vivek.txt VIVEK.txt all are three different files.

*You can use upper and lowercase letters, numbers, "." (dot), and "_" (underscore) symbols.

* You can use other special characters such as blank space, but they are hard to use and it is better to avoid them.

* In shot, filenames may contain any character except /, which is reserved as the separator between files and directories in a pathname.

* No need to use . (dot) in a filename. Some time dot improves readability of filenames. And you can use dot based filename extension to identify file. For example

  • .sh = Shell file
  • .tar.gz = Compressed archive

* Most modern Linux and UNIX limit filename to 255 characters. However, some older version of UNIX system limits filenames to 14 characters only.

* A filename must be unique inside its directory. For example, inside /home/vivek directory you cannot create demo.txt file and demo.txt directory name. However, other directory may have files with the same names. For example, you can create demo.txt directory in /tmp.

See also:

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 6 comments… read them below or add one }

1 KarthiKeyan 02.19.07 at 8:23 pm

i can not execute the following shell command…

“cd directory name with spaces”

2 SutantoKurniawan 06.27.07 at 5:25 pm

Escape the spaces with “\”.
eg.

“cd Directory\ Name\ With\ Spaces”

3 RoHaN 08.27.07 at 10:24 am

Thank You Very Much Vivek Sir For All Such Given Information Above…! :-)

SD/-
RoHaN.

4 Joe 02.29.08 at 6:16 pm

alternatively, you can use double quotes for the directory name like

cd “directory name with spaces”

5 bebby 02.19.09 at 9:28 am

Must be very careful when creating files/ directories names with spaces.. considering a file is created with its name “tempfile with spaces” and if the same directory has another file named just “tempfile”, the contents written to the file “tempfile with spaces” will also be written to the file “tempfile”. Better avoid creating files with spaces in the filename.

6 bebby 02.19.09 at 9:31 am

The above said comment is applicable only when you try to open the file without quotes as mentioned in comment by Joe.

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Previous post: What Happens When Hard Disk Fails in RAID 5

Next post: Linux/UNIX: chmod error