How to Find Files With Linux

I just bought a new laptop (Thinkpad T500, which I'll review later) and was trying to copy the files from my old laptop to a portable hard drive. There was an error every time the computer tried to copy a file that contained a colon or a question mark.

I wanted to make a list of all the files that contained those characters so I could rename them and manually copy them over. I was originally looking into piping ls -l into the awk command to extract the filename from the last column. You can apparently extract the last column/field on a line with $NF (See this awk tutorial).

I went onto IRC chat for more info and found out that piping ls into another command automatically lists the files on one line, which removes the need to use awk.

My next step was to try ls and grep commands, but that wasn't working.

Someone on IRC suggested the obvious: use the find command.

Here's how it works:

To recursively find all files in a directory that contain a colon in the filename, use this command:

find . -name \*\:\*

To find files with a question mark in them use:

find . -name \*\\?\*

To save the output as a file, do this:

find . -name \*\\?\* > output.txt

For more on how to use the find command, type man find in a terminal.

No votes yet

Comments

I did not understand why

I did not understand why you escape the asterisk(wild card).
It should be 'find . -name ' concatenate with 2 asterisks , with one backslash and a question mark in between the two asterisks.
Maybe your page has rendered the command not in the way as you typed.

Webmaster Tips's picture

backslashes

I'm not sure -- I typed it as someone sent it to me and it worked as typed above.

The backslashes aren't necessary?

Syndicate content