Some Linux commands I found useful

July 22, 2011

To find out the version of the system:
uname -r -m

To backup and restore a database
mysql -u root -p libdata </home/pradeep/Desktop/libuser.sql

To create a database
mysqladmin -u root  -p create libdata

To drop a database
mysqladmin -u root  -p drop libdata

Current folder path

Set up a virtual node
Copy the default website as a starting point. sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/mysite 

Edit the new configuration file in a text editor "sudo nano" on the command line or "gksudo gedit", for example: gksudo gedit /etc/apache2/sites-available/mysite

Change the DocumentRoot to point to the new location. For example, /home/user/public_html/

Change the Directory directive, replace <Directory /var/www/> to <Directory /home/user/public_html/>

You can also set separate logs for each site. To do this, change the ErrorLog and CustomLog directives. This is optional, but handy if you have many sites
Save the file 

Deactivate and Activate apache site:
sudo a2dissite default && sudo a2ensite mysite

Finally, we restart Apache2:
sudo /etc/init.d/apache2 restart

Test Apache
echo '<b>Hello! It is working!</b>' > /home/user/public_html/index.html
Finally, browse to http://localhost/


Find php version
php -v
You can recover MySQL database server password with following five easy steps.

Step # 1: Stop the MySQL server process.

Step # 2: Start the MySQL (mysqld) server/daemon process with the --skip-grant-tables option so that it will not prompt for password.

Step # 3: Connect to mysql server as the root user.

Step # 4: Setup new mysql root account password i.e. reset mysql password.

Step # 5: Exit and restart the MySQL server.

Here are commands you need to type for each step (login as the root user):

Step # 1 : Stop mysql service

# /etc/init.d/mysql stop


Stopping MySQL database server: mysqld.
Step # 2: Start to MySQL server w/o password:

# mysqld_safe --skip-grant-tables &


[1] 5988
Starting mysqld daemon with databases from /var/lib/mysql
mysqld_safe[6025]: started
Step # 3: Connect to mysql server using mysql client:

# mysql -u root


Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 4.1.15-Debian_1-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

Step # 4: Setup new MySQL root user password

mysql> use mysql;
mysql> update user set password=PASSWORD("root") where User='root';
mysql> flush privileges;
mysql> quit

Step # 5: Stop MySQL Server:

# /etc/init.d/mysql stop


Stopping MySQL database server: mysqld
STOPPING server from pid file /var/run/mysqld/
mysqld_safe[6186]: ended

[1]+  Done                    mysqld_safe --skip-grant-tables
Step # 6: Start MySQL server and test it

# /etc/init.d/mysql start
# mysql -u root -p

lsof |grep snd — how to free a linux sound device
Restarting networking services
sudo /etc/init.d/networking restart
ps -e | grep mysql
sudo shutdown -h now

M-crypt set-up and installation
sudo apt-get install mcrypt
sudo apt-get install php5-mcrypt

dkpg --list |grep crypt
dpkg --status mcrypt

 mplayer -playlist  -dumpstream -dumpfile output.ram

Basic setup
anon-access = read
auth-access = write
realm = My First Repository
password-db = passwd

:::: To encrypt password ::::
perl -e '$pass="mypasswd"; print crypt($pass, $pass);

View Package Paths In Red Hat
rpm -ql <packagename>

Create A File
touch <filename>

Change ownership of file
chown <username>:<groupname> <file or directory name>

Change file permissions
chmod 755 <filename>

use -r for recursive application


Login as
su <username>
Change Password

Dxdiag equivalant

The 'lspci' utility lists devices on the PCI busses in the system.

The 'dmidecode' utility should allow you to get detailed information from your BIOS about your processor, memory, chipsets, etc.

The output of the 'dmesg' command will quite often contain most of the information you want.

The 'glxinfo' command can give you details of the OpenGL capabilities of your hardware.

Disk space usage
df -h

What is machine's RAM/Memory usage?
free -m

How many physical CPU's?
cat /proc/cpuinfo | grep "physical id"|sort|uniq|wc –l

How many cores each CPU has?
cat /proc/cpuinfo | egrep "core id|physical id" | tr -d "\n" | sed s/physical/\\nphysical/g | grep -v ^$ | sort | uniq | wc –l

Total size of current directory
du -s

What is the OS Name
cat /etc/*release*

To login to service account w/o console

 su -s /bin/bash jenkins

You Might Also Like


Popular Posts