Locating files starting with a string for my hw - linux

I have a conundrum and I am not necessarily trying to cheat or anything I am just simply stuck. I am trying to complete an assignment for my intro to Linux class and I was hoping someone would be able to help me find the right solution. I have to:
In the same directory (where the last file was found) list all files
starting with "host" --
Use the long listing format Use a command to
find the file that shows the name of your computer
now the directory in question is /etc and I have tried several commands to no avail for both of these but especially the first one. I have tried find and locate and even attempted a grep and it just is not working as intended. I can't get files that start with "host" at most I keep getting a list of permission denied or files that end in .host and so I am not sure what I am doing wrong but I really need help so I can turn in my assignment. You don't have to tell me what the exact command should be I am just looking for some guidance again I am not trying to cheat just need help to figure it out.

and welcome to Stack Overflow! Here are some pointers.
See globbing in Linux and the * symbol.
"long listing" is an option for ls command, see ls --help. The name of your computer (or, more accurately, the name of your host) is a file in /etc/. You should see it when doing #1.

Related

ssh logon with variables

For work, I often have to log on to several different servers which are generally structured in the following:
ssh [username]#[clientName]-[product].[domainName]
The username and domain name are always the same, but the client and the product vary. On my previous computer, I was given a script which allowed me to log on to these servers by typing [product] [clientName], but I lost it when I switched PCs and now I don't know how to do that again.
Though I no doubt have been using the wrong search terms or something, I can't seem to find an answer to this question. All my searches lead me to aliases, which work but only for specific commands, not a general one where I can change the variable. I have over 100 clients and many have multiple different products, so an alias for each is impractical.
Could anyone explain how I implement this?
Bonus: It would also be useful for the command to also take me to a specific sub-directory on the server.
In the script, $0 is the name of the script, and $1 is the first argument. So the script should do:
ssh username#"$1"-"$0".domainName
Create the script once with a generic name, then use symbolic links to that for all the product names.
Put the script and all the links in a directory, and add that directory to your $PATH.

Could someone explain why cmd's 'where' does not find this file please?

Boiled down issue:
Background:
I am trying to get opencv4nodejs to install and am running into errors like opencv2/core.hpp file not found.
Digging into this, knowing full well that I have installed the appropriate files in C:\tools, and added all the required paths and refreshed my cmd.exe to reflect this, I am still getting hit with errors.
Question:
Could someone please describe why the above commands would lead to cmd.exe being unable to find the file I need?
The first dir %OPENCV_INCLUDE_DIR%opencv2\core.hpp command clearly shows that it exists within the environment of the console. Note: This variable has been appended to PATH as %OPENCV_INCLUDE_DIR%
The where opencv2\core.hpp cannot find it, much like my other program cannot find it. I am a bit of a cmd noob, so I may be missing something obvious here, but how can this be the case?
Thanks!

How to get gdb on Linux to find source file for binary cross compiled on windows

I am trying to debug an application that is cross-compiled on a Windows host for a Linux target.
The problem:
Because the initial compilation is in windows the stored source file paths in the binary is of the form C:\Users\foo\project\.... On the Linux target I have put the source files under \home\foo\project\.... By default gdb does not find the source file because of the different path.
What I have tried so far:
Use "directory" command in gdb to give an exact path for the .c source file in the target Linux system where the app is being debugged. This works but unfortunately there are literally hundreds of files so this solution is unrealistic.
Use the set substitute-path C:\\Users\\foo\\project /home/foo/project command to have gdb substitute all prefixes. Note that the \\ seems necessary such that show substitute-path registers the right string. This unfortunately does not work. My guess is that the substitute-path command does not handle ms-dos style paths.
Tried separating the debug info out into a separate .debug file (see How to generate gcc debug symbol outside the build target?) and then using debugedit to change the paths with the command debugedit --base-dir=C:\Users\foo --dest-dir=/home/foo project.debug. Unfortunately this does not work either. debugedit seems to work fine if the existing path is all UNIX/Linux like but doesn't seem to work with ms-dos style paths.
I have looked around stackoverflow and while there are similar topics I can't find anything that will help me. Would really appreciate any suggestions/help. I realize that cross compiling from Windows is a very roundabout way but can't avoid that for the moment.
Thanks
Although it's rather old question, I did encountered the same problem. I managed to resolve it but using sed on binary executable... (yeah, a 'bit' hack-ish, but did not found another way). With sed I've managed to replace symbols paths right inside the executable, the trick is that new path's length should be the same as the old one.
sed -i "s#C:/srcpath#/srcpath/.#g" ./executable
Be sure to make new path the same length, otherwise the executable will brake.
I also have this same problem. Your option 1 isn't as bad as you think because you can script creating all the 'directory' commands with something like this python code:
def get_directory_paths():
return_array = list()
unix_path = os.path.join('my','unix','path')
for root, dirs, files in os.walk(unix_path):
for dir in dirs:
full_unix_path = os.path.join(root,dir)
escaped_unix_path = re.sub("\s", "\\\\ ", full_unix_path)
return_array.insert(0, "directory " + escaped_unix_path)
return '\n'.join(return_array)
The downside is that if you have two source files with the same name in different directories, I don't think gcc can pick the right one. That worries me, but in my particular situation, I think I'm safe.
For option 2 (which I suspect would fix the aliasing condition from #1), I think the problem is that the substitutions are not ending with a "file separator" according to the linux so they aren't applied:
To avoid unexpected substitution results, a rule is applied only if the from part of the directory name ends at a directory separator. For instance, a rule substituting /usr/source into /mnt/cross will be applied to /usr/source/foo-1.0 but not to /usr/sourceware/foo-2.0. And because the substitution is applied only at the beginning of the directory name, this rule will not be applied to /root/usr/source/baz.c either." (from https://sourceware.org/gdb/current/onlinedocs/gdb/Source-Path.html#index-set-substitute_002dpath )
I haven't tried anything like your #3 and I also considered something like #dragn suggestion, but in my situation the paths are not even close to the same length, so that will be an issue.
I think I'm stuck with #1 and a script, but if anyone has other suggestions, I'm interested options :-)

how to print from a symbolic relationship?

i'm using linux and i created a symbolic link in my directory from another file. now, i want to print the records shown in that file in alphabetical order. i tried to do lp and lpr [symbolic file name] within the directory it is located, but kept getting a error with something along the following:
The program 'lpr' can be found in the following packages:
any ideas for how to do this? i feel like this is basic, but i cant find anywhere how to do this even though i have been searching.
thanks for any insight.
You have to use yum or whatever software update/install program your system has - to install lpr.
You may already have cups, which does the same things lpr does. As #janos already mentioned links are not the problem, your system software does not match your expectations about what is there.
This question really belongs on superuser.com

Getting linux terminal value from my application

I am developing a Qt application in Linux. I wanted to pass Linux commands to a terminal. That worked but now i also want to get a response from the terminal for this specific command.
For example,
ls -a
As you know this command lists the directories and files of the current working directory. I now want to pass the returned values from the ls call to my application. What is a correct way to do this?
QProcess is the qt class that will let you spawn a process and read the result. There's an example of usage for reading the result of a command on that page.
popen() , api of linux systerm , return FILE * that you can read it like a file descriptor, may help youp erhaps。
Parsing ls(1) output is dangerous -- make a few files with funny names in a directory and test it out:
touch "one file"
touch "`printf "\x0a\x0a\x0ahello\x0a world"`"
That creates two files in the current working directory. I expect your attempts to parse ls(1) output won't work. This might be alright if you're showing the results to a human, (though a human will be immensely confused if a filename includes output that looks just like ls(1) output!) but if you're trying to present something like an explorer.exe or Finder.app representation of files in the filesystem, this is horribly broken.
Instead, use opendir(3), readdir(3), and closedir(3) to read directory entries yourself. This will be safer, more portable, and (as a side benefit) slightly better performing.

Resources