Tag: linux commands

  • Find files older than X minutes

    Find files older than X minutes

    To find files that are older than X minutes, use the command

    find /path/ -type f -mmin +30

    This will find all files inside /path/ that are older than 30 minutes.

    If you need to delete those files, run

    find /path/ -type f -mmin +30 -delete

    To find files created in the last 30 minutes, run

    find /path/ -type f -mmin 30

    See find

  • How to cut lines separated by multiple spaces?

    How to cut lines separated by multiple spaces?

    cut is a Linux command that can be used to cut a line of text with a specific delimiter. I want to cut lines separated by multiple spaces like

    cut multiple space

    Since the fields are separated by multiple spaces, I can’t just use cut -d’ ‘ command. What you can do is combine multiple spaces into one using tr command.

    tr -s ' '
    

    Here is the command I used to get all database name with Sleep connections

    mysqladmin processlist | grep "Sleep" | tr -s ' ' | cut -d' ' -f8
    

    Another solution is to use awk command.

    mysqladmin processlist | grep "Sleep" | awk '{print $8}'
    

    See cut

  • setfacl

    The setfacl utility sets Access Control Lists (ACLs) of files and directories.

    To install setfacl on Ubuntu/Debian, run

    apt install acl
    

    Here is an example, where we create 2 users, one user will be given access to folder inside another users home directory.

    useradd -m --shell /bin/bash  user1
    useradd -m --shell /bin/bash  user2
    su - user1
    mkdir share
    setfacl -m u:user2:rwx share
    

    in setfacl, -m option is used to modify. u specify user, if you need to set acl for a group, use g instead of u.

    See Linux Commands

  • chown

    chown command is ued to change ownership of a file or folder

    In this example ownership of folder public_html to username and group specified.

    chown -R username:group public_html
    

    -R used for recursively change ownership, that is all files and folders inside the folder also get the new ownership.

    See Linux Commands

  • uname

    List Kernel Full details

    boby@hon-pc-01:~ $ uname -a
    Linux hon-pc-01 4.4.0-53-generic #74-Ubuntu SMP Fri Dec 2 15:59:10 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
    boby@hon-pc-01:~ $ 
    

    List Architecture

    boby@hon-pc-01:~ $ uname -m
    x86_64
    boby@hon-pc-01:~ $ 
    

    Show Kernel Version

    boby@hon-pc-01:~ $ uname -r
    4.4.0-53-generic
    boby@hon-pc-01:~ $ 
    

    See Linux Commands