trackgasil.blogg.se

Grep usage in the file name in linux command line
Grep usage in the file name in linux command line













And of course, we can look for files that don’t contain the search term. The file names are listed, not the matching lines.

Grep usage in the file name in linux command line code#

To find out which C source code files contain references to the sl.h header file, use this command: grep -l 'sl.h'. In zsh -o extendedglob where ^ is a globbing operator, ^ would mean any file but p, q or s. To see the names of the files that contain the search term, use the -l (files with match) option. 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.

grep usage in the file name in linux command line

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. a is to include hidden files, that is files whose name starts with. 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.

grep usage in the file name in linux command line

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 usage in the file name in linux command line

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.













Grep usage in the file name in linux command line