Shell Commands

From Got Opinion Wiki
Jump to navigation Jump to search

Check Linux Version

Determine kernel version:

uname -r

Determine distribution version:

cat /etc/issue

Script command sessions

To log your terminal sessions used script command:

$script /tmp/terminal.log

CTRL+D to end script logging.

Courtesy of Unix Tutorial site

Regular Expressions

Regular expressions tutorial

Using regular expressions

vi

My vi notes

vi text editor

Secure Copy (SCP)

Copy file "example.txt" from a remote host to local host

$ scp username@remotehost.com:example.txt /local/host/directory

Example copying remote file to local home directory:

$ scp -p username@10.0.0.200:/home/username/pkginfo_160209.txt ~/
Password: 
pkginfo_160209.txt                                                                          100%  101KB 101.0KB/s   00:00

Copy file "example.txt" from local host to a remote host

$ scp example.txt username@remotehost.com:/remote/host/directory

Copy directory "dirLocal" from local host to remote host's directory "dirRemote"

$ scp -r dirLocal username@remotehost.com:/remote/host/directory/dirRemote

Copy file "example.txt" from remote host "remote1.com" to remote host "remote2.com"

$ scp username@remote1.com:/remote/host/directory/example.txt \
    username@remote2.com:/remote/host/directory/

sed

Print text from line 1024 to line 1034 to console

sed -n 1024,1034p textFile

Store same text to file

sed -n 1024,1034p textFile > newTextFile


Tape Archival (tar) & gzip

Create tar

tar -cvf filename.tar filemane

Undo tar

tar -xvf filename.tar

List contents tar

tar -tvf filename.tar

Compress file

gzip -9 filename

Decompress file

gzip -d filename

TAR and compress simultaneously

tar -cvzf newFileName.tar.gz fileOrDirectorToArchiveAndCompress

un-TAR and decompress simultaneously

tar xvfz fileName.targz

RAR

Install unrar utility

sudo apt-get install unrar

Extract files with full path.

unrar x filename.rar

Download files

To download type wget then location of file.

Check file integrity

Check MD5 checksum by using md5sum filename then compare checksum.

Check SHA1 checksum by using sha1sum filename then compare checksum.

ifconfig

To determine your IP address settings run:

ifconfig

Searching

To find path to a file run:

# find / -name "filename"

To find an expression within a file:

tips using grep

List open files

List Open Files

For example:

lsof -i tcp:80

Comparing files

How do I compare two files under linux or unix

Customize BASH prompt

Customize your bash prompt basics

Networking

tcpdump man page with examples

Firewall

iptables firewall configuration tutorial

Linux Home Networking Linux Firewalls Using iptables

Tips

Find version of OS

cat /etc/redhat-release

cat /etc/redhat-release

cat /etc/fedora-release

cat /etc/SuSE-release

Password protect with Apache

Password protect your pages with htaccess

Find hostname

Use hostname command without arguments

Users and Groups

Users

Permissions

Hardware

Graphics card

Determine your graphic card run lspci command and find line that contains VGA compatible:

[paul@templar ~]$ lspci
00:00.0 Host bridge: nVidia Corporation C55 Host Bridge (rev a2)
00:00.1 RAM memory: nVidia Corporation C55 Memory Controller (rev a1)
00:00.2 RAM memory: nVidia Corporation C55 Memory Controller (rev a1)
00:00.3 RAM memory: nVidia Corporation C55 Memory Controller (rev a1)
00:00.4 RAM memory: nVidia Corporation C55 Memory Controller (rev a1)
00:00.5 RAM memory: nVidia Corporation C55 Memory Controller (rev a2)
00:00.6 RAM memory: nVidia Corporation C55 Memory Controller (rev a1)
00:00.7 RAM memory: nVidia Corporation C55 Memory Controller (rev a1)
00:01.0 RAM memory: nVidia Corporation C55 Memory Controller (rev a1)
00:01.1 RAM memory: nVidia Corporation C55 Memory Controller (rev a1)
00:01.2 RAM memory: nVidia Corporation C55 Memory Controller (rev a1)
00:01.3 RAM memory: nVidia Corporation C55 Memory Controller (rev a1)
00:01.4 RAM memory: nVidia Corporation C55 Memory Controller (rev a1)
00:01.5 RAM memory: nVidia Corporation C55 Memory Controller (rev a1)
00:01.6 RAM memory: nVidia Corporation C55 Memory Controller (rev a1)
00:02.0 RAM memory: nVidia Corporation C55 Memory Controller (rev a1)
00:02.1 RAM memory: nVidia Corporation C55 Memory Controller (rev a1)
00:02.2 RAM memory: nVidia Corporation C55 Memory Controller (rev a1)
00:03.0 PCI bridge: nVidia Corporation C55 PCI Express bridge (rev a1)
00:06.0 PCI bridge: nVidia Corporation C55 PCI Express bridge (rev a1)
00:07.0 PCI bridge: nVidia Corporation C55 PCI Express bridge (rev a1)
00:09.0 RAM memory: nVidia Corporation MCP51 Host Bridge (rev a2)
00:0a.0 ISA bridge: nVidia Corporation MCP51 LPC Bridge (rev a3)
00:0a.1 SMBus: nVidia Corporation MCP51 SMBus (rev a3)
00:0a.2 RAM memory: nVidia Corporation MCP51 Memory Controller 0 (rev a3)
00:0b.0 USB Controller: nVidia Corporation MCP51 USB Controller (rev a3)
00:0b.1 USB Controller: nVidia Corporation MCP51 USB Controller (rev a3)
00:0d.0 IDE interface: nVidia Corporation MCP51 IDE (rev a1)
00:0e.0 IDE interface: nVidia Corporation MCP51 Serial ATA Controller (rev a1)
00:0f.0 IDE interface: nVidia Corporation MCP51 Serial ATA Controller (rev a1)
00:10.0 PCI bridge: nVidia Corporation MCP51 PCI Bridge (rev a2)
00:10.1 Audio device: nVidia Corporation MCP51 High Definition Audio (rev a2)
00:14.0 Bridge: nVidia Corporation MCP51 Ethernet Controller (rev a3)
01:00.0 VGA compatible controller: nVidia Corporation G92 [GeForce 8800 GT] (rev a2)
[paul@templar ~]$

Useful sites

Linux SCP help

Command Line Fu as in Kung "Fu"

BASH cures cancer

Linux