Saturday, 11 April 2020

Some Linux Tricks

There are some basic linux tricks that I occasionally need and that I'd like to share:

  • Passing the output of a program/command as argument to another program/command Notice that when using pipes "|" we are passing the stdout as stdin to second program. What I mean here is passing it as argument. Let's say we have a file that contains the path to a folder which contents we want to list. We have 2 ways to achive this, with the $() "operator" or with the xargs tool that seems to be installed in most modern systems:
    ls $(cat fileContainingPath.txt)
    cat fileContainingPath.txt | xargs ls
  • Find what application has a file open (one of the main reasons to make me launch SysInternals Process Explorer in Windows). It's that simple as doing:
    lsof filename
  • See the shared libraries (.os files, equivalent to Windows .dlls) loaded by a process. We'll use again lsof, this time like this:
    lsof -p PIDofTheProcess | grep '\.so$'
  • Find to what process does a window belong to* (this is another of the main reasons for me to launch Process Explorer in Windows):
    xprop | grep PID

No comments:

Post a Comment