Tuesday, October 4, 2011

Linux cmd syntax

(Anhgolden's Blog)-

Zip and Unzip:
# zip -r archive_name.zip directory_to_compress
# unzip archive_name.zip

Tar and Untar:
# tar -cvf archive_name.tar directory_to_compress
# tar -xvf archive_name.tar
# tar -xvf archive_name.tar -C /tmp/extract_here/

Tar.gz and Untar.gz:
# tar -zcvf archive_name.tar.gz directory_to_compress
# tar -zxvf archive_name.tar.gz
# tar -zxvf archive_name.tar.gz -C /tmp/extract_here/

Move and Rename:
# mv old_folder_name new_folder_name
# mv old_file_name new_file_name
# mv file_name destination_directory

Copy:
# cp -r folder_name_(subdirs-and-files) destination

Delete:
# rm -rf filename or directory (subdirs and files)

Export mysql db:
#mysqldump -u [USERNAME] -p [DBNAME] | gzip > [/path_to_file/DBNAME].sql.gz
or
#mysqldump -u [USERNAME] -p [DBNAME] > [/path_to_file/DBNAME].sql
#gzip -d [/path_to_file/DBNAME].sql.gz

Import mysql db:
# gunzip mysqldump.sql.gz
# mysql -u username -p -h localhost test-database < mysqldump.sql
password: _


Use mysql:
#mysql -u [USERNAME] -p
SHOW DATABASES;
DROP DATABASE [DBNAME];
CREATE DATABASE [DBNAME];
USE [DBNAME];
SOURCE [/path_to_file/DBNAME].sql;

Change password root:
#passwd

Restart apache linux server:
# /etc/init.d/httpd restart

Update date/time:
# rdate -s time.nist.gov
# date

Change Ownership and Group
#chown -R username:usergroup dir/files

Change Permission
#chmod 777 -R dir/files

Change Mysql password:
#mysqladmin -u root password new-password
or

#mysqladmin -u root -p old-password password new-password

Shutdown linux:
#Shutdown -h now (h: halt means to stop)

#Shutdown -h +t (t: minutes)

Restart or reboot linux:
#Shutdown -r [+t]

#Reboot [-f] (f: force)

No comments:

Post a Comment