I'm having trouble creating an alias so I can run find in "silent mode" (without all the Permission denied messages). my bash skills are pretty bad so I'm not sure how to fix this  here's my alias in ~/.bashrc:  alias find='function _find(){find / -name "$1" 2&gt;&amp;1 | grep -v "Permission denied"}'   so if I run source ~/.bashrc and then sudo find "Exercism", I get an output of find: ‘Exercism’: No such file or directory  but running find / -name "Exercism" 2&gt;&amp;1 | grep -v "Permission denied" yields the correct result.  I'm not sure I'm passing the argument right, or at all, into the aliased find function.
1635
It's taken me almost 10 years of Linux usage to ask this question. It was all trial and error and random late-night internet surfing.  But people shouldn't need 10 years for this. If I were just starting out with Linux, I'd want to know: When to alias, when to script, and when to write a function?  Where aliases are concerned, I use aliases for very simple operations that don't take arguments.   alias houston='cd /home/username/.scripts/'   That seems obvious. But some people do this:  alias command="bash bashscriptname"   (and add it to the .bashrc file)   Is there a good reason to do that? I'm trying really hard, but I genuinely can't think of any circumstances in which I'd want to do that. So, if there is an edge case where that would make a difference, please answer below.  Because that's where I would just put something in my PATH and chmod +x it, which is another thing that came after years of Linux trial-and-error.  Which brings me to the next topic. For instance, I added a hidden folder (.scripts/) in the home directory to my PATH by just adding a line to my .bashrc (PATH=$PATH:/home/username/.scripts/), so anything executable in there automagically autocompletes.  If I needed to.  I don't really need that, though, do I? I would only use that for languages that are not the shell, like Python.  If it's the shell, I can just write a function inside the very same .bashrc:  funcname () {   somecommand -someARGS "$@" }   As I stated, I found a lot of this out through trial and error. And I only truly saw the beauty of functions when my computer died and I was forced to use the computers of the people around me when they weren't using them.   Instead of moving a whole directory of scripts from computer to computer, I ended up just replacing everyone else's .bashrc with my own, since they had never even made a single modification.  But did I miss anything?   So, what would you tell a beginning Linux user about when to alias, when to script, and when to write a function?   If it's not obvious, I'm assuming the people who answer this will make use of all three options. If you only use aliases, or only use scripts, or only use functions—or if you only use aliases and scripts or aliases and functions or scripts and functions—this question isn't really aimed at you.
121013
Exec allows us to either pass all arguments at once with {} + or to pass them one by one with {} \;  Now let's say I want to rename all jpeg, no problem doing this:  find . \( -name '*.jpg' -o -name '*.jpeg' \) -exec mv '{}' '{}'.new \;   But if I need to redirect output, '{}' isn't accessible after redirection.  find . \( -name '*.jpg' -o -name '*.jpeg' \) -exec cjpeg -quality 80 '{}' &gt; optimized_'{}' \;   This wouldn't work. I'd have to use a for loop, storing find's output into a variable before using it. Let's admit it, it's cumbersome.  for f in `find . \( -name '*.jpg' -o -name '*.jpeg' \)`; do cjpeg -quality 80 $f &gt; optimized_$f; done;   So is there a better way?
24279
I want to make an alias in my .bashrc or .bashrc_aliases file (probably the latter).  Specifically, I want to call the clang command for my *.c file I'm writing. What I'm looking for is best summed up if I provide an example:  I have program1.c written I want to be able to type (in the terminal) compile program1, and something like the following should be actually run:  clang -ggdb -std=c99 -Wall -Werror   program1.c -lcrypt -lcs50 -lm -o program1   For those who have taken Harvard's CS50 class, you will recognize this as their make command. So if the above is impossible, and you know another way to make this happen, I'm all ears. I'm trying to avoid using their VM, as my netbook isn't really up to par to handle a VM.
50121
The man page for GNU find states:    -exec command ;     [...] The  string `{}'  is  replaced  by the current      file name being processed everywhere it occurs in the      arguments to the command, not just in arguments where      it is alone, as in some  versions  of  find.     Both  of  these  constructions might need to be escaped      (with a `\') or quoted to protect them from expansion      by the shell.     That's from the man to find (GNU findutils) 4.4.2.   Now I tested this with bash and dash, and both don't need to have the {} being masked. Here is a simple test:  find /etc -name "hosts" -exec md5sum {} \;    Is there a shell, for which I really need to mask the braces? Note, that it doesn't depend upon whether the file found contains a blank (invoked from bash):   find ~ -maxdepth 1 -type d -name "U*" -exec ls -d {} \;  /home/stefan/Ubuntu One   This changes if the found file is passed to a subshell:  find ~ -maxdepth 3 -type d -name "U*" -exec bash -c 'ls -d {}' \;  ls: cannot access /home/stefan/Ubuntu: No such file or directory ls: cannot access One: No such file or directory   which can be solved by:  find ~ -maxdepth 3 -type d -name "U*" -exec bash -c 'ls -d "$0"' {} \;   in contrast to:   find ~ -maxdepth 3 -type d -name "U*" -exec bash -c 'ls -d "{}"' \;  /home/stefan/Ubuntu One   but that's not what the man page is talking about, is it? So which shell treats {} in a different way?
46712
I put some alias commands in my .bashrc file, so that they might be loaded everytime I open a new Terminal window. Yet this doesn't happen. I have to select run script: in the Terminal&gt;Preferences&gt;&quot;MyDefaultTheme&quot;&gt;Shell prefpane and add: source .bashrc &amp;&amp; clear for it to work... This seems odd since many tutorials only say you just have to add to the .bashrc file and all is good. Note that I don't run in bash when using the terminal, I like the other (default) one (don't know what it is) better, because it show me where I am all the time eg: &gt;&gt;d54c6b47b:~ romeo$  in stead of: &gt;&gt;bash$  In bash all is loaded as should be. So my question is, why didn't my .bashrc file load automatically and did I have to add the option to call it everytime? Also some tutorial told me to do something like: $alias la=’ls -la’ &gt;&gt; ~/.bashrc  which should write the alias to my .bashrc, this doesn't work either... Note that I'm a UNIX novice, so be gentle.
61685
I'd like to find the files in the current directory that contain the text "chrome".  $ find . -exec grep chrome find: missing argument to `-exec'   What am I doing wrong?
56238
Bash 4.2 on CentOS 6.5:  In my ~/.bash_profile I have a bunch of aliases, including:  alias grep='grep -n --color=always'   so that I can get color highlighting and print line numbers automatically when running grep. If I run the following, highlighting works as expected:  $ grep -Re 'regex_here' *.py   However, when I ran this recently:  $ find . -name '*.py' | xargs grep -E 'regex_here'   the results were not highlighted and line numbers weren't printed, forcing me to go back and explicitly add -n --color=always to the grep command.   Does xargs not read aliases in the environment? If not, is there a way to make it do that?
1256
In my ~/.bashrc file reside two definitions:   commandA, which is an alias to a longer path commandB, which is an alias to a Bash script   I want to process the same file with these two commands, so I wrote the following Bash script:    #!/bin/bash  for file in "$@"     do     commandA $file     commandB $file done   Even after logging out of my session and logging back in, Bash prompts me with command not found errors for both commands when I run this script.  What am I doing wrong?
81980
On a server when I login as root I see .bashrc (Ubuntu 10.10).  On my Mac I have a .bash_profile  Does Ubuntu always have only a .bashrc file and not .bash_profile? (I'm just confused, so asking, I realize they are different o/s's but maybe there is a relationship somehow?)  On my server, I want to create an alias, should I put it in .bashrc?  What if I want this alias to be applied so all users can use it?
19837
I want to know if I can pass an argument with an alias command.  for example:  alias d="dmesg|grep -iw usb|tail -5"    Now d will print the last 5 lines. If I want to use d to print a different number of lines, I have to make change in the alias command declaration of d again.  Is there any way I can modify the declaration of an alias so that I don't have to retype the declaration to change the number of lines. Like incorporating passing the number of lines as an argument while declaring alias for d? Or is there some other method to solve this?
55288
G'day,   I have tried to solve this problem all morning but have not had success. I would like to search for certain scripts in a particular folder and execute them all in parallel. The scripts have different names, but all end with "run.sh". Below what I have tried without success.   The first approach was to use find in combination with -execdir. This works, however, the scripts are executed in a sequantial fashion. I want all scripts to be executed simultaneously (parallel). There seems to be no option to achieve this with -execdir  find . -name "*run.sh" -type f -execdir 'nohup' {} '&amp;' \;   Then, I tried using xargs because there is has a parallel option (-P). I have not tried the parallel option yet, because I am unable to get xargs to run the scripts in their respective subfolders. The commands below execute all scripts, but do that in the folder I am running the command in, therefore the scripts themselves do not work. The scripts have to be executed in their own subfolders. In the above example, -execdir is doing that as opposed to -exec. How do I achieve that with xargs?  nohup find . -name "*run.sh" -type f | xargs -0 -I{} bash -c f\ \{\}   or  nohup find . -name "*run.sh" -type f | xargs -0 -I{} bash -c "f {}"   or  nohup find . -name "*run.sh" -type f | xargs -0 -I{} bash -c "./{}"    I am really frustrated and am hoping that there is somebody out there that can help.  Thank you so much!
103444
I've added the line   alias ll='ls -l'   to the /etc/bash.bashrc. After a restart, the alias ll from that file affects me, which I checked by commenting out the corresponding alias in my ~/.bashrc (and logging out and back in after that edit). However, it seems to not affect root, as when I type sudo ll, I get "no such command". Shouldn't the alias work in any situation if it's in the system-wide .bashrc?
100841
I'm using the command  ls -a | grep '^\.'  for showing only the hidden files. I added the line  alias hidden='ls -a | grep '^\.'' # show only hidden files  to .bash_aliases file  but this does not work. It's probably the problem with ' character.  Could you please help me write the correct alias?
37969
How to create an alias that actually extends another alias of the same name in Bash?  Why:  I used to have GREP_OPTIONS set on .bashrc to something like this:  GREP_OPTIONS="-I --exclude=\*~"   I also had a script (let us say, setup-java.sh) which I would call before working on some Java projects. It would contain the line:  GREP_OPTIONS="$GREP_OPTIONS --exclude-dir=classes"   If I also use Sass, then I would call setup-sass.sh which contains the line:  GREP_OPTIONS="$GREP_OPTIONS --exclude-dir=\*/.sass-cache"   But  and apparently the standard solution is either create an alias or some script...
115700
I have a directory, dir1 which contains many files whose names end in either .jpg or .png. I want to copy all the .png files to dir2 which is empty.  This command works:  find dir1 -name '*.png' -exec cp {} dir2 \;   but this command doesn't:  find dir1 -name '*.png' -exec cp {} dir2 + find: missing argument to `-exec'   I also tried:  find dir1 -name '*.png' -exec cp {} -t dir2 + find: missing argument to `-exec'   and:  find dir1 -name '*.png' -exec cp {} dir2 \+ find: missing argument to `-exec'   After looking at , I even tried:  find dir1 -name '*.png' -exec cp {} dir2 {} + find: Only one instance of {} is supported with -exec ... +    says that:     -exec {} + was added in [version] 4.2.12 in 2005   My version of find is 4.4.2.  What am I doing wrong?
94744
I'm trying to find where a specific alias has been declared. I've searched all the usual places I know to look for aliases:   ~/.bashrc ~/.bash_profile /etc/bashrc /etc/profile   With no luck.  I know it's an alias because when I do which COMMAND, I get:  alias COMMAND='/path/to/command'     /path/to/command   Is there a way to find what file declares an alias only knowing the alias name?
12595
I'm using find with the -exec option in console, on FreeBSD (for example, find . -exec sha1 {} \;).   How do I correctly place (and if needed, escape) redirect and other execution control symbols that could syntactically apply to either of the exec command or the find command, such as > >> | and &amp;, where I might want the symbol to apply to the find or the exec commands on different occasions?  On the same theme, what is the syntax if I want to use tee to view the output of the -exec commands on the console (to watch progress) and also appended to a file (for later use)?   (I know shells vary but hopefully the most used shells such as sh/csh are quite similar?)  Update:  In part, I want to learn if nested find -exec can be done without scripting, as a simple command. Here is the use-case that prompted the questio :   outer find: find all subdirs matching DIR_MATCH_TEXT in DIR1  inner find: for each matching subdir found in the outer loop (call it DIR2), execute the commandfind DIR2 -name "FILE_MATCH_TEXT" -exec sha1 {} \; &gt;&gt; DIR1/DIR2_hashes.txt   The aim being to create a set of files, one for each matching subdir, containing the output of some find -exec action on that subdir.  By this I mean that, if /backups contains /jan2017 and /feb2017, the result will be two files at /backups/jan2017_hashes.txt and /backups/feb2017_hashes.txt, with jan2017_hashes.txt containing the output from sha1 for (say) all .pdf files in /backups/jan2017, and feb2017_hashes.txt containing the output from sha1 for all .pdf files in /backups/feb2017.  From replies so far I gather the outer find would have to use a shell call as the argument to -exec?