terminal commands to get hidden files ending with a particular pattern - terminal

I can easily search for non-hidden files in terminal ending with a particular pattern.
*for example*
Consider these files are present in the folder in which I am searching
1new 2new 3new 4new .5new
If I enter the command la *ew I get these files as output
1new 2new 3new 4new
I am getting the same result when using ls -a *ew
So what command should I enter in order to get hidden files ending with a particular pattern.

ls does not support regular expressions as per my understanding. So, you might need to pipe the output to some other command like grep which supports regular expressions. Try below command and see if it works as per your need.
ls -a | grep new
Refer this post for more information.

Related

"cat - 1>& 2" Command Interpretation [duplicate]

Examples:
Create an ISO image and burn it directly to a CD.
mkisofs -V Photos -r /home/vivek/photos | cdrecord -v dev=/dev/dvdrw -
Change to the previous directory.
cd -
Listen on port 12345 and untar data sent to it.
nc -l -p 12345 | tar xvzf -
What is the purpose of the dash and how do I use it?
If you mean the naked - at the end of the tar command, that's common on many commands that want to use a file.
It allows you to specify standard input or output rather than an actual file name.
That's the case for your first and third example. For example, the cdrecord command is taking standard input (the ISO image stream produced by mkisofs) and writing it directly to /dev/dvdrw.
With the cd command, every time you change directory, it stores the directory you came from. If you do cd with the special - "directory name", it uses that remembered directory instead of a real one. You can easily switch between two directories quite quickly by using that.
Other commands may treat - as a different special value.
It's not magic. Some commands interpret - as the user wanting to read from stdin or write to stdout; there is nothing special about it to the shell.
- means exactly what each command wants it to mean. There are several common conventions, and you've seen examples of most of them in other answers, but none of them are 100% universal.
There is nothing magic about the - character as far as the shell is concerned (except that the shell itself, and some of its built-in commands like cd and echo, use it in conventional ways). Some characters, like \, ', and ", are "magical", having special meanings wherever they appear. These are "shell metacharacters". - is not like that.
To see how a given command uses -, read the documentation for that command.
It means to use the program's standard input stream.
In the case of cd, it means something different: change to the prior working directory.
The magic is in the convention. For millennia, people have used '-' to distinguish options from arguments, and have used '-' in a filename to mean either stdin or stdout, as appropriate. Do not underestimate the power of convention!

What does "-" (dash) means in bash? [duplicate]

Examples:
Create an ISO image and burn it directly to a CD.
mkisofs -V Photos -r /home/vivek/photos | cdrecord -v dev=/dev/dvdrw -
Change to the previous directory.
cd -
Listen on port 12345 and untar data sent to it.
nc -l -p 12345 | tar xvzf -
What is the purpose of the dash and how do I use it?
If you mean the naked - at the end of the tar command, that's common on many commands that want to use a file.
It allows you to specify standard input or output rather than an actual file name.
That's the case for your first and third example. For example, the cdrecord command is taking standard input (the ISO image stream produced by mkisofs) and writing it directly to /dev/dvdrw.
With the cd command, every time you change directory, it stores the directory you came from. If you do cd with the special - "directory name", it uses that remembered directory instead of a real one. You can easily switch between two directories quite quickly by using that.
Other commands may treat - as a different special value.
It's not magic. Some commands interpret - as the user wanting to read from stdin or write to stdout; there is nothing special about it to the shell.
- means exactly what each command wants it to mean. There are several common conventions, and you've seen examples of most of them in other answers, but none of them are 100% universal.
There is nothing magic about the - character as far as the shell is concerned (except that the shell itself, and some of its built-in commands like cd and echo, use it in conventional ways). Some characters, like \, ', and ", are "magical", having special meanings wherever they appear. These are "shell metacharacters". - is not like that.
To see how a given command uses -, read the documentation for that command.
It means to use the program's standard input stream.
In the case of cd, it means something different: change to the prior working directory.
The magic is in the convention. For millennia, people have used '-' to distinguish options from arguments, and have used '-' in a filename to mean either stdin or stdout, as appropriate. Do not underestimate the power of convention!

Fuzzy search Shell command?

The following situation:
I am on a different mac (no command history) using the Terminal (bash) remembering only a part of a command e.g. searching for a command with util in it. Did not remember that it was mdutil.
How to fuzzy search for a command in an efficient manner completely in the terminal, without creating new files?
Typical ways I do it now:
To find that command I could google, not always efficient and needs internet connection and browser.
Or Tab Tab, see all commands and scroll through them until I recognize the right one.
Or output all commands to a textfile and search in that.
I guess you could do something like this:
oldIFS="$IFS"
IFS=:
for dir in $PATH; do
ls $dir/*util* 2> /dev/null
done
IFS="$oldIFS"
That would loop through all the directories in your $PATH looking for a command that contains util.
How about starting with man -k and refining, like this:
man -k util | grep -i meta
Moose::Util::MetaRole(3pm) - Apply roles to any metaclass, as well as the object base class
mdutil(1) - manage the metadata stores used by Spotlight
compgen -ca | grep util
did it the best. Instead of util you can search any part of a command.
Like gniourf_gniourf said, a better solution would be
compgen -caX '!*util*'

Using find and grep to Mimic findstr Command [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I recently switched from a Windows development environment to an Apple development environment. The move has been a challenging process, but I'm struggling with picking up UNIX based commands in terminal to makeup for the commands I used on a daily basis in Windows command prompt. Any help would greatly appreciated, explanations on a basic level of what's going on in the commands provided is a huge bonus for me as I'm trying to get a grasp on the UNIX commands, but reading the manual is like reading a foreign language to me most of the time.
Here's my question: Is there a single line command, preferably short enough to memorize, that I can execute to mimic or produce very similar output to the following Windows CMD command:
findstr /s /c:"this piece of text" *.code
I use this command on Windows often to produce a result set that shows me where the text between the quotes resides in any of the files matching the *.code pattern in any subdirectories. This can be used to check version numbers of numerous files pulled back from servers to looking for where a variable was declared in a large project. The output comes in this form:
file1.code: other text this piece of text other text
file2.code: other text this piece of text other text
file3.code: other text this piece of text other text
file4.code: other text this piece of text other text
file5.code: other text this piece of text other text
Where other text is any other text found on the same line as my search string in the given file. I have searched through the questions here and found several people using find . -name *.code to build a list of files in the subdirectories. They then use the -exec flag from the find command paired with a grep sequence to search text. I tried this in several of the mentioned ways and was failing, I think due to escape sequences or missed characters. It would be awesome if there was a way to just give the command a string in between quotes that it just searched for as is.
I tried the following and wasn't getting any results... Maybe a syntax error?
find . -exec grep -H .getItemToChange().getItemAttributes()
UPDATE
The correct code is provided below with a great explanation by John. If this helps you like it helped me give his answer an upvote!
I was hoping to find the .java file with this function call in it in a large project. It wasn't giving me any results and it also didn't have a way to filter to only *.java.
Can anyone help me out here? Explanations to your commands are GREATLY appreciated.
find . -name '*.code' -exec grep -H 'pattern' {} +
Make sure to quote '*.code' so the shell doesn't expand the * wildcard. Usually we do want the shell to do the expansion, but in this case we want the literal string *.code to be passed to find so it can do the wildcard expansion itself.
When you use -exec you need to put {} somewhere; it's the placeholder for the file names that are found. You also need either \; or + at the end of the command. It's how you signal to find where the end of -exec's arguments are (it's possible to have other actions following -exec). \; will cause grep to be run once for each file while + runs a single grep on all of the files.
find . -name '*.code' -print0 | xargs -0 grep -H 'pattern'
Another common way to do this is by chaining together find and xargs. I like using -exec better, but find+xargs works just as well. The idea here is that xargs takes file names passed in on stdin and runs the named command with those file names appended. To get a suitable list of file names passed in we pipe the output of a find command into xargs.
The -print0 option tells find to print each file it finds along with a NUL character (\0). This goes hand in hand with xargs's -0 option. Using -print0 and -0 ensures that we can handle file names with unusual characters like whitespace and quotes correctly.

Copy a whole bunch of files with their names being changed a little bit using shell script

I have a very large number of files with very similar names: row1col1.txt, row1col2.txt, row1col3.txt, row1col4.txt......
I'd like to make copies of them all and change the names to row2col1.txt, row2col2.txt,
row2col3,txt, row2col4.txt......
Using the cp command in shell script, how can I do it efficiently?
How are you going to generate the file names? How are you going to specify the substitution?
One possibility is:
ls row1col*.txt |
sed 's/row1\(.*\)/cp & row2\1/' |
sh -x
This uses ls to generate the list of names, and sed to generate a cp command for each named file, and pipes that to sh so that the copy operations occur. Don't run it to sh until you are confident that the rest is right.
If you use the program mcp contained in the packet mmv, you can do that like this:
mcp row1\* row2\#1

Resources