gnu

  • GNU – pushd/popd

    This couple of commands are really helpful. It allows you to easily navigate through the system without having to repeat long paths. For example, imagine that you are in the directory /user/data/data2/home/ but want to change to other directory for a moment, say /etc ; you can do:

    pushd /etc -> this will move to /etc and push our directory into the stack. After finish you job in /etc we can type:

    popd -> this will bring us to the original directory

  • Gnu – Flock

    This is an interesting command. Have you ever wanted to be sure that just one instance of your app/script is running at the same time? Then, flock is your tool. The sintax is as follows:

    flock [options] file|directory command [arguments]

    Lets see an example:

    flock /home/user/lockfile htop

    This runs htop and uses a generated file in home/user named lockfile to control the locking. If you try to run the same command, you will not be able to run htop again until the first instance finish.

  • Gnu – Timeout

    This is one of those extremely useful commands that not many people know. Basically runs a shell command and exits when the time runs out. The format is as follows:

    timeout [OPTION] DURATION COMMAND [ARG]…

    Lets see an example:

    • timeout 10s top : This starts the top utility waits for 10 seconds and quit. Simple. The sufixes are:
      • s for second
      • m for minutes
      • h for hours
      • d for days

    As always, check the man page for more details and info.

  • Gnu – w

    Have you ever wonder who is in your system? and doing what? Well, beauty always comes in small packages and today it is not an exception, the only thing you need is: w .This small tool comes to the rescue. The format is as follows:

    w [options] user […]

    Lets see some examples:

    • w -> this command with no parameters shows you all the info you need. This is the output (depends on your system):

    17:37:51 up 7:52, 1 user, load average: 0,44, 0,62, 0,69
    USER TTY LOGIN@ IDLE JCPU PCPU WHAT
    user :0 09:45 ?xdm? 1:23m 0.00s /usr/libexec/gdm-x-session --run-script /usr/bin/gnome-session

    lets see what we have here:

    1. 17:37:51 -> current time
    2. up 7:52 -> how long the system has been running
    3. 1 user -> how many users are currently logged on
    4. load average: 0,44, 0,62, 0,69 -> the load average the past 1, 5 and 15 minutes respectively
    5. Then, for each user logged into the system we have one row showing:
      1. user-> login name
      2. :0 -> the tty name
      3. From -> this field only appears if the user is connected through a remote ssh conection. In this example do not appears because the user is local
      4. 09:45 -> login time
      5. ?xdm? -> idle time (usually for remote users, if the user is local, shows xdm, the display manager)
      6. JCPU -> is the time used by all processes attached to the tty
      7. PCPU -> is the time used by the current process (the one in the what field)
      8. /usr/libexec… -> command line of the current process

    That is a lot of info for just w !

  • Gnu – ls

    This command allows you to list files and directories (dir in Ms-dos world). Lets see how this works.

    The format is as follows:

    ls [OPTION]… [FILE]…

    You can type ls as is to show a barebones listing of files and directories. Lets see more possibilities:

    • ls -l -> this shows the long listing format (its a compact way to show the info)
    • ls -a -> shows only the hidden files (the ones starting with a dot)
    • ls -la -> shows all files in listing format plus, the hidden ones
    • ls -i -> shows inode information about the files (info about the file system)
    • la -lh -> shows files and details in human readable format
    • ls -lha -> You get the idea, you can combine the options to get the result that you want, with this you get details in human readable format plus hidden files

    As you can see there are many combinations. Those here are just a tiny fraction of what is possible with this command. If you want more info, type man ls to see the full list of options.