LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Find a file (https://www.linuxquestions.org/questions/linux-newbie-8/find-a-file-516548/)

Ejdaha 01-05-2007 06:15 AM

Find a file
 
Hi all
I'm newbie in Linux. I want to find some file on whole Linux file system.

And I want to export some environment variables every time I connect to session
Where I must put this code?

Thanks...

pwc101 01-05-2007 06:27 AM

Can't really help with the environment variables, but to find a file, open up a terminal and type:
Code:

find / -iname file_you_want_to_find
the first bit calls find (the program) the / indicates the root directory, and will search all folders therein, the third part (-iname) tells find to search for files by name, and to ignore the case of the search string/filename. Finally, the last part (file_you_want_to_find) is what you're searching for :)

Hope this helps.

tshrinivasan 01-05-2007 06:29 AM

Hi Ejdaha,

Welcome to the real world.

"find" itself is the command
man find
will tell you more

ex
#find / -name "test.txt"

there are more options in find.
as finding by name,regular expressions, size, date, file type etc.
man find will help u more.

for environment variables, put them in /etc/profile as root.
This is the common file for all users.

~/.bash_profile is for particular users.

Ejdaha 01-05-2007 06:42 AM

Thank you very very much

Bruce Hill 01-05-2007 06:43 AM

find / -iname '*wordperfect*' 2>/dev/null

substitute your file for wordperfect

Broder 01-05-2007 07:32 AM

I also like locate:
locate filename

pwc101 01-05-2007 07:46 AM

Quote:

Originally Posted by Feelda
I also like locate:
locate filename

If you use locate, you may need to first run updatedb as root.

yuubouna 01-14-2007 08:34 PM

hello,
what do you mean [/dev/null] ?

yuubouna

matthewg42 01-14-2007 08:56 PM

/dev/null is a special file which sounds silly, but turns out to be very useful. If you write into /dev/null, nothing happens at all - the data just falls though a wormhole in space and time, forever to vanish from the universe.

This seems pretty useless, but it turns out a lot of the time, the output of programs you run on the command line splurge out all sorts of useless information which you might want to ignore. You can do this by re-directing the output to /dev/null.

For example (the $ denotes commands you enter in the shell, other lines what is output by those commands):
Code:

$ echo "This is annoying output"
This is annoying output
$ echo "This is annoying too" > /dev/null

Most programs produce output on two file handles, standard output and standard error. Standard output is usually used for legitimate output of a program, and standard error for error messages and debugging. For example if you execute "ls", the regular output is on standard output, and the errors on standard error.

By default both of these print to your terminal window. For example:
Code:

$ ls -d /var /etc /notexisting /alsonotexisting
ls: /notexisting: No such file or directory
ls: /alsonotexisting: No such file or directory
/etc  /var

What we see here is the error messages AND the proper output. If you're using bash, or another borne style shell (typical for modern Linuxes), you can re-direct these two outputs separately. For example, we can say that we don't want to see the proper output by redirecting it to /dev/null. This is done with the > symbol:
Code:

$ ls -d /var /etc /notexisting /alsonotexisting > /dev/null
ls: /notexisting: No such file or directory
ls: /alsonotexisting: No such file or directory

(note the lack of the line showing the /etc and /var directories).

Similarly, we can choose to re-direct the standard error with 2>
Code:

$ ls -d /var /etc /notexisting /alsonotexisting 2> /dev/null
/etc  /var

Just as a useful note: Each file handle which a program has open has a number. Standard output has the number 1, standard error has the number 2. ">" is in fact an abbreviation of "1>". There is one other file handle open for most processes - number 0 which is standard input. This is typically connected to some file from which a program reads, the user's keyboard (yes, you can type input directly into most programs), or the previous command in a pipeline.

natureday 01-14-2007 10:20 PM

You just need to find the root folder:)
Anna

yuubouna 01-14-2007 11:37 PM

thanks a many matthewg42!
how about this one?

iconv -f Shift_JIS -t UTF-8 ${basename} > /dev/null/

does this convert encoding from original FileName to the same FileName?

Pardon me, for not being related to this thread..
yuubouna(^_-)-☆

matthewg42 01-15-2007 12:12 AM

Quote:

iconv -f Shift_JIS -t UTF-8 ${basename} > /dev/null/

does this convert encoding from original FileName to the same FileName?
You should remove the trailing / from /dev/null - it is not proper and will lead to an error. Assuming you do, this is what will happen:

It will convert from the Shift_JIS character encoding to UTF-8 encoding. It will read input from the file whose name is stored in the variable "basename". Since no output file is specified with the -o option, output will be written to standard output, which is then re-directed to /dev/null (i.e. it is discarded). The original file will not be modified.

Note that iconv, in common with many of the Unix command line programs, iconv does not respond well to outputting to the file which is also the input file - doing this will just leave you with an empty file. Instead you should re-direct your output to another filename - perhaps using the same name as the original with a .utf8 suffix, as shown below. If you wish, you may then move the new file "over" the original, erasing it.

In this example I do not use a variable to store the name of the input file - it is simply called "my_file", and is assumed to contain valid Shift_JIS encoded text:
Code:

iconv -f Shift_JIS -t UTF-8 my_file > my_file.utf8
If you wish to replace the original file with the new one, you just need to mv it. This is like rename. Be cautious though - mv will overwrite the original without prompting you "are you sure" (unless you have mv aliases to include the -i option):
Code:

mv my_file.utf8 my_file
Re-direction is also harsh. By default it will replace files without asking you. There is a way to make the shell more cautious about "clobbering" files with re-direction, but this is seldom enabled. Be careful.

To a command-line newcomer, it's a little scary that commands will silently overwrite files without prompting you "are you sure" at every turn. I suppose the rationale is that if you can be bothered to type a command, you should know what you want. This becomes a benefit to productivity once you know what you're doing despite the initial hesitation it sometimes causes. It also means users don't get conditioned into just replying "yes" to every prompt without reading them (enable macros in this word document anyone?).


All times are GMT -5. The time now is 06:44 PM.