Searching in the terminal


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Searching in the terminal
# 1  
Old 01-09-2011
Question Searching in the terminal

Hello,

I am fairly new to Unix, I've been running Ubuntu 10.10 on my laptop for a couple days now. I have followed a tutorial on using the terminal, and I can get around but there are some things I haven't figured out how to do yet.

For example, I have a directory which contains all my movies, series etc. I want to search through it, and find all files that are either .mkv, .wmv or .avi files, but that don't end in -sample.*whichever*.

I have got this so far
ls -lhR | grep sample.* -vi | grep .mkv

It shows all .mkv files that don't end in sample or Sample.

What I can't figure out yet:

  • how can I view .wmv or .avi files at the same time too?
  • if I want to search for -sample.* instead of sample.*, how do i make sure it doesn't see -sample as an option for grep?
  • I wanted to see the diff between using -v and -vi in the first grep command. I tried:
    diff ls -lhR | grep sample.* -vi | grep .mkv ls -lhR | grep sample.* -v | grep .mkv
    but that didn't work. Adding ( ), which was just a random guess btw, caused a syntax error. Is there any way to do this?
Thanks in advance!
# 2  
Old 01-09-2011
It's much more straight-forward if you use find instead, eg
Code:
find . -type f \( -name '*.mkv' -o -name '*.avi' -o -name '*.wmv' \) \! -name '*-sample*'

Read as: find in the current directory all files with a name of *.mkv or *.avi or *.wmv and not with *-sample* in the name.

Last edited by pludi; 01-09-2011 at 01:10 PM..
# 3  
Old 01-09-2011
Makes sense using find, but it doesn't work. Just shows a > on a new line on which I can type, and doesn´t do anything and i have to press ^D.

I can't really figure out the code you gave.

find . => find in current directory
-type f => a regular file
\( => can't really figure this out, I suppose escaping the parentheses so they are not treated as a keyword?
-name '*.mkv' => pretty straightforward
-o => or according to the Man Page
\! => I suppose it means not?
# 4  
Old 01-09-2011
If you get an right angle bracket on the prompt there's usually one to many or not enough quotes. I've made one too much in my example, corrected now. The parentheses are used for grouping, since the default operation is "and", and we want the filenames to be or'd. Escaping is needed for them and the exclamation mark, since they hold special meaning for some shells (bash included). Otherwise your explanation of the command is correct.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Print Terminal Output Exactly how it Appears in the Terminal to a New Text File

Hello All, I have a text file containing output from a command that contains lots of escape/control characters that when viewed using vi or view, looks like jibberish. But when viewed using the cat command the output is formatted properly. Is there any way to take the output from the cat... (7 Replies)
Discussion started by: mrm5102
7 Replies

2. Shell Programming and Scripting

Cannot get terminal application to launch with a graphical launcher when successful in terminal

I have been having an extremely annoying problem. For the record, I am relatively new at this. I've only been working with unix-based OS's for roughly two years, mostly Xubuntu and some Kali. I am pretty familiar with the BASH language, as that's the default shell for debian. Now, I've made this... (16 Replies)
Discussion started by: Huitzilopochtli
16 Replies

3. UNIX for Dummies Questions & Answers

A terminal controlling a terminal...

Hi all... Consider me a dummy here... I do not want any code or for anyone to show me how to do it at this time, but here is the question:- I have had this brainstorm to be able to control the AudioScope.sh program in the "Shell Scripting And Programming" forum... Is it possible, by... (4 Replies)
Discussion started by: wisecracker
4 Replies

4. UNIX for Dummies Questions & Answers

Does DOS has a terminal or pseudo terminal?

I am wondering if the DOS console works like the unix terminal? (1 Reply)
Discussion started by: vistastar
1 Replies

5. Shell Programming and Scripting

searching a file with a specified text without using conventional file searching commands

without using conventional file searching commands like find etc, is it possible to locate a file if i just know that the file that i'm searching for contains a particular text like "Hello world" or something? (5 Replies)
Discussion started by: arindamlive
5 Replies

6. UNIX for Dummies Questions & Answers

Searching

Hi guys, I have a very common issue :( im trying to work it out but I am still not used to it. my problem is searching. very often I should look for piece of string in a text file or a file itself: I want to learn some easy and professional commands to ease this routine for me. I want to be... (2 Replies)
Discussion started by: messi777
2 Replies

7. UNIX for Dummies Questions & Answers

Gnuplot wxt terminal vs x11 terminal

Hi, I installed ubuntu recently on my pc. And I installed gnuplot as well. When I first started working with gnuplot it was working . I did a plot and when I wanted to fit my data something happened and not the default terminal of gnuplot is xwt! I changed it to: set terminal x11, but it... (0 Replies)
Discussion started by: cosmologist
0 Replies

8. UNIX for Advanced & Expert Users

Pseudo-terminal will not be allocated because stdin is not a terminal.

I am trying to automate a SSH login using Keys using the following command ssh -i id_rsa usernamw@ipaddr. I am successful in doing this and i am getting the Warning Screen and I logon successfully. but when I am executing the command tail -1cf put.dat | ssh -i id_rsa username@ipaddr > get.dat ... (1 Reply)
Discussion started by: Shivdatta
1 Replies

9. Shell Programming and Scripting

searching searching

Guys Im checking some of my files for errors. I want to be able to find text and make sure it's located on the right place. Example Chapter 1 TEXT LKJ TEXT 12Y more and more text Chapter 2 TEXT 34G TEXT HHG more and more text Chapter 3 TEXT FG45 TEXT 11w more and more text ... (3 Replies)
Discussion started by: tony3101
3 Replies

10. UNIX for Advanced & Expert Users

connecting to unix through hyper terminal - as a dumb terminal

I just changed from windows NT to XP and I am no longer able to connect to my unix system. I used to use hyper terminal -- which acts as dumb terminal to my main frame unix system. I think one of the options used to be "direct to comX". This option isn't listed now. I use a serial port and the... (2 Replies)
Discussion started by: michelle
2 Replies
Login or Register to Ask a Question