Sunday, August 23, 2015

command line - print names of files in folder from path in terminal


I was making a program and want to see all the items in a folder by giving it the path. my program uses the terminal so the commands are the same.


something along the lines of


echo "/Users/Danny/Desktop/saves"


save1.txt
save2.txt
save3.txt


that doesn't work that way but is there a way of doing that?


Answer



echo isn't the right command and I don't think you have the file path quite right. You'll need to specify an absolute or a relative path and it looks like you aren't doing either. A tilde (~) should suffice (e.g. ~/Users/Danny...) for a relative path.


I think the command you're looking for is "ls" (that's an L in lowercase and not a 1 just for clarification).



  • ls "/Users/Danny/Desktop/saves" will list the visible contents of the folder.

  • ls -al "/Users/Danny/Desktop/saves" will list everything (including any hidden content).

  • ls -R "/Users/Danny/Desktop/saves" will list files in subdirectories.


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...