Find by contentĪ find command doesn't have to perform just one task. Notice that I don't use 2>/dev/null in this instance because I'm only listing the contents of a file path within my home directory, so I don't anticipate permission errors. The ls -R command lists the contents of a directory recursively, meaning that it doesn't just list the target you provide for it, but also descends into every subdirectory within that target (and every subdirectory in each subdirectory, and so on.) The find command has that function too, by way of the -ls option: $ find ~/Documents -lsģ554235 0 drwxr-xr-x 05:36 /home/seth/Documents/ģ554224 0 -rw-rw-r- 05:36 /home/seth/Documents/Fooģ766411 0 -rw-rw-r- 05:36 /home/seth/Documents/Foo/foo.txtģ766416 0 -rw-rw-r- 05:36 /home/seth/Documents/Foo/foobar.txt If you can't remember the exact name of the file, or you're not sure whether you capitalized any characters, you can do a partial and case-insensitive search like this: $ find / -iname "*foo*txt" 2>/dev/null Use 2>/dev/null to silence permission errors (or use sudo to gain all permissions). When you know the name of a file but can't remember where you saved it, use find to search your home directory. Whether you're on your own computer or trying to support someone on an unfamiliar system, here are 10 ways find can help you locate important data. As its name implies, find helps you find things, and not just by filename. The good news is that tcsh autocompletes your files, and quotes them according to the correct archanesyntax.The find command is one of the most useful Linux commands, especially when you're faced with the hundreds and thousands of files and folders on a modern computer. Many a program failed utterly when a text field had a quote mark or a leading pace, etc. I even have a database test item in all databases I made, called the "O'Reilly" test. Nowadays, we need to support all file names, even "O'Reilly's Army.txt". Also, it's an old habit from the days when you only got 8 chars to say it. Most techies I've worked with use the 3-fingers-on-one-hand-2-on-the-other method, and they like to use short variable name, don't like to comment, and in general cannot be counted on to help with the user doc. Maybe because, unlike most programmers, I can type with ten figures at a normal writing speed - few people need more than 40 words per minute to type as fast as they can compose. I'm a big fan of English language file names, that is, not something like RSFunc97Stat.txt. It doesn't crap out as soon as it hits the space. Now if your file name is /home/he/Documents/00 - Writing/02 The Rapture of the Maiden/0 - Text/25th/Rapture, pt 1-4, ch 01-20 old.txt, I use the C-shell, as I was a berkeley/Sun user at the Lab, but the same ideas apply in bash. To get it to work on anyįile system, EG NTFS, you need to quote the $PWD. Garbage if you have actual file names, not Unix-style file The problem is $PWD, which results in useless Is there a faster way to do what I am trying to do than to use find? However, it is a ton to type, and it is certainly not as fast as using ls with grep. This will give me a nice format (It also includes the user, group, size, and last date of access, which are helpful). If I just use find without ls or grep, then it goes faster, but it is a bunch to type: find $PWD/ -type f -name file.name -printf '%M %u %g %s\t%a\t%p\r\n' I can use ls integrated with find and grep to get the output in exactly the format that I want, and I could use something like this: ls -ault `find $PWD/ -type f` | grep file.nameīut this is extremely slow, I'm guessing because two commands are actually running. I would prefer to use ls because it is the fastest, and I would type: ls -alR $PWD/īut this doesn't show the file's path, so if I grep'ed the output, then I would see file permissions, but not the directory from which it originated. I want to do this so that I can grep out what I want, so that when I run the command, I can get just the matching files, their permissions, and their full paths, like: | grep file.name I have done a bit of searching online, and I am trying to find a way to recursively list all files with their absolute path and with their permissions.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |