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.
- Linux version :
cat /etc/*elease - Check if linux is 32 Bit or 64 Bit :
cat /etc/*elease - Connect to mysql using command line :
mysql -u username -pPassword - 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 - Current disk usage:
df -h - Memory usage:
free -m - Delete folder and files in it:
rm -rf folder-name - Check log activity:
tail -f *path-to-log*. Eg: tail -f /var/log/apache2/error.log - Enable any module:
sudo a2enmod *module-name*. Eg: sudo a2enmod rewrite - Zip file:
sudo zip -r file.zip folder/ - To list the largest directories from the current directory in human readable format:
du -sh * | sort -hr | head -n10 - To Recursively list all files in a directory including files in symlink directories:
find -follow - List all users in linux:
cat /etc/passwd - Add a linux user:
sudo addusernewuser - Delete a linux user:
sudo userdel -rolduser - Create Swap memory in linux:
- Command 1:
sudo dd if=/dev/zero of=/swapfile bs=1G count=4 - Command 2:
sudo chmod 600 /swapfile - Command 3:
sudo mkswap /swapfile
- Command 1:
- Unzip file:If the
unzipcommand isn’t already installed on your system, then run:- Install unzip:
sudo apt-get install unzip - After installing the unzip utility, if you want to extract to a particular destination folder, you can use:
unzip file.zip -d destination_folder
- Install unzip: