SED Cheatsheet



Some useful cheatsheet for sed:-

sed ‘2d’ file.txt Remove second line from file.txt
sed ‘/mickgenie/d’ file.txt Remove the line containing the word/string mickgenie from file.txt
sed ‘$d’ file.txt Remove last line from file.txt
sed ‘/^$/d’ file.txt Remove empty line from file.txt
sed ‘1,5d’ file.txt Remove line between 1 and 5 from file.txt

Linux epoch time conversion


In Linux or database, many time is display in epoch format, and human might not understand what is the exact time for it. However, you may easily convert them through Linux command.

To convert from digital to epoch format,

# date +%s

To convert from epoch to digital format,

# date [email protected]

Linux: Command to check Perl Modules

instmodsh, a shell to examine installed modules. Used to easily list all the installed module from your server/PC.

[email protected] [~]# instmodsh
Available commands are:
   l            - List all installed modules
   m <module>   - Select a module
   q            - Quit the program

By hitting ‘l’, it will show you the list of installed module,

cmd? l
Installed modules are:


Linux: disk usage command – du

du is a standard unix command to calculate disk space from Unix/Linux system.

To get the sum space of the directory,


To get sum space with human-readable,

du -sh

To get sub directories space

du -sh *

To get sub directories space with all hidden folder,

du -sk .[!.]* * | sort -n

Understand Linux-based RAM and it’s cache

Linux Operating System that powered by Linux kernel have an advanced disk cache algorithm that used to store frequently access data from Hard disk.

This is to explain why some Linux server’s RAM still getting high memory usage even you upgrade your RAM.

To find out how much memory using by the Linux-based server, you may use the linux command “free” to track it. To get the detailed/actual memory usage, you may run the following command from your Linux box.

free -m

You should get some result as below,

             total       used       free     shared    buffers     cached
Mem:         15905       2879      13026          0        384        900
-/+ buffers/cache:       1593      14311
Swap:         3999          0       3999

With the result above, you may see that the used memory is 2879MB and free memory is 13026MB. However, the cached memory is 1593MB while the actual free memory will be 14311MB.

cPanel: How to export SSL from cPanel

With cPanel control panel, they do not provide any tool to export the SSL certificate. To done this, you may easily get the SSL export with Linux command through SSH.

To get this done, you may access to SSH through Terminal to Putty.
1. First of all, you need to ensure that you have the root access. Otherwise, contact the server administrator.
2. Log into the SSH.
3. Run the following command and replace the domain_name with your domain name such as,

# openssl pkcs12 -export -out /backup/domain_name.pfx -inkey /etc/ssl/private/domain_name.key -in /etc/ssl/certs/domain_name.crt

Linux Command: alias

Some times, you will found out your used server having different setting in term of the command used from the other server such as “ls” is having different color, etc.

To actually understand what is the shortcut set from your server, you may use Linux command named alias.

To show previous set shortcut,
[email protected] [~]# alias
alias attrib=’chmod’
alias chdir=’cd’
alias copy=’cp’
alias d=’dir’

To set new alias,
[email protected] [~]# alias bb=’ps aux | more’

To remove the alias,
[email protected] [~]# unalias bb

How to remove file older than 3 days

You might ask how to remove file that existed for 3 days or more.

It is quite straight forward and easy from Unix(Linux) command if you using find.

You may refer to the sample script as below.
find . -type f -mtime +3 -exec rm -rf {} \;

As the command above, it will find the file type of file and file existed for 3 days, execute the command of rm (remove). To be clear you may refer to the detail as below.
type – file type, you may define f for file and d for directory
mtime – It could be define that the last modified date and +3 is 3 days
exec – execution of your Linux command
\; – indicate that your command end

Alternatively,  you may use atime which last active time to replace mtime. Have fun.