Is there single command to search for all the softlink in the entire server?

Latest response

Hi,

I got a request from my application team to search for all the softlink in their servers prior to the RH6 - RH7 upgrade.

Also they want a list of all the files including the ownership and permission in the entire server.

Not sure when the find will end, what CPU and MEM it will consume.

Any suggestion?

Thanks in advance!!!

Responses

Hi Marco Hernaez,

Some ideas to your questions...

To find just symbolic links you could try this command

  • [EDITED: See tip below from Stephen Sadowski on the "disown" command, seems very useful!] This specific point may be a bit overkill. If your ssh session to the server you're doing this command on terminates unexpectedly, you can consider either using "screen" or "tmux" to avoid your session dying hopefully.
  • Here is the find command to acquire symbolic links. To search your file system for symbolic links, try this:
# note the letter following the word "type" below is the letter "L" in lower-case
find /var -type l -ls > /var/tmp/symlinks_on_$(hostname -s).txt
  • You could change "/var" above to just "/"
  • If you wanted a list of all files and ownership for the entire server, you can run try running this command, and some concerns to this action follow the command:
find / -type f -ls > /path/to/super_huge_file_that_will_be_difficult_to_go_through.txt
  • The naming I selected for the file above, you're going to end up with a super huge file that could be annoying to open, read, parse simply because of it's gigantic size.
  • Your query in your original post said "Also they want a list of all the files including the ownership and permission in the entire server", so I limited the command to just output files.
  • When you run this command, the "/path/to/super_huge_file_that_will_be_difficult_to_go_through.txt" should obviously be changed to a directory you can write to, and you'll want to do this as root. The resulting file could be quite large in size, so redirect the output to a place that has a good amount of storage.
  • I have no idea if your system has a potential raid array or SAN storage, so if you execute this command on a server that has a 500TB (terabyte) attached RAID array, this may interrogate the entire file system, and you may end up with an output file that is most likely not easily parse-able.
  • Is there any possibility you could ask them for specific directories they actually need instead of doing the entire server? But it is their choice if they want to go through a super-gigantic file.
  • If your server uses NFS locations, you could potentially through this command search all attached NFS storage. That might not be good, to say the least.

I'd make an assessment of the above before proceeding. Otherwise, you might end up giving them a file and use the famous words by Bugs Bunny "But remember, you asked for it". I just recommend being aware of the impact of the command, the potential size of the output, and let them know in advance if that's what they really want.

lastly, you could do this "directory by directory" so do "/var", "/etc", and so forth one at a time and redirect the output accordingly to a file that denotes each directory. it is all a matter of what they want to endure.

Regards,
RJ

Alternately if you don't want to use screen or tmux, you could do:

$  find / -type f -ls > /path/to/super_huge_file_that_will_be_difficult_to_go_through.txt &
$ disown -h

Marco Hernaez

One does not need to use tmux or screen, however, since this find command could potentially take a long time -- I mention that because some Linux servers are configured to automatically log someone off, or if somebody is using a Windows computer and using the program named putty to ssh to the system, their windows system might be rebooted (such as a corporate setting) their ssh session could be ended if a timeout is configured. This may not apply to your environment.

Try it without using tmux or screen. If the find command takes too long and your session times out before completing, then you may have to redo the command to get your output. Arguably, my response previously with tmux and screen is probably overkill.

Regards,
RJ

RJ - That's the point of disown, so that the process isn't tied to the terminal session.

If you background the process, then disown it, it will still complete even if the terminal is closed or killed. No need for tmux or screen, just in case they aren't available.

Stephen, thanks for the very nice tip of "disown" - I hadn't heard of that. - nice. I edited my initial reply citing your use of "disown".

Regards,
RJ

Glad to help!