Wednesday 3 September 2014

Useful Linux Commands

Compress/Uncompress archives:

To compress a directory with zip do the following:

zip -r archive_name.zip directory_to_compress
To uncompress a zip archive do the following:
unzip archi_name.zip
To compress a directory with tar do the following:
tar -cvf archive_name.tar directory_to_compress
To extract - tar archive:
tar -xvf archive_name.tar
Notes: This will extract the files in the archiv_name.tar archive in the current directory. Like with the tar format you can optionally extract the files to a different directory by tar -xvf archive_name.tar -C /tmp/extract_here/
To compress a directory with tar.gz do the following:
tar -zcvf archive_name.tar.gz directory_to_compress
To extract tar.gz archive:
tar -zxvf archive_name.tar.gz
To compress a directory with Tar.gz2 do the following:
tar -jcvf archive_name.tar.bz2 directory_to_compress
To extract tar.gz2 archive:
tar -jxvf archive_name.tar.bz2 -C /tmp/extract_here/
To know which version of linux distro you are using:
cat /etc/*-release
Linux Commands Related to Files & Directories
Copy files and directories:
cp stuff stuff.bak
Copy to another directory:
cp xyz.php /directory
Options/Flags That Are Used With CP
-I - interactive. Prompts you to confirm if the file is going to overwrite a file in your destination. This is a handy option because it can help prevent you from making mistakes.
-r - recursive. Rather than just copying all the files and directories, copies the whole directory tree, subdirectories and all, to another location.
-f - force. Copies without prompting you for confirmation that the file should be overwritten. Unless you're sure you want to force the copy, you probably don't want to make friends with this option right now.
-v - verbose. Will show the progress of the files being copied.
Mysql Database Import/Export:
Import as sql:
mysql -u username -p databasename < db.sql
Import as bz2:
bunzip2 < db.sql.bz2 < mysql -u username -p databasename
Notes: It will prompt you for database password. Insert database password and database import will start importing. If you get any error related to socket add -socket=/opt/lampp/var/mysql/mysql.sock to above command.
Export as sql:
mysqldump -u youruser -pUserPassword yourdatabase > wantedsqlfile.sql
Export as sql.gz:
mysqldump -u [user] -pUserPassword yourdatabase | gzip > filename_to_compress.sql.gz

If  you want know about winter internship than click here

No comments:

Post a Comment