How to find a file in linux from terminal window - linux

Actually i want to search a file which is located some where in the system. Im having debian linux and i need to search using terminal.

Use the find command, for example
find . -name "foo.*"
to search for all files named foo.* in the current directory.
Here is the manual page documentation.

Related

Location of .bashrc for "Bash on Ubuntu on Windows" in Windows 10

Microsoft just introduced a Linux subsystem in its Windows 10 Anniversary Edition. The installation is pretty straight forward, but I could not locate bash files on Windows.
How does it work? What does ~ refer to in Windows? Where to find .bashrc?
Since the Windows 10 Fall Creators Update, the location changed to:
C:\Users\USERNAME\AppData\Local\Packages\{DIST}\LocalState\rootfs\home\{LINUXUSER}\
Where:
{DIST} is equal to CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc
{LINUXUSER} is the user for which you are looking for the .bashrc file
Just for anyone wondering that came here from Google.
Sorry for the misunderstanding, I check on google and it will be at C:\Users\USERNAME\AppData\Local\Lxss\home\USERNAME .
I tried and it works, in the cmd just type cd\ && dir *bashrc* /s it will locate the file, and in my case i see the line C:\Users\USERNAME\AppData\Local\Lxss\home\USERNAME but when I want to navigate it with the window browser it doesn't work, but if you copy paste it, it works :-)
I found it here.
Considering that you need to know where a file is located you can use the find command.
The syntax of the command is find {search-path} {file-names-to-search} {action-to-take}by default the action to take is printing the file name.
So if you are finding .bashrc file you can use find / -name .bashrc the bash will return you /home/yourusername/.bashrc
Also, if you want to access to your home directory you can use cd ~
Hope my answer will be helpful :-)
just type
vi ~/.bashrc
and that should put you into the file where ever it is.
You can navigate there simply by doing cd ~
List all files with ls -a and you should be able to see it.
~ means that is user home folder, way like /home/%username%/
you can list files like ls -al and see .bashrc file.
Right now on WSL 2 you can find it under /home/{user_name} and the file is hidden.
You can access it from Ubuntu console by {text_editor} .bashrc
If you want to edit that in Windows just type in ubuntu console explorer.exe . and it opens the current folder and shows all hidden files.
It's weird but works fine.
Other answers doesn't work for me using WSL 2.
The LocalState folder contains a virtual disk so rootfs does not exist,
and AppData\Local folder does not have the Lxss folder.
The solution for me is surprisingly simple:
wsl -u root
This will allow you to get into wsl as root.
From here, you have access to the whole linux.
Fix the .bashrc or anything you want.
Don't screw up the root user. :)
I find my .bashrc file in:
/home/your_user_name
you can run cd /home/your_user_name or cd ~ should work as well
If you previously installed git bash for window, you may also find .bashrc file in your window user profile folder. In Linux subsystem, you may local the file under /mnt/c/Users/your_window_user_name/.bashrc However, modifying that file only works for git bash in window but not for the shell terminal of the Linux subsystem.
Note: my installation of the Ubuntu is 20.04 LTS straight from window store.

Find command not working as expected in centOS

I am using CentOS Linux release 7.0.1406 on virtual box. I am trying to find the files using find command.
this find command is not giving any response:
find . -name "orm.properties"
My current working directory is /eserver6. File orm.properties is present in /eserver6/share/system/config/cluster, but find command is not able to find the file.
I have tried other combinations like
find . -name "orm.*"
find . -name 'orm*'
this is finding few files staring with orm but not all the files present inside the current working directory.
The command line looks correct and it should find the file. Some reasons why it might fail:
You don't have permission to enter one of the folders in the path to /eserver6/share/system/config/cluster.
You made a typo
The file system is remote and the remote file system behaves oddly
There is a simlink somewhere in the path. By default, find doesn't follow symlinks to avoid recursive loops. Use find /eserver6 -L ... to tell find to look at the target of the link and follow it if it's a folder.
The command
find /eserver6 -name "orm.properties"
should definitely find the file, no matter where you are. If it doesn't, look at -D debugoptions in the manpage. You probably want -D stat to see at which files find looks and what it sees.
If your user have entry into sudoers file then its ok and you can run
sudo find / -name "orm.properties"
or else ask your admin to give an entry in sudoers file of your user and run the same command then it will work.

how to find path from where current binary running?

After somewhere searching finally not getting what i want.
I am working on some embedded board with linux system. And many users access it by telnet.So each user suppose copy some binary somewhere and executed like ./binary.So i can see this process running by simply ps command but from where it's running i don't know.
somewhere found that, use which command but as per my understanding(if i am not wrong) which command find only path of that binary whether it's currently executing or not.
And what if multiple users copied same binary in different path?
Also looked another solution use readlink but limited busybox binary supported in my target board. So readlink is not there.
One another solution like
file /proc/"proess id"/exe but here file command not present because of custome linux in my board which contain only limited functionality and binary.
So any other solution is there?
Try ls -l /proc/"proess id"/exe. ls utility from GNU coreutils shows links with -l option, but I don't have exact information about ls from busybox.

How to find a particular folder through terminal in fedora

Presently i am using linux(Fedora 15) and i ma trying to search a folder in the entire file system like with below command
find / -name "apache-tomcat*"
The execution of the above command is taking more and more time that a user cant wait and results are some thing like below
[root#user fedrik]# find / -name "apache-tomcat*"
find: `/proc/6236/task/6236/ns/net': No such file or directory
find: `/proc/6236/task/6236/ns/uts': No such file or directory
find: `/proc/6236/task/6236/ns/ipc': No such file or directory
find: `/proc/6236/ns/net': No such file or directory
find: `/proc/6236/ns/uts': No such file or directory
find: `/proc/6236/ns/ipc': No such file or directory
find: `/proc/6462/task/6462/ns/net': No such file or directory
.................
.................
But as i have mentioned it is taking long time to process and sometimes it is been strucked, so can anyone please let me know on how to search a particular folder by name with a command from linux terminal that will be very fast and should search in the entire file system like above i used '/'
Edit
Actually my intention is to search the folder something like apache-tomcat-7.0.37 in the entire filesystem,
for example there may be many folders like apache-tomcat-6.0.45, apache-tomcat-5.1.7, apache-tomcat-5.0.37........... on different locations on filesystem
So as we can observe only the last part(which is numerical part) is changing and the entire folder name is same, so is there a way to search for these kind of folders irrespective of the last numerical part , like by using regular expression or somethingl ike that.
Finally my intention is to find the folders of the format apache-tomcat-xxxxxxx on the entire file system, because if we search for just apache-tomcat we will get hundreds of results and even thousands too sometimes which is difficult to analyze and search from them
?
Try this:
locate apache-tomcat
It uses a database (updated by the hilariously-named updatedb, which you can run with sudo updatedb to refresh the search index).
locate apache-tomcat | grep -E '^apache-tomcat-[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+$'
or just use [0-9] instead of [[:digit:]]. That's probably more readable. Or
locate apache-tomcat | perl -ne 'print if /^apache-tomcat-\d+\.\d+\.\d+$/'
Whatever you do, you definitely want to use locate instead of find, as it will be much faster.

Newbie: linux command

Two questions to ask:
1. I am using scp command to copy a file from a remote server, I am wondering how can I specify the place where to paste the copied file on my local computer?
for example, if I wanna copy a test.txt file from a remote server and paste it on my local computer under /home/myname/tmp/ what is the proper command?
is it
scp SERVER_ADDRESS /home/myname/tmp/
2. If I want to search a file whose name contain text of "test" , what is the command I should use? I mean search for any file with name test , ('_' is a wildcard)
--------------------------- update ------------------------
what is the difference between "find" and "grep"?
1:
scp SERVER_ADDRESS:/path/to/remote/file.txt /path/to/local/file.txt
2:
find . -name "*test*"
This will search for files/directories containing "test" anywhere in the filename. The search will start from the current directory . To search in another path, use find /path/ -name "*test*". If you only want to search in files, that is, exclude directories, then add -type f before the -name option.
First man scp is your friend (as are all man pages in general).
Yes: in full, that'd be like scp server:/path/to/file.txt /local/path/.
Your main options here are:
locate test (if you have locate installed and its database is up to date)
-or-
find /path/name -name '*test*' to find any named files inside the /path/name directory and all its children.

Resources