Working with files names that have spaces and special characters

Sometimes you need to work with multiple files that have spaces in their names.

To do this you can backslash the special characters (\) or put quotes around their names..If you use filename completion, it should backslash the characters for you.

To see files with control characters add the “–show-control-chars” option to your ls command.  You will need the -a option to see “hidden” files that start with a “.”.

If you want to work with a set of file and some have space or other characters in them you can use the read command in a loop to work with the files.

Let’s say you want to in find all the files that have “finding deleted files” in the them in the /home/ directory and display the filenames and the content.  You can use this command:

find /home -type f|while read FILE; do
grep "finding deleted files" "$FILE" /dev/null

They /dev/null adds a second filename to the list so grep will print the filename.

Leave a Reply

Your email address will not be published. Required fields are marked *