Important Linux + ubuntu + centos commands

We daily come across in need of various Linux + ubuntu + centos commands while updating our server and it becomes hard to remember each and every command by tips. So i thought of adding all commands at one place.

  1. Linux version : cat /etc/*elease
  2. Check if linux is 32 Bit or 64 Bit : cat /etc/*elease
  3. Connect to mysql using command line : mysql -u username -pPassword
  4. Backup mysql table in a file on server: mysql -u username -p --database=your_dbname --host=your_hostname --port=3306 --batch -e "select * from table_name" | sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//g' > your_backup_filename
  5. Current disk usage:  df -h
  6. Memory usage: free -m
  7. Delete folder and files in it:  rm -rf folder-name
  8. Check log activity: tail -f *path-to-log*. Eg: tail -f /var/log/apache2/error.log
  9. Enable any module: sudo a2enmod *module-name*. Eg: sudo a2enmod rewrite
  10. Zip file: sudo zip -r folder/
  11. To list the largest directories from the current directory in human readable format: du -sh * | sort -hr | head -n10
  12. To Recursively list all files in a directory including files in symlink directories: find -follow
  13. List all users in linux: cat /etc/passwd
  14. Add a linux user: sudo adduser newuser
  15. Delete a linux user: sudo userdel -r olduser
  16. Create Swap memory in linux:
    1. Command 1: sudo dd if=/dev/zero of=/swapfile bs=1G count=4
    2. Command 2: sudo chmod 600 /swapfile
    3. Command 3: sudo mkswap /swapfile
  17. Unzip file:If the unzip command isn’t already installed on your system, then run:
    1. Install unzipsudo apt-get install unzip
    2. After installing the unzip utility, if you want to extract to a particular destination folder, you can useunzip -d destination_folder

Leave a Reply

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