Sunday, August 20, 2017

Find system files and place files in correct location

We will spend a lot of time on the find,we have an example of the find,
Which allows me to find,find files with particular permissions and place them somewhere else.
We can do,everything else and find out throughout the course.
Using the locate command is the best thing.(this uses the database).
The update db command,will constantly in the system,
The update db command,will run periodically,system and we just do the update.
It will force the database,to scan the filesystem and update the database cache,whenever your system boots,it is apart.

Whenever the updatedb command is updated,the locate command to locate.(this is to locate the files and strings).return a path

and a matching value.
For example,if you want to locate the who command:

[ root@tcox ~]#  updatedb


[ root@tcox ~]#  locate who
/etc/selinux/targeted/modules/active/modules/rwho.pp
/usr/bin/who
/usr/bin/whoami/
/usr/share/man/man1/who.1.gz
/usr/share/man/man1/whoami.1.gz
/usr/share/slinux/devel/include/rwho/pp.bz2


we can ignore case here.
We can do,locate -i to ignore the case.

[ root@tcox ~]#   locate  -i posix


when we ignore the case:
we get the additional values:

[ root@tcox ~]#   locate  -i posix   | wc -l
616

[ root@tcox ~]#   locate  -i posix  | wc -l
810

[ root@tcox ~]#   cd /etc/
[ root@tcox etc]#   vim updateddb .conf




PRUNE_BIND_MOUNTS   =  'yes'
PRUNEFS  = "9p afs anon_inodefs autofs bdev  binfmt_misc  cgroup cifs coda configfs  cpuset debugfs devpts  gfs gfs2 jffs2 sysfs tmpfs
PRUNENAMES    =  ".GIT.HG.SVN"
PRUNEPATHS  =  "/afs   /media    /net   /sfs  /tmp  /udev   /var  /cache/ccache   /var/spool 



updated.conf contains the settings that,indicate,how updatedb,will fnd/locate the paths.
We have an additional way of finding commands on the system,including the path that contained in.by running the which
command.
Which command,will run,when I execute the ssh.
The command we have to run is the /usr/bin/ssh.




[ root@tcox etc]#  which ssh
/usr/bin/ssh
[ root@tcox etc]#


hey,Based up on the path,I cannot find sshlisteon command:




[ root@tcox etc]#   sshlistenon
bash:  sshlistenon:  command not found
[ root@tcox etc]#


However,you may be having instances,where your having multiple commands,that much,that your looking for.


Then you ssh the client utility you have installed.
We are defined:



[ root@tcox etc]#  sshlistenon
-bash:  sshlistenon: command not found
[ root@tcox etc]#  which  ssh
/usr/bin/ssh
[ root@tcox etc]# whereis ssh
ssh:  /usr/bin/ssh    /etc/ssh   /usr/share/man/man

[ root@tcox etc]#   whereis -m ssh
ssh: /usr/share/man/man1/ssh.1.gz
[ root@tcox etc]#



then it will,tell me the man page is there.
If I want to search for the source files,we will be issuing the –s

If I want to search unusual or undocumented entry for ssh or rarely find for any file.


[ root@tcox etc]#  whereis  -u ssh
ssh:  /usr/bin/ssh  /etc/ssh   /etc/ssh  
[ root@tcox etc]#

another command,we uses is the type command:it is equivalent to the cat command.
Take the contents of the file and output to the particular screen.


[ root@tcox etc]#  type ssh
ssh is /usr/bin/ssh
[ root@tcox etc]# type who
[ root@tcox etc]#

it is in /usr/bin/who


if someone has created like alias,



[ root@tcox etc]#  type ll
ll is aliased to 'ls -l   --color=auto'   
[ root@tcox etc]#

it will help us and explain us about the ll .
if I do,type –a ls
then I can do the,it will tell me all the instances of that command including alias.
It will helps us and find us to know,the command or we don’t know,where they appear in the path.
If you know partially,we can use the globbing and we can use the locate.
We can also,use the find command,to help us to do things.
We are creating a backup,I want to find any files,that have SUID enabled in the /usr/bin directory.the files that are only
accessible.with services that require root access,but we set the special id on execution,so that when a normal user,runs
them,they have been run zif that was runned by the user or root user,take all of those files from there particular location and
make a copy of them and put them some where else or you have to change permissions on something.
Is all about taking files and matching a file criteria about something.
They are a lot of methods to use the find command.
We are creating the backup directory,what we are going to do,we are going to find the, in the /usr/bin about the permissions
that is set for the SUID (i.e 4000) and I want to execute the copy on those results to,usually we say the (/mnt/bkup ),but we are
saying the /root/bkup.


[ root@tcox etc]#  type -a ls 
ls  is aliased to 'ls --color=auto'
ls is /bin/ls
[ root@tcox etc]# cd
[ root@tcox ~]#  mkdir bkup
[ root@tcox etc]# cd bkup
[ root@tcox bkup]#   pwd
/root/bkup
[ root@tcox bkup]#   find /usr/bin  -perm -4000  -exec cp {} /root/bkup  \;
[ root@tcox bkup]#  



we are going to do the bkup,all been backedup here.



[ root@tcox bkup]#   ls -al  /usr/bin/change
-rwsr-xr-x  root  root  70480  May 10 2016   /usr/bin/change
[ root@tcox bkup]#  




when we go the /usr/bin/chage will help us to know the SUID bit.
(we are just making a copy from one place to another).
The find command is great for performing,single operation over a long list of find and found files.
It will show us the ability to combine that.inorder to manage our filesystem as a system administrator.

Now we can understand the text streams and redirects all of that work.






























No comments:

Post a Comment