Linux commandline Cheat Sheet

The following page is a general dumping ground for snippets i have found useful when managing Linux servers and generally operating a Linux machine, its in the process of being tidied up, but in the mean time....

NETWORK SNIPPETS
Show devices: ifconfig
Show wireless devices: iwconfig
Scan wifi for IP addresses: sudo arp-scan --interface=wlan0 192.168.1.0/24
Scan ethernet for IP addresses: sudo arp-scan --interface=eth0 192.168.1.0/24
Restart network: sudo ifdown -a; sudo lspci | ifup -a
Ping Whole Network: ping -b 192.168.1.255
Show LAN detail: route -n
Grab my ethernet port IP: ifconfig | grep -A 1 eth0
RemapHost: sudo vim /etc/hosts
127.0.0.1 www.newhostname.com
Send message to all logged on users: wall < "write your message here"

NETWORK SNIPPETS
shutdown: sudo halt
netcat chatroom:
- Listen: $ nc -l -p 3333
- Connect: $ nc 192.168.1.44 3333
Netcat port scanning: $ nc -v -n -z -w 1 192.168.1.2 1-1000
Or listen on a port with socat: $ socat - TCP-LISTEN:19999,crlf

MYSQL
Login: $ mysql -u USERNAME -p
Use database: $ use DATABASENAME
Check table@ CHECK TABLE node_counter;
Repair table: REPAIR TABLE node_counter;
Dump Individual db: mysqldump databaseName > file.sql
[connect] mysql -h localhost -u root -p
[Tunnel]
$ Open tunnel: ssh -L 3306:localhost:3306 root@yourhost.co.uk
The local host parameters will work as a connection with "localhost:3305".
[Add a user]
create user 'new-username'@'localhost' identified by 'password-for-new-account'
grant all on mydatabase.* to useraccount@localhost

# select largest database tables in MySQL
SELECT CONCAT(table_schema, '.', table_name),
       CONCAT(ROUND(table_rows / 1000000, 2), 'M')                                    rows,
       CONCAT(ROUND(data_length / ( 1024 * 1024 * 1024 ), 2), 'G')                    DATA,
       CONCAT(ROUND(index_length / ( 1024 * 1024 * 1024 ), 2), 'G')                   idx,
       CONCAT(ROUND(( data_length + index_length ) / ( 1024 * 1024 * 1024 ), 2), 'G') total_size,
       ROUND(index_length / data_length, 2)                                           idxfrac
FROM   information_schema.TABLES
ORDER  BY data_length + index_length DESC
LIMIT  10;

MySQL REPAIR & OPTIMISE ALL DB's
Repair: mysqlcheck -Ar
Optimise: mysqlcheck -Ao
repair &Optimise: mysqlcheck -Aor
mysql log: mysqld.log
slow queries log: /var/log/mysqld-slow-queries
Start MYSQL: service mysqld startWhen MYSQL running (ensure it restarts on re-boot): chkconfig mysqld on mysql > show databases;myql> CREATE DATABASE foo;mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES ON databasename.* TO 'username'@'localhost' IDENTIFIED BY 'password';mysql> SET PASSWORD FOR 'newUser'@'localhost' = PASSWORD('password');mysql> DROP DATABASE foo;Clear table data: TRUNCATE TABLE tablename;replace text: UPDATE tablename SET fieldname = Replace(fieldname, 'replace this', 'with this');
APACHE
virtual hosts syntax: apachectl configtest
Restart: apachectl graceful
Hard restart: apachectl -k restart

FILE SYSTEM
[List Attached Drives]: sudo blkid
[Unmount All]: umount -a
[Carbon Copy to a USB Drive]: sudo dd if=/dev/sda1 of=/dev/sdb1
[Make Execute..]: chmod u+x filename.sh

FILE PERMISSION
Set file permissions: chmod [owner][grp][anyonelse]
0 = No Permissions
1 = Execute Only
2 = Write Only
3 = Write and Execute
4 = Read Only
5 = Read and Execute
6 = Read and Write
7 = Read, Write and Execute

JOBS/START/STOP PROCESSES
[list jobs] jobs
[stop a job] Ctrl z
[kill specified job] kill %1
[run specific job in the background ] bg %1
[run specific job in the forground ] bg %1

DESKTOP
xrandr --output VGA1 --mode 1920x1200
[Reload Desktop]: xfdesktop
[List Screens]: xrandr

USERS
[Change Password]: passwd username

AUDIO
Test audio output: speaker-test -t sine -f 2600 > /dev/null
Set Device/Volume/Levels: alsamixer
Pipe random output to audio on ALSA systems:
aplay -c 2 -f S16_LE -r 44100 /dev/random

Pipe random output to audio on OSS systems:
/dev/random > /dev/audio

GSTREAMER
$ sudo apt-get install gstreamer0.10-0
$ sudo apt-get install gstreamer0.10-tools;
$ sudo apt-get install gstreamer0.10-plugins;
$ sudo apt-get install gstreamer0.10-plugins-base;
$ sudo apt-get install gstreamer0.10-plugins-bad

The check things are installed:
$ gst-inspect-0.10

Setup Multichannel Audio on Xubuntu 10.10
1. Make sure sound cards are defined in .asoundrc in the home dir.
2. Install jackd
3. Configure realtime: sudo dpkg-reconfigure -p high jackd
4. Select realtime option 'yes'.
5. sudo adduser tomkeene audio

To compile exampe clients:
gcc -o metronome `pkg-config --cflags --libs jack` metro.c

Run metronome:
$ ./metronome -b 120

JACK AUDIO
Start with build in audio: jackd -r -d alsa -d hw:0

List Jack in/out options:
$ jack_lsp
alsa_pcm:capture_1
alsa_pcm:capture_2
alsa_pcm:playback_1
alsa_pcm:playback_2
metro:120_bpm

Connect options to outputs:
$ jack_connect metro:120_bpm alsa_pcm:playback_1

Comments

Post new comment

  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <h3> <h2> <h4> <img> <div> <table> <tr> <td> <pre>
  • Lines and paragraphs break automatically.
  • Insert image: [img:node_id align=(left|right) size=(|fullLA|fullPreview|fullSQ|halfLA|halfPO|halfSQ|thirdSQ) action=(popup|link|frame) url=url style="margin:10px;" title=text description=text]

More information about formatting options

 
info@theanthillsocial.co.uk XHTML 1.0 Strict CSS2 WAI