Display files/directories by letter
Question:
Enter the command to list files and directories in the coffees directory that start with the letter n using a relative pathname. Background: i know if i type "ls n*" it will display it for the current directory but how would i do it for another without physically changing the directory you are in. The directory looks like: /home/eric/dir1/coffees/nuts Attempts: i tried ls ./dir1/coffees n* ls ./dir1/coffees | n* ls n* ./dir1/coffees ls n* | ./dir1/coffees i get the error: ls: cannot access n*: no such file or directory |
Your first attempt is close
Code:
ls ../dir1/coffees/n* You can use as many dirs as it takes eg Code:
ls ../../dira/dir1/coffees/n* http://rute.2038bug.com/index.html.gz http://tldp.org/LDP/Bash-Beginners-G...tml/index.html http://www.tldp.org/LDP/abs/html/ |
thanks!
|
Also take some time to learn more about how globbing works. The shell will expand the wildcards in the given string into a list of matching filenames, if there are any, before the command is run, as a list of arguments for it to process.
For that reason, you also don't need to use ls, unless you want it's advanced file listing features. If you just want to print out a list of items, a simple built-in printf will do just as well. Code:
printf '%s\n' ../../dira/dir1/coffees/n* |
All times are GMT -5. The time now is 11:53 AM. |