Here’s a list of 10 commands which may come handy when using the command line in Linux:

  1. Search for all files modified in the last N days containing a specific text in their name
  2. find DIR -mtime -N -name "*TEXT*"

    For example:

    find ~ -mtime -5 -name "*log*"

    Will display all the files modified in the past 5 days which include the text ‘log’ in their filename.

  3. Determine which processes use the most memory
  4. ps aux | sort -nk 4 | tail

    Will show the first 10 processes which use the most memory, using ascendant sorting. Alternately:

    ps aux | sort -nrk 4 | head

    Will show the first 10 processes using most memory, using descendent sorting.

    Output of ps aux | sort -nrk 4 | head

  5. Display the username which is currently logged in
  6. whoami
  7. Show date using format modifiers
  8. date +"%H:%M:%S"

    Will output time in format HOUR:MINUTE:SECOND. You can use any format specifiers explained in the man page. The double quotes are required in case you need to use spaces.

    Showing date in format month, day year

  9. Show info about a specific user
  10. finger $USER
    Output of finger $USER

  11. Show disk usage separately for each partition
  12. df -h

    The -h switch will tell df to show human-readable sizes (KB, MB and GB when it is the case)

    df -B 1K

    Will show sizes in kilobytes.

  13. Show which modules are loaded
  14. lsmod
  15. Add or remove a module to/from the Linux kernel
  16. Insert a module:

    modprobe MODULE

    Remove a module:

    modprobe -r MODULE
  17. Search for a file using locate
  18. locate FILENAME

    Will search the locate database (created with updatedb) for any path or file which contains FILENAME.

  19. Change the encoding of a text file
  20. iconv -f INITIAL_ENCODING -t DESIRED_ENCODING filename

    For example:

    iconv -f ISO-8859-16 -t UTF-8 myfile.txt

    Will change the encoding of myfile.txt from ISO-8859-16 (Romanian) to UTF-8.

Tags: