Can you specify rules for naming file and directory names under Linux and UNIX operating systems?
Following are general rules for both Linux, and Unix (including *BSD) like systems:
- All 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 short, filenames may contain any character except / (root directory), which is reserved as the separator between files and directories in a pathname. You cannot use the null character.
- 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 (255 bytes). 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 a 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.
Linux / UNIX: Reserved Characters And Words
Avoid using the following characters from appearing in file names:
- /
- >
- <
- |
- :
- &
Please note that Linux and UNIX allows white spaces, <, >, |, \, :, (, ), &, ;, as well as wildcards such as ? and *, to be quoted or escaped using \ symbol.
See also:
Featured Articles:
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- My 10 UNIX Command Line Mistakes
- Linux: 20 Iptables Examples For New SysAdmins

- 25 PHP Security Best Practices For Sys Admins
- The Novice Guide To Buying A Linux Laptop
- 10 Greatest Open Source Software Of 2009
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- Top 20 OpenSSH Server Best Security Practices
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Linux Video Editor Software
Facebook it - Tweet it - Print it -



{ 13 comments… read them below or add one }
i can not execute the following shell command…
“cd directory name with spaces”
Escape the spaces with “\”.
eg.
“cd Directory\ Name\ With\ Spaces”
Thanks for reminding my sluggish memory :P
Thank You Very Much Vivek Sir For All Such Given Information Above…! :-)
SD/-
RoHaN.
alternatively, you can use double quotes for the directory name like
cd “directory name with spaces”
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.
Thanks Bebby, I was not aware of this concept.
The above said comment is applicable only when you try to open the file without quotes as mentioned in comment by Joe.
What are the rules for having in the same directory a file and a sub-directory having the same name? Experimenting on several Linux-es out there it seems that it’s not possible, but somehow I remember seeing this possible on a Linux / Unix-like system before…
what about folders with ()
like # cd (name) dose not work
cd \(name\)
works but not in some scripts I found. looking for a fool proof way coping with file names with space’s and \’s in them especially when doing
diff $A $B && rm -f $B
sort of thing.
What about hyphens, parentheses or brackets?
Many thanks to SutantoKurniawan, Joe and Bebby for their advice on the spaces thing, I’m OK with MSDOS but relatively new to Linux and that one was bugging me.
Regards Terry Bruce.