Difference between revisions of "Shell Commands"

From Got Opinion Wiki
Jump to navigation Jump to search
 
(5 intermediate revisions by the same user not shown)
Line 29: Line 29:


[http://www.cs.colostate.edu/helpdocs/vi.html vi text editor]
[http://www.cs.colostate.edu/helpdocs/vi.html vi text editor]
== Secure Copy (SCP) ==
Copy file "example.txt" from a remote host to local host
<pre>$ scp username@remotehost.com:example.txt /local/host/directory</pre>
Example copying remote file to local home directory:
<pre>$ scp -p username@10.0.0.200:/home/username/pkginfo_160209.txt ~/
Password:
pkginfo_160209.txt                                                                          100%  101KB 101.0KB/s  00:00</pre>
Copy file "example.txt" from local host to a remote host
<pre>$ scp example.txt username@remotehost.com:/remote/host/directory</pre>
Copy directory "dirLocal" from local host to remote host's directory "dirRemote"
<pre>$ scp -r dirLocal username@remotehost.com:/remote/host/directory/dirRemote</pre>
Copy file "example.txt" from remote host "remote1.com" to remote host "remote2.com"
<pre>$ scp username@remote1.com:/remote/host/directory/example.txt \
    username@remote2.com:/remote/host/directory/</pre>
== sed ==
Print text from line 1024 to line 1034 to console
<code>sed -n 1024,1034p textFile</code>
Store same text to file
<code>sed -n 1024,1034p textFile > newTextFile</code>


== [http://www.gnu.org/software/tar/ Tape Archival (tar)] & [http://www.gzip.org/ gzip] ==
== [http://www.gnu.org/software/tar/ Tape Archival (tar)] & [http://www.gzip.org/ gzip] ==
Line 58: Line 93:
=== un-TAR and decompress simultaneously ===
=== un-TAR and decompress simultaneously ===
<code>tar xvfz fileName.targz</code>
<code>tar xvfz fileName.targz</code>
== RAR ==
Install unrar utility
<code>sudo apt-get install unrar</code>
Extract files with full path.
<code>unrar x filename.rar</code>


== Download files ==
== Download files ==
Line 103: Line 148:


[http://www.cyberciti.biz/howto/question/man/tcpdump-man-page-with-examples.php tcpdump] man page with examples
[http://www.cyberciti.biz/howto/question/man/tcpdump-man-page-with-examples.php tcpdump] man page with examples
<pre>sudo tcpdump -D (list interfaces)
(end with Ctrl+C)
-i (interface, use 'any' for all)
-n (disable name resolution)
-nn (disable name resolution and port resolution)
-T radius
-T vxlan
-A (Print each packet (minus its link level header) in ASCII. Handy for capturing web pages.)
-v (-vv or -vvv, verbose mode)
udp
sudo tcpdump -i <interface_name> udp and port <port #> -s0 -vv -X (what is S)
-s (snaplen) Snarf snaplen bytes of data from each packet rather than the default of 262144 bytes.
-X When parsing and printing, in addition to printing the headers of each packet, print the data of each packet (minus its link level header) in hex and ASCII. This is very handy for analysing new protocols. In the current implementation this flag may have the same effect as -XX if the packet is truncated.
-XX When parsing and printing, in addition to printing the headers of each packet, print the data of each packet, including its link level header, in hex and ASCII.</pre>
[https://www.commandlinefu.com/commands/view/4371/see-entire-packet-payload-using-tcpdump See entire packet payload using tcpdump]


=== Firewall ===
=== Firewall ===
Line 179: Line 252:


== Useful sites ==
== Useful sites ==
[http://www.hypexr.org/linux_scp_help.php Linux SCP help]


[http://www.commandlinefu.com/commands/browse Command Line Fu] as in Kung "Fu"
[http://www.commandlinefu.com/commands/browse Command Line Fu] as in Kung "Fu"

Latest revision as of 07:20, 9 January 2024

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

sudo tcpdump -D (list interfaces)

(end with Ctrl+C)

-i (interface, use 'any' for all)

-n (disable name resolution)
-nn (disable name resolution and port resolution)

-T radius 
-T vxlan

-A (Print each packet (minus its link level header) in ASCII. Handy for capturing web pages.)

-v (-vv or -vvv, verbose mode) 

udp

sudo tcpdump -i <interface_name> udp and port <port #> -s0 -vv -X (what is S)

-s (snaplen) Snarf snaplen bytes of data from each packet rather than the default of 262144 bytes.

-X When parsing and printing, in addition to printing the headers of each packet, print the data of each packet (minus its link level header) in hex and ASCII. This is very handy for analysing new protocols. In the current implementation this flag may have the same effect as -XX if the packet is truncated.

-XX When parsing and printing, in addition to printing the headers of each packet, print the data of each packet, including its link level header, in hex and ASCII.

See entire packet payload using tcpdump

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