top and important linux commands

In this blog article I will be going to put together top and important linux commands that may be really helpful during web development, server administration, monitoring and day to day linux operations. I am starting with few commands and will keep on adding as and when I encounter more.

1. Clean a file or remove all contents of file or make file size zero

cat /dev/null > logfile

OR

true | tee logfile

OR

truncate --size 0 logfile

Out of above 3 commands you can use any. The command will clean up contents of file named logfile and make it size zero.

2. Find Process Id of a process

ps aux | grep httpd

OR

pidof httpd

Above commands will display pids(process ids) of httpd process, httpd is the process name. You can try for other process names.

3. Top Command

top

Above commands will display list of top processes, along with the memory and cpu consumption by each process. It displays over all cpu and memory consumption, cpu ideal %, stolen cpu %, swap utilization etc. as well.

Output of top command:

top-command

4. chown Command

chown ubuntu:www-data /var/www/html

Above commands will change the ownership of /var/www/html directory to ubuntu user and www-data group. To change permission recursively including the files and subdirectories inside /var/www/html user below command.

chown -R ubuntu:www-data /var/www/html

To change only group ownership to apache, you can use the command as below:

chown -R :apache /var/www/html

5. Remove a file

rm /var/log/maillog

Above command will remove maillog file from /var/log directory. To remove a folder and its content recursively use below command:

rm -rf /var/log

This command will delete log directory and all its contents.

6. Chmod all directories to 755 and files to 644



find . -type d -print0 | xargs -0 chmod 0755
find . -type f -print0 | xargs -0 chmod 0644 

OR


find . -type d -perm 777 -exec chmod 755 {} \;
find . -type f -perm 777 -exec chmod 644 {} \; 

. Stands for current directory, incase you want to do for some other directory then give the path in place of dot, like as below.


find /var/www/html -type d -perm 777 -exec chmod 755 {} \;
find /var/www/html -type f -perm 777 -exec chmod 644 {} \;
Please follow and like us:
20

Add a Comment

Your email address will not be published. Required fields are marked *