Linux question of the day

135678

Comments

  • UnixGuyUnixGuy Mod Posts: 4,570 Mod
    ... to use xargs. ...

    This is the correct answer icon_thumright.gif use "xargs" with the "find" command.

    xargs will overcome the limitation of "ls/rm/mv" commands as they accept limited number of arguments. Also, using "xargs" with "find" will solve the problem if some file names contain special characters/white spaces.

    This will list our files:
    root@station1 # find /var/tmp -name "*.tmp" -type f -print | xargs 
    

    and this will delete the files:
    root@station1 # find /var/tmp -name "*.tmp" -type f  | xargs rm 
    


    to use "find" without "xargs", we can use the -exec with find but this will not work with file names that contain special characters in their name:
    root@station1 # find /var/tmp -name "*.tmp" -type f  -exec rm {} \;
    



    More examples:
    xargs: How To Control and Use Command Line Arguments
    Hack 22. Xargs Command Examples
    Certs: GSTRT, GPEN, GCFA, CISM, CRISC, RHCE

    Learn GRC! GRC Mastery : https://grcmastery.com 

  • W StewartW Stewart Member Posts: 794 ■■■■□□□□□□
    Interesting. Without knowing about the xargs option in find, I would try to route the output to a file or pipe the output into less if it didn't throw me another error.
  • smlksmlk Registered Users Posts: 1 ■□□□□□□□□□
    yeh you are right..
  • W StewartW Stewart Member Posts: 794 ■■■■□□□□□□
    I want to find out what application is listening on port 110. Give me two commands that will help me find this information.

    You can substitute port 110 for port 22 or 80 or whatever port you want.
  • UnixGuyUnixGuy Mod Posts: 4,570 Mod
    I use netstat with these options:
    [ root@station1 ~ ] netstat -anup | grep 110
    


    netstat options can be different from distro to distro, and I sometimes get the options wrong. What do you use?
    Certs: GSTRT, GPEN, GCFA, CISM, CRISC, RHCE

    Learn GRC! GRC Mastery : https://grcmastery.com 

  • W StewartW Stewart Member Posts: 794 ■■■■□□□□□□
    lsof -i:22
    

    lsof lists all of the open files on your system. The -i option specifies the internet address with the ":" specifying the port number. Not specifying an address tells it to listen on all addresses. And I agree, netstat is very different in FreeBSD.
  • MentholMooseMentholMoose Member Posts: 1,525 ■■■■■■■■□□
    On Linux I would use:

    netstat -plantu | grep :110

    That order and combination of switches is easy for me to remember and usually provide all needed info... process / listening ports / all ports / no resolving / TCP ports / UDP ports

    I couldn't remember another command to do it. Makes sense that lsof can do it.
    MentholMoose
    MCSA 2003, LFCS, LFCE (expired), VCP6-DCV
  • paul78paul78 Member Posts: 3,016 ■■■■■■■■■■
    Here's a scenario based one:

    You download and install an application and you noticed that it is looking for a shared library that you don't have. But your distro doesn't support that missing library, so you download the source code, compile, and install the shared library. You run the application again but it still complains that the library still isn't found. You check for the library and you see that it's installed in the directory /usr/local/lib/newlib.

    What is the most probable reason why the application is not finding the shared library and how do you fix it?
  • UnixGuyUnixGuy Mod Posts: 4,570 Mod
    @Paul78:

    Maybe add /usr/local/lib/newlib to the path? export PATH=$PATH:/usr/local/lib/newlib and add the same to the profile?

    Interesting scenario. I'd check if that application is supported by the OS.
    Certs: GSTRT, GPEN, GCFA, CISM, CRISC, RHCE

    Learn GRC! GRC Mastery : https://grcmastery.com 

  • paul78paul78 Member Posts: 3,016 ■■■■■■■■■■
    Hint: assume that its a Linux app and library but the distro package manager does not support it.
  • lordylordy Member Posts: 632 ■■■■□□□□□□
    Put /usr/local/lib in /etc/ld.so.conf and run ldconfig.
    Working on CCNP: [X] SWITCH --- [ ] ROUTE --- [ ] TSHOOT
    Goal for 2014: RHCA
    Goal for 2015: CCDP
  • hiddenknight821hiddenknight821 Member Posts: 1,209 ■■■■■■□□□□
    Maybe the source code shouldn't be complied with the default configuration? I think what needed to be done is that you compile it in the path prefix of the common library configuration: ./configure prefix=/usr/lib

    Although, the above is not a good practice for downloaded source codes, but it's probably an inevitable workaround to this particular problem.
  • paul78paul78 Member Posts: 3,016 ■■■■■■■■■■
    The right answer is the one proposed by lordy. While I agree that you can specify the installation of the shared libs into the main lib directory (assumming that the package uses autoconf properly), I generally prefer to use the sourcecode author's default.

    The reason isnt related to the shell path but the dynamic loader's configuration. A short description can be found if you read the man page on linux-ld.so.
  • UnixGuyUnixGuy Mod Posts: 4,570 Mod
    I Learned a lot by reading about this problem. Thanks Paul & Lordy
    Certs: GSTRT, GPEN, GCFA, CISM, CRISC, RHCE

    Learn GRC! GRC Mastery : https://grcmastery.com 

  • W StewartW Stewart Member Posts: 794 ■■■■□□□□□□
    I learned something new as well. This thread is pretty useful.
  • paul78paul78 Member Posts: 3,016 ■■■■■■■■■■
    Here's another scenario based question - it may require hints so feel free to ask.

    You are using a packaged distro which has an older 2.6 kernel. You decide that you want to compile a newer kernel but you want some extra feature so you download the latest kernel from kernel.org. You configure the kernel options that you want and install it. When you reboot - you run into the following problem when the kernel boot:

    ERROR: Couldn't open /dev/null (no such file or directory)
    fsck.ext4 No such file or directory while trying to open /dev/sda1
    Possibly non-existent device?

    You are put into single-user read-only mode. You go to /var/log/messages and you don't see any messages other than from the last reboot.

    What do you do to recover? And what do caused the issue?
  • W StewartW Stewart Member Posts: 794 ■■■■□□□□□□
    I believe somewhere a long the lines the device names changed with a certain kernel version but I'm not entirely sure. Maybe it was a switch to udev or something. from single user mode I'd attempt to modify the fstab file to use the uuid of the drive rather than the name but I could be way off. That's my best answer without googling.

    Edit it also looks like the dev filesystem isn't mounted either. I'm definitely thinking it's udev related.
  • W StewartW Stewart Member Posts: 794 ■■■■□□□□□□
    Just read the read only part. I'd have to boot into a working kernel and maybe try to recompile the new kernel. Maybe the ext4 driver is missing or maybe I need to make an initrd. If not I'll let somebody else take a guess at it.
  • paul78paul78 Member Posts: 3,016 ■■■■■■■■■■
    You're on the right track. The filesystem errors are a red-herring. It's devfs related.
  • paul78paul78 Member Posts: 3,016 ■■■■■■■■■■
    Ok - if no one else...

    Newer Linux kernels > 2.6 (don't remember the exact version) support a new file system (CONFIG_DEVTMPFS). In this filesystem, the kernel driver core maintains device nodes with their default names and permissions for all registered devices with an assigned major/minor number. And if you also configure CONFIG_DEVTMPFS_MOUNT - this will instruct the kernel to auto mount the devtmpfs filesystem at /dev.

    In this scenario - the kernel was not configured with CONFIG_DEVTMPFS and CONFIG_DEVTMPFS_MOUNT
  • paul78paul78 Member Posts: 3,016 ■■■■■■■■■■
    Ok - new question since there hasn't been a new one in a week.

    You download the latest Firefox and you try to run it. You get an error about a missing shared library so you download the missing library and then compile/install it. When you run the firefox binary again, you encounter a new missing shared library.

    How do you get the list of all the shared libraries that are dynamically linked to an executable?
  • paul78paul78 Member Posts: 3,016 ■■■■■■■■■■
    paul78 wrote: »
    How do you get the list of all the shared libraries that are dynamically linked to an executable?
    No takers icon_smile.gif

    Ok - answer is to use ldd. The ldd program will print shared library dependencies required by a program or shared library.
  • ChooseLifeChooseLife Member Posts: 941 ■■■■■■■□□□
    Just dropping by to say hi :) I have been busy lately and away from TE for some time...

    Great to see this thread taking on the life of its own :) Thanks for keeping it alive and posting interesting questions!
    “You don’t become great by trying to be great. You become great by wanting to do something, and then doing it so hard that you become great in the process.” (c) xkcd #896

    GetCertified4Less
    - discounted vouchers for certs
  • lsud00dlsud00d Member Posts: 1,571
    paul78 wrote: »
    No takers icon_smile.gif

    Ok - answer is to use ldd. The ldd program will print shared library dependencies required by a program or shared library.

    I haven't even thought about ldd in a long time...probably since studying for L+!
  • onesaintonesaint Member Posts: 801
    Just stumbled across this thread this morning. It reads like a good book!
    Work in progress: picking up Postgres, elastisearch, redis, Cloudera, & AWS.
    Next up: eventually the RHCE and to start blogging again.

    Control Protocol; my blog of exam notes and IT randomness
  • ChooseLifeChooseLife Member Posts: 941 ■■■■■■■□□□
    This brilliant thread inspired me to another tricky question:

    Question: How can you download a file from an HTTP server using bash without netcat/curl/wget/w3m/lynx?

    We can use the same example of http://images.google.com/intl/en_ALL/images/logos/images_logo_lg.gif for consistency.



    P.S. TE forum engine does not properly parse links to its own threads.. Sigh
    “You don’t become great by trying to be great. You become great by wanting to do something, and then doing it so hard that you become great in the process.” (c) xkcd #896

    GetCertified4Less
    - discounted vouchers for certs
  • paul78paul78 Member Posts: 3,016 ■■■■■■■■■■
    Oh - how cool - I didn't know bash had a builtin tcp device file. Good one.
  • hiddenknight821hiddenknight821 Member Posts: 1,209 ■■■■■■□□□□
    Me neither, paul78. I tried looking in my bash book, but none of them discussed the built-in tool I can use to download a file. I'd have to download the file through another tool.

    @Chooselife: Were you saying without included but not limited to netcat/curl/wget/w3m/lynx? Or can we use the tool you haven't blacklisted?
  • onesaintonesaint Member Posts: 801
    Paul eluded to it. I had to do some digging as it's not apparent unless you've read about it someplace. If you give, here is an article on it from Linux Journal.

    Great reference thread and question!
    Work in progress: picking up Postgres, elastisearch, redis, Cloudera, & AWS.
    Next up: eventually the RHCE and to start blogging again.

    Control Protocol; my blog of exam notes and IT randomness
  • hiddenknight821hiddenknight821 Member Posts: 1,209 ■■■■■■□□□□
    Thanks @onesaint. Didn't realize Paul subtly gave the solution away. I didn't know /dev/tcp file actually existed for a purpose. I really need to do some digging around more often. Great thought-provoking question again, @ChooseLife.
Sign In or Register to comment.