Home
Misc
Linux
TCP/IP
Windows
Random Daodejing
Photos

Linux

I/O Redirection & Pipes  /  Filenames with Spaces, Apostrophes, etc.  /  Desktop Configuration   



FILENAMES WITH SPACES, APOSTROPHES, ETC.


Filenames with spaces can be worked with in a couple different ways:

$ less filename\ with\ spaces

or

$ touch 'filename with spaces'

or

$ touch "filename with spaces"


In the first example the escape character (\) is used, e.g.

$ cd /media/Stuff/My\ Data/

same as,

$ cd /media/Stuff/"My Data


What if you have quotes in the filename??
--------------------------------------------------------

In this rare occurance, you simply wrap the filename with the opposite (single or double) quotation!

$ touch "05'.txt"

and

$ touch '05".txt'


Files that start with -
---------------------------

rm ./-iputadashinthefoldername


In this example the 'complete path' is used.


Other
--------

Other special characters such as ? or # can be dealt with similarly to working with spaces, using the escape character to change the interpretation.


Unix Shell Metacharacters
-----------------------------------

>        Output redirection
>>        Output redirection (append)
<        Input redirection
*        File substitution wildcard; zero or more characters
?        File substitution wildcard; one character
[ ]        File substitution wildcard; any character between brackets
`cmd`        Command Substitution
$(cmd)        Command Substitution
|        Pipe (|)
;        Command sequence, Sequences of Commands
||        OR conditional execution
&&        AND conditional execution
( )        Group commands, Sequences of Commands
&        Run command in the background, Background Processes
#        Comment
$        Expand the value of a variable
\        Prevent or escape interpretation of the next character
<<        Input redirection


Escaped Characters
---------------------------

\NNN        the character whose ASCII code is NNN (octal)
\ \        backslash
\a        alert (BEL)
\b        backspace
\c        suppress trailing newline
\f        form feed
\n        new line
\r        carriage return
\t        horizontal tab
\v        vertical tab


Further Reading
---------------------

Reserved Characters and Words
https://en.wikipedia.org/wiki/Filename#Reserved_characters_and_words

Fixing Unix/Linux/POSIX Filenames:  Control Characters (such as Newline), Leading Dashes, and Other Problems
https://dwheeler.com/essays/fixing-unix-linux-filenames.html