Useful Linux Commands

Linux offers very powerful tools for text processing, files search, etc.

This is a short overview of some commands that we are using regularly

Contents:

Help and description of Linux commands

for many commands to get more info about options and how to use, you can type in terminal

$ commandname --help
$ man commandname

Connecting

Connect to another machine

$ ssh user@host
Connect to mysql (use -h if it is not locally)
$ mysql -uuser -p -hhost

MySQL

See also: Using My SQL

Create a database

create database dbname

Set permissions

grant all on dbname.* to "user"@"192.168.1.%" identified by "password";
grant all on dbname.* to "user"@"localhost" identified by "password";

Load from file into database

$ mysql -uuser -p databasename<filename

Dump data from database into file

$mysqldump -uuser -p -hhost dbname > filename.mysql

Set cache variable

mysql> set global query_cache_size = 1000000;
mysql> show global variables like 'query_cache_size';

Searching

To search for files or folders

  • find -name
  • locate
  • wheries
  • which

To search for active java processes

e.g. to test whether Pentaho server is running

$ ps -ef |grep java

Text processing

See also: Reading text files

To open text documents in terminal

  • vi
  • less
  • tail
  • tail -f
  • head
Followed by the file name. For all of the above, once inside the file
  • :q to exit
  • / to search for a string

To search for a string in multiple text files

$ grep 'string' *.txt

To search recursively for all files containing the word 'string'

$ grep -r -o 'string' *
  • -o only show file names, suppress content
  • -r recursive
More info

Replace strings in multiple files

$ sed -i 's/string_old/string_new/g'  *.report

Test what character has the specified octal value

e.g. octal = 200

Can be useful when debugging issues with character types.

$ echo $'\200'

References


Creator: Julia Gusman on 2009/08/21 12:25
XWiki Enterprise 1.7.2.16857 - Documentation