Visit Our UNIX and Linux User Community


Having trouble creating an alias for grep

 
Thread Tools Search this Thread
Operating Systems OS X (Apple) Having trouble creating an alias for grep
# 1  
Old 03-14-2014
Having trouble creating an alias for grep

Hi,

I'm using Mac 10.9.1. I would like to create an alias for grep so that it won't print out messages like "grep: /Users/davea/workspace/myproject/subdir/: Is a directory" all the time. So in my terminal, I opened ~/.profile and entered

Code:
alias grep='grep -s'

However, when I close and re-open my terminal and then enter

Code:
find ~/workspace/myproject/ -name "*" | xargs grep 'mytoken'

I still get the above messages. What else do I need to do to make these messages go away by default?

Thanks, - Dave
# 2  
Old 03-14-2014
Code:
find ~/workspace/myproject/ -type f -exec grep 'mytoken' {} \;

Try using the full power of find. -type f restricts the search to regular files, so it excludes directories. The "*" is not needed because find looks at all files by default. if you wanted filenames that end in dat, then -name '*dat' would be required.
# 3  
Old 03-14-2014
Thanks, although my question has less to do with find and more to do with why the grep alias isn't working. Do you know why that is? I just used the find as an example, but maybe I should dig up another example that doens't involve find so as not to distract from the problem.

- Dave
# 4  
Old 03-16-2014
Quote:
Originally Posted by laredotornado
Thanks, although my question has less to do with find and more to do with why the grep alias isn't working. . . .
man bash:
Quote:
ALIASES
Aliases allow a string to be substituted for a word when it is used as the first word of a simple command. . . .
That's why none of your longer commands will be working...

Last edited by RudiC; 03-18-2014 at 11:18 AM.. Reason: grammatical error
# 5  
Old 03-17-2014
Is there anotehr way I can make "grep -s" the default behavior for my grep command assuming the "alias" I specified isn't an option?
# 6  
Old 03-17-2014
man again, here man grep:
Quote:
ENVIRONMENT VARIABLES
The behavior of grep is affected by the following environment variables.
. . .
GREP_OPTIONS
This variable specifies default options to be placed in front of any explicit options.
This User Gave Thanks to RudiC For This Post:

Previous Thread | Next Thread
Test Your Knowledge in Computers #1007
Difficulty: Medium
ix = ln(cos x+isin x)
True or False?

10 More Discussions You Might Find Interesting

1. Red Hat

Trouble creating RHEL 6.5 bootable image with custom kickstart file

Hi everyone, I have a custom kickstart file from a software vendor and I'm trying to package that with a RHEL 6.5 and then attach it to a VM and install RHEL with the settings in the kickstarter file. I'm doing this from a windows PC using an app called InfraRecorder. I've extracted the... (0 Replies)
Discussion started by: 911Eric
0 Replies

2. Solaris

Trouble creating a disk partition slice (EFI)

Hi all, I am using SPARC Solaris 11.1 with EFI labelled disks. I am new to ZFS file systems and slightly stuck when trying to create a partition (slice) on one of my LUNs. EFI labels use sectors and blocks and I am not sure how exactly it works. From here I can try and create a... (2 Replies)
Discussion started by: selectstar
2 Replies

3. Shell Programming and Scripting

Having a little trouble with grep

I am trying to make a script that has grep finding lines that I get from the cat command, that start with something and end with an argument. I can get the first part, but whenever I try to add on the part that looks at the end of the line too, it stops working. Any ideas why? Here is my script: ... (11 Replies)
Discussion started by: sammythesp3rmy
11 Replies

4. Linux

Grep Alias

I would like to create an alias on my 'grep' command on Linux. Generally when I use 'grep', I do as follows: $ ps -ef | grep -i ntp | grep -v grep My question is how can I simply run the 'grep' command as shown above and it also include the -i / -v switches as well w/o me having to enter... (1 Reply)
Discussion started by: cmennens
1 Replies

5. Homework & Coursework Questions

Creating a .profile, displaying system variables, and creating an alias

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Here is what I am supposed to do, word for word from my assignment page: 1. Create/modify and print a... (2 Replies)
Discussion started by: Jagst3r21
2 Replies

6. UNIX for Dummies Questions & Answers

Help on creating and saving an alias

Hello, I want to create an alias for this command: grep -i "<keyword_to_search>" <path_to_search> Here's the alias I intended to make: alias k 'set ARGS1 =(\!1); set ARGS2 =(\!2); grep -i "$ARGS1" ARGS2' So that next time, for example, if I want to search the keyword "Help" in the path... (5 Replies)
Discussion started by: mar85
5 Replies

7. Shell Programming and Scripting

Creating .../ alias in bash

I want to create an alias as follows but is not working alias ../='cd ../' (3 Replies)
Discussion started by: kristinu
3 Replies

8. Solaris

Creating Alias for FILE

Hello, I need the command to create alias for a file "FILE" (NOT for commands) ? And Is there any difference between creating alias for files and creating alias for commands ? For info, i'm using Solaris 8 Thx, http://www.unix.com/images/misc/progress.gif (5 Replies)
Discussion started by: newpromo
5 Replies

9. UNIX for Dummies Questions & Answers

Creating alias for directory path

I am trying to create an alias for a frequently used directory path by using alias xyz="/proj/dir_name" and then trying to reach a sub-directoy by using cd xyz/abc but I get an error saying " No such file or directory " plz tell me wats wrong with this ... (3 Replies)
Discussion started by: jasjot31
3 Replies

10. IP Networking

ifconfig: difference between creating logical or alias network interface

Hi guys, I have set up multiple virtual FTP servers on a server through one physical NIC. I believe there are to ways; setting logical or alias ip's. I would like to know what is the difference between setting up a logical ip or setting up an alias ip to a physical network interface? Some links to... (5 Replies)
Discussion started by: zaff
5 Replies

Featured Tech Videos