1

I need to display the permissions details for all the files names in a directory that begin with just "_". I have tried various commands using ls and find and no joy.

  • Do the filenames start with dash or the ls permissions string? – Jeff Schaller Oct 3 '18 at 19:10
  • Sorry its an underscore, the file names that start with an underscore – Deirdre Oct 3 '18 at 19:17
  • Sorry for the mis-edit, then! You had an underscore in the title, but a dash in the body. Feel free to edit the question to take it in the correct direction. Thank you! – Jeff Schaller Oct 3 '18 at 19:17
6

Try:

ls -l -- -*

The -- indicates that what follows are not command line options.

Based on your update, for underscores you should just be able to do:

ls -l _*

Though the -- option won't hurt (it just won't do anything in that case)

  • yes i used _ as i noticed the dash. worked perfectly – Deirdre Oct 3 '18 at 20:15
4

"-" is interpreted as a parameter, but you don't need to suffer, just append the path before the file name or just use ./.

touch ./-badfilename1 ./-badfilename2
ls -l ./-* 
ls -l /full/path/for/the/file/-* 
rm ./-badfilename? 

And every command will just work (ls, rm, cat, touch etc!).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.