![]() ![]() In zsh -o extendedglob where ^ is a globbing operator, ^ would mean any file but p, q or s. It will fail with the odd named files listed above. However, this command is (somewhat) less reliable. The -d option to ls makes it list the present directory entry instead of the contents of each directory (as presented by default). If there's no matching file, in csh, tcsh, zsh or bash -O failglob, you'll get an error message and the command will be cancelled. The shell is the reason to get a list of directories in the PWD. So in those shells like bash that don't treat ^ specially, if there is a file called ^p in the current directory, that will become ls /usr | grep ^p That means that ^ is meant to be expanded by the shell to the list of files that match that pattern (relative to the current directory). Then, in most shells ( fish being a notable exception), is a globbing operator. First ^ is a special character in a few shells like the Bourne shell, rc, es or zsh -o extendedglob (though OK in bash or other POSIX shells). Since you only want those that start with p, q or s, that's redundant. You can use any of the flags discussed before like -la the key point here is that the result will be outputted into a file and not logged to the command line. Type the ls > output.txt command to print the output of the preceding command into an output.txt file. ![]() a is to include hidden files, that is files whose name starts with. List files and output the result to a file. Generally, you can't post-process the output of ls reliably. So that command doesn't return the files whose name starts with p, q or s, but the lines of the filenames that start with p, q or s. That's probably what your teacher is expecting but it's wrong or at least not reliable.įile names can be made of many lines since the newline character is as valid a character as any in a file name on Linux or any unix. grep searches the named input FILEs (or standard input if no files are named, or if a single hyphen-minus (-) is given as file name) for lines containing a. Would select from the output of ls -a /usr (which is the list of files in /usr delimited by newline characters) the lines that start by either of the p, r or s characters. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |