Handling Corrupted File Names in Linux
by Eugene Mazarakis
Introduction
Many times in your job as a data engineer, you need to manage files on Linux. Sometimes these files may have strange names, such as ‘test file name’ or ‘-fileTest000’. How can you display these files in Linux?
In the linux folder we have the following two files:
- -fileTest000 (dash in front of the name)
- test file name (spaces between the words)
Solution
- -fileTest000
When you run the command cat -fileTest000, it doesn’t display the contents of the file. It interprets the ‘-‘ as an option for something, as shown below. So, if you want to display the contents of the file, you should provide the full file path. One of the ways to do that is the following:
cat “$(pwd)/-fileTest000”
- test file name
When you run the command cat test file name, it doesn’t display the contents of the file. So, if you want to display the contents of the file, you should do one of the following:
- cat ‘test file name’
- cat “test file name”
- cat test\ file\ name