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 regularlyHelp 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
$ mysql -uuser -p -hhost
MySQL
See also: Using My SQLCreate 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 filesTo open text documents in terminal
- vi
- less
- tail
- tail -f
- head
- :q to exit
- / to search for a string
To search for a string in multiple text files
$ grep 'string' *.txt
$ grep -r -o 'string' *
- -o only show file names, suppress content
- -r recursive
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
on 30/08/2010 at 15:56