I have to find a lot of information in the esxi host for configuration.
When I run commands like:
# grep -i "^Banner" /etc/ssh/sshd_config
I get no results but if I execute:
cat /etc/ssh/sshd_config
I can see in file the string "Banner /etc/issue".
Why does grep not return the information requested? What am I missing?
I would experiment with the searched file a bit.
Please try the following command:
cat /etc/ssh/sshd_config | grep -i '^Banner'
Or if it fails just
cat /etc/ssh/sshd_config | grep -i Banner
(the word 'banner' anywhere).
Further please try to copy the file to your local repository
and try examining with vi sshd_config to test if there aren't any non-visible characters in the file making the search insufficient.
It could be the hidden characters in the file, or that the searched string isn't located at start of the line (or combination of both.)
Related
I have a server which runs on centos 7. I need to find a file containing 0774386850 so that I can replace with another string. Kindly give me a Linux command to give me that file
By using grep command, you can achieve what you expected
grep -rlnw '/path/to/somewhere/' -e '0774386850'
-r or -R is recursive,
-n is line number, and
-w stands for match the whole word.
-l (lower-case L) file name of matching files.
grep -r "0774386850 " /path/to/dir
You can use either grep/fgrep or find to achieve your goal.
I have outputted the IPTables log to another log file,
/var/log/iptableftp.log
Within that file it displays the full iptables log line, Is there a way to search the /var/log/iptableftp.log file I previously made and search for SRC= and removing everything thats before and after and just leaving the IP address behind?
you should have a look at sed
cat iptables.log | sed -e 's/SRC=([0-9\.]+).*/$1/g'
sed uses regex in to form: s/exp_to_find/replace_with/g
Edited to fix arg in replace expression, thx to Ed Morton
I searched the Internet, but maybe I used the wrong keyword, but I couldn't find the syntax to my very simple problem below:
How do I redirect a file as command line arguments to the Linux command "touch"? I want to create a file with "touch abc.txt", but the filename should come from the filename "file.txt" which contains "abc.txt", not manually typed-in.
[root#machine ~]# touch < file.txt
touch: missing file operand
Try `touch --help' for more information.
[root#machine ~]# cat file.txt
abc.txt
Try
$ touch $(< file.txt)
to expand the content of file.txt and give it as argument to touch
Alternatively, if you have multiple filenames stored in a file, you could use xargs, e.g.,
xargs touch <file.txt
(It would work for just one, but is more flexible than a simple "echo").
I am a windows user having basic idea about LINUX and i encountered this command:
cat countryInfo.txt | grep -v "^#" >countryInfo-n.txt
After some research i found that cat is for concatenation and grep is for regular exp search (don't know if i am right) but what will the above command result in (since both are combined together) ?
Thanks in Advance.
EDIT: I am asking this as i dont have linux installed. Else, i could test it.
Short answer: it removes all lines starting with a # and stores the result in countryInfo-n.txt.
Long explanation:
cat countryInfo.txt reads the file countryInfo.txt and streams its content to standard output.
| connects the output of the left command with the input of the right command (so the right command can read what the left command prints).
grep -v "^#" returns all lines that do not (-v) match the regex ^# (which means: line starts with #).
Finally, >countryInfo-n.txt stores the output of grep into the specified file.
It will remove all lines starting with # and put the output in countryInfo-n.txt
This command would result in removing lines starting with # from the file countryInfo.txt and place the output in the file countryInfo-n.txt.
This command could also have been written as
grep -v "^#" countryInfo.txt > countryInfo-n.txt
See Useless Use of Cat.
I have a proxy config file which has the following line:
Allow 212.21.3.44
I'd like to replace that IP address portion with my new IP address when it changes. It would probably be easier to just use the line number when searching for it &ndash I don't think that config file will change at all other than that particular setting.
How can I do it from the command line with something like like Perl, sed, etc.?
If you want to use sed to change a specific line number, you could use:
sed -i '<line number> s/Allow .*$/Allow <new ip>/g' <filename>
sed -i 's/[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/my.new.ip.here/' file.txt
The -i flag will change the file in place (depends on your distro/flavor of *nix - works on Ubuntu for me).
in case line number does change
sed -i '/Allow/s/Allow .*$/Allow <new ip>/' <filename>