Reply
Thread Tools
Posts: 2,802 | Thanked: 4,491 times | Joined on Nov 2007
#11
What's wrong with find /home -name "xou*"?
 
Posts: 1,751 | Thanked: 844 times | Joined on Feb 2010 @ Sweden
#12
You should also add "ls", "cd" and "mv" to the command list.

ls = view inside an directory (i.e. ls /home/user)
ls -a = view all files, even the hidden ones
ls -l = view it like a list

cd = go up and down in the file system (i.e. cd /home/user/)
cd .. = go down one step
cd ~ = go to home directory

mv = move or rename a file or directory (i.e. mv /home/file.txt /home/user/file.txt)
__________________
You like what i do? Donate!

Make your desktop look awesome - use the AwOken Theme with the AwOken Icon Theme.

Add me on twitter @almehdin
Visit the swedish maemo/meego community forums
 

The Following 4 Users Say Thank You to AlMehdi For This Useful Post:
jukzh's Avatar
Posts: 122 | Thanked: 22 times | Joined on Jun 2010 @ China
#13
Originally Posted by AlMehdi View Post
"grep" is used to find a string from an output of a command.. when you only write "find /" it will output all the files on the n900. Which is not that useful. But if you add grep to find so it becomes "find / | grep <name>". Then "find" will only output the words that equals the one in grep.
Code:
find <path to look in> | grep <word to look for>
If you know the file you are looking for is in "/home" and that it starts with "xou" you could write:
Code:
find /home/ | grep "xou"
It will then give an out put on all the files and directories with "xou" in it. In this case it would find all the cases of xournal in /home/.
Note, it's not exactly the same thing.
Code:
/home/user # time find . -name "*.py" | wc
real	0m 0.63s
user	0m 0.11s
sys	0m 0.46s
       95        95      5352
/home/user # time find . | grep "*.py" | wc 
real	0m 0.87s
user	0m 0.12sa
sys	0m 0.45s
        0         0         0
/home/user #
 

The Following User Says Thank You to jukzh For This Useful Post:
Posts: 1,751 | Thanked: 844 times | Joined on Feb 2010 @ Sweden
#14
Originally Posted by lma View Post
What's wrong with find /home -name "xou*"?
It would work too.. but grep is good to understand
__________________
You like what i do? Donate!

Make your desktop look awesome - use the AwOken Theme with the AwOken Icon Theme.

Add me on twitter @almehdin
Visit the swedish maemo/meego community forums
 
jukzh's Avatar
Posts: 122 | Thanked: 22 times | Joined on Jun 2010 @ China
#15
Quick lookup in the manual and I found the way:
Code:
/home/user # time find . | grep ".*\.py$" | wc  
real	0m 0.91s
user	0m 0.12s
sys	0m 0.45s
       95        95      5352
/home/user # time find . -name "*.py" | wc  
real	0m 0.64s
user	0m 0.10s
sys	0m 0.46s
       95        95      5352
/home/user #
 
jukzh's Avatar
Posts: 122 | Thanked: 22 times | Joined on Jun 2010 @ China
#16
Originally Posted by Rob1n View Post
As none of the manual pages are installed on the N900, it really doesn't help.
I think porting man, and puting up busybox's manpage, woudn't be a big deal, just no one really need it.
 
Posts: 1,751 | Thanked: 844 times | Joined on Feb 2010 @ Sweden
#17
Originally Posted by jukzh View Post
Quick lookup in the manual and I found the way:
Code:
/home/user # time find . | grep ".*\.py$" | wc  
real	0m 0.91s
user	0m 0.12s
sys	0m 0.45s
       95        95      5352
/home/user # time find . -name "*.py" | wc  
real	0m 0.64s
user	0m 0.10s
sys	0m 0.46s
       95        95      5352
/home/user #
remember.. this should be noob friendly. "find -name" is normaly better in a script.. but "grep" is useful in more instances than just find. Both will do the job to locate the file. Also using ".", "*" or for that matter "?" is not needed for a noob.
__________________
You like what i do? Donate!

Make your desktop look awesome - use the AwOken Theme with the AwOken Icon Theme.

Add me on twitter @almehdin
Visit the swedish maemo/meego community forums
 
Posts: 3,617 | Thanked: 2,412 times | Joined on Nov 2009 @ Cambridge, UK
#18
Originally Posted by jukzh View Post
Note, it's not exactly the same thing.
Code:
/home/user # time find . -name "*.py" | wc
real	0m 0.63s
user	0m 0.11s
sys	0m 0.46s
       95        95      5352
/home/user # time find . | grep "*.py" | wc 
real	0m 0.87s
user	0m 0.12sa
sys	0m 0.45s
        0         0         0
/home/user #
The find on it's own is obviously more efficient, which is why the times are lower. You don't want to use "*.py" in the grep though, as grep uses regular expressions and not globbing, so "\.py$" will get you the same results (the "\" is needed to escape the ".", which represents a single-character wildcard, and the "$" is needed to anchor the search to the end of the name, otherwise any ".py" in the middle of names will be picked up as well).
 
jukzh's Avatar
Posts: 122 | Thanked: 22 times | Joined on Jun 2010 @ China
#19
Originally Posted by AlMehdi View Post
remember.. this should be noob friendly. "find -name" is normaly better in a script.. but "grep" is useful in more instances than just find. Both will do the job to locate the file. Also using ".", "*" or for that matter "?" is not needed for a noob.
I heard of noobs, hwo whant's a dog to search filesystem by voice command.
 
Posts: 2,802 | Thanked: 4,491 times | Joined on Nov 2007
#20
Originally Posted by AlMehdi View Post
remember.. this should be noob friendly. "find -name" is normaly better in a script
I think -name and glob patterns should be much easier to understand and remember for a beginner than grep and regular expressions.

but "grep" is useful in more instances than just find.
True. If the point was to demonstrate grep fair enough, though I think one can come up with better examples using something other than find (eg ps, df, various /proc files etc).
 

The Following User Says Thank You to lma For This Useful Post:
Reply


 
Forum Jump


All times are GMT. The time now is 00:46.