Sponsored Content
Full Discussion: Command comparisons
Top Forums UNIX for Dummies Questions & Answers Command comparisons Post 302535577 by methyl on Friday 1st of July 2011 06:44:15 AM
Old 07-01-2011
Java

There are some funny quote characters here like it has come from a Windows editor. Also the "-name" parameter is missing.
Quote:
find . “*.log” | xargs grep ERROR
find . “*.log” –exec grep ERROR ‘{}’ \;
You probably mean:
Code:
find . -type f -name '*.log' | xargs grep "ERROR"
find . -type f -name '*.log' -exec grep "ERROR" {} \;

On many modern versions of "find" the "+" syntax is actually fastest of all:
Code:
find . -type f -name '*.log' -exec grep "ERROR" \+


Addendum:
Quote:
ls * | wc –w => this gives you the number of files in the current directory including all subdirectories
Sort of true. It does however exclude filenames starting with a period (e.g. .profile). It also sorts each directory to alphabetical order which is a bit of a waste if all you wanted to do was count them. It also gives an incorrect count if any filename contains a space character because you are counting "words". You also count directory files but because "including all subdirectories" is ambiguous it's hard to tell whether this is intentional.

Code:
This is a more efficient and accurate way to count every type of file (including directory files)
find . -print |wc -l
Or if your "find" allows the syntax:
find . | wc -l

Or if you just want to count all files:
find . -type f | wc -l


Last edited by methyl; 07-01-2011 at 08:10 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to automate file comparisons

Hi, I need a script that loops through all the files two directories passed to it via parameter, and if two files have the same name, do a cmp comparison on the files. If the files are different, output the specifics returned by cmp. What's the best way to go about writing this, as I am a... (6 Replies)
Discussion started by: herman404
6 Replies

2. UNIX for Dummies Questions & Answers

Can grep do numerical comparisons?

Say for example I have a list of numbers.. 5 10 13 48 1 could I use grep to show only those numbers that are above 10? For various reasons I can only use grep... not awk or sed etc. (7 Replies)
Discussion started by: Uss_Defiant
7 Replies

3. Shell Programming and Scripting

numeric range comparisons

I have two files.And a sort of matrix analysis. Both files have a string followed by two numbers: File 1: A 2 7 B 3 11 C 5 10 ...... File 2: X 1 10 Y 3 5 Z 5 9 What I'd like to do is for each set of numbers in the second file indicate if the first or second number (or both) in... (7 Replies)
Discussion started by: dcfargo
7 Replies

4. Shell Programming and Scripting

Best practice for bracket comparisons?

So, I have no formal higher education in programming at all and am self taught. I am now wondering what would be considered best practices? Like should I hard code a variable, then compare it to what I want to know or achieve, or should I just put the commands with in the brackets? Example, a... (5 Replies)
Discussion started by: tlarkin
5 Replies

5. Shell Programming and Scripting

String comparisons

Can someone please tell me what is wrong with this stings comparison? #!/bin/sh #set -xv set -u VAR=$(ping -c 5 -w 10 google.com | grep icmp_req=5 | awk '{print $6}') echo I like cookies echo $VAR if "$VAR" == 'icmp_req=5' then echo You Rock else echo You Stink fiThis is the error.... (6 Replies)
Discussion started by: cokedude
6 Replies

6. UNIX for Dummies Questions & Answers

Date comparisons

Hi, I want to perform a simple date comparisons, i.e. select all files modified after a certain date (say 12-feb-2011) I do not have the option of creating a file and using find's -newer option. Any simple way to do this? I can do this by reading the stat command's output and comparing... (10 Replies)
Discussion started by: jawsnnn
10 Replies

7. UNIX for Dummies Questions & Answers

File and if statement comparisons

I'd love to get help on this one please. Ok so say I have a file called README with lines such as this: index:index.html required:file1.1:file2.1:file3.1 I'm having trouble with writing an if statement that compares the items in a list with a file inside README, what I imagine in my head... (7 Replies)
Discussion started by: mistsong1
7 Replies

8. Shell Programming and Scripting

Pair wise comparisons

Hi, I have 25 groups and I need to perform all possible pairwise compariosns between them using the formula n(n-1)/2. SO in my case it will be 25(25-1)/2 which is equal to 300 comparisons. my 25 groups are FG1 FG2 FG3 FG4 FG5 NT5E CD44 CD44 CD44 AXL ADAM19 CCDC80 L1CAM L1CAM CD44... (1 Reply)
Discussion started by: Diya123
1 Replies

9. Shell Programming and Scripting

File comparisons

Hi all, I want to compare two files based on column value Kindly help me a.txt 123,ABCD 456,DEF 789,SDF b.txt 123,KJI 456,LMN 321,MJK 678,KOL Output file should be like Common on both files c.txt 123,ABCD,KJI (8 Replies)
Discussion started by: aaysa123
8 Replies

10. Shell Programming and Scripting

String regex comparisons

Here is the sample code: str1="abccccc" str2="abc?" if ]; then echo "same string" else echo "different string" fi Given that ? implies 0 or 1 match of preceding character, I was expecting the output to be "different string", but I am seeing "same string". Am I not using the... (3 Replies)
Discussion started by: Rameshck
3 Replies
dragbox(1)																dragbox(1)

NAME
dragbox - Command line drag-and-drop tool for Gnome. SYNOPSIS
dragbox [-naxpu0] [--get | --list] [--name id] [item ...] DESCRIPTION
Dragbox is a tool for connecting the command line with the desktop environment. It summons a drag handle in a window when you are managing files or text in the shell, connecting the different workspaces -- desktop and command line. Dragbox can take items on the command line or from a pipe and put on its shelf. The inverse is also possible: dragged-to items can be out- put to the shell. It is possible to have more than one instance running, and put items on or get items from any of them. Right-click in the window to open a context menu or access the preferences window. Clicking an item copies it to the clipboard (files can be opened as an option). OPTIONS
-f, --file file Add file to the dragbox and report an error if it does not exist. -t, --text "snippet" Add snippet to the dragbox as text. This is needed explicitly if you want to treat an existing path as text. -n, --no-fork Do not fork after launch. This implies --write-on-exit. The program will not be able to communicate with other instances of itself. --get Query a running instance for its contents, output and exit. This respects settings affecting output format. Note that --get takes no arguments; use --name to specify which shelf to get. -m, --name name Use shelf identifier name. This can be used to have multiple dragboxes (shelves) available. --list List running instances. --window-title title Set window title to title. This will only have effect when the window is first created. Output settings -a, --write-async Output dragged-to items to standard output as they are received. -x, --write-on-exit Output contents of the dragbox to standard output at exit. -p, --paths Use absolute paths when outputing files. This is default. -u, --uris Use URIs when outputing files. -0, --null-terminate Separate dragged-in items' output with , not . This is useful together with xargs -0 The following are generic options -h, --help Displays usage information and exits. -v, --version Displays version information and exits. EXAMPLES
dragbox . file1.txt Adds the current directory and file1.txt to the currently running dragbox, or creates a new one. If file1.txt does not exist, its name is added as text. dragbox -t "Dragbox is cool" Adds a text snippet to the currently running dragbox, or creates a new one. dragbox --get -0 | xargs -0 tar cfz backup.tar.gz Get current items and pipe to xargs to create a tarball. Note that this simple command will have problems if contents include text items. dragbox --name remember . Put the current directory on a shelf called "remember" TIPS AND TRICKS
Dragging in gnome works very well, but there are some hidden tricks that can make some things easier. Pressing modifier keys can switch between different types of drags; dragging a file to nautilus normally copies it, but you can hold shift to move it, or shift-ctrl to make a symlink. You can drag from any window without activating it by holding the altgr or super key when you drag. This is often very useful. You can bring up a minimized or obscured window while dragging by hovering momentarily over it's button in the window list (in the gnome- panel) Just like minimized windows, you can switch workspaces while dragging if you hover over the workspaces switcher for a short while. If you selected something in a window and focus another window, it looks like the selection disappeared. In many cases it's still there, you can try to drag it without focusing the window (see above) Type escape while dragging to cancel the drag ACCESSING DRAGBOX
Dragbox needs an X session to run and display its shelves. However, to access dragbox shelves from non-graphical sessions, all you need is to make sure dragbox knows which X session to connect to. It might be enough to define the DISPLAY variable. AUTHOR
dragbox was written by Ulrik Sverdrup <ulrik.sverdrup@gmail.com> dragbox(1)
All times are GMT -4. The time now is 04:20 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy