Difference between revisions of "Linux commands"

From Organic Design wiki
(See also: Port forwarding)
(Port forwarding)
Line 105: Line 105:
 
Port forwarding allows a remote client to gain access to a network so an intranet can be accessed.
 
Port forwarding allows a remote client to gain access to a network so an intranet can be accessed.
 
   
 
   
 +
ssh -fN -L[PORT]:appserver:[PORT] username@sshdserver
 +
 +
Then point your webbrowsers proxy server to appserver:[PORT] and access the intranet etc.
 +
 
*[http://en.wikipedia.org/wiki/Port_forwarding Port_forwarding (Wikipedia)]
 
*[http://en.wikipedia.org/wiki/Port_forwarding Port_forwarding (Wikipedia)]
 
*[http://www.securityfocus.com/infocus/1816 SSH Port Forwarding article]
 
*[http://www.securityfocus.com/infocus/1816 SSH Port Forwarding article]
 
*[http://www.ssh.com/support/documentation/online/ssh/adminguide/32/Port_Forwarding.html Port Forwarding (ssh.com)]
 
*[http://www.ssh.com/support/documentation/online/ssh/adminguide/32/Port_Forwarding.html Port Forwarding (ssh.com)]
 +
 
== See also ==
 
== See also ==
 
*[http://files.fosswire.com/2007/08/fwunixref.pdf Linux commands cheat sheet]
 
*[http://files.fosswire.com/2007/08/fwunixref.pdf Linux commands cheat sheet]

Revision as of 08:21, 16 December 2009

Info.svg This is the start of a list of useful Linux shell commands (generally "one liners") we use a lot


Ubuntu package management

Searching for an installed package

Use dpkg and grep;

<bash>

dpkg -l

will list all packages with java in the name

Searching for installable packages

apt-cache performs a variety of operations on APT´s package cache

<bash>

apt-cache search java </bash>

lists all packages in the cache with java in the name that are installable

Files

Get the size of a directory and its contents

<bash>

du -sh /home/foo </bash>

Search and replace content in files

You could also use find and sed, but I find that this little line of perl works nicely.
<bash>

perl -pi -w -e 's/SEARCH/REPLACE/g;' *.php </bash>

  • -e means execute the following line of code.
  • -i means edit in-place
  • -w write warnings
  • -p loop

EXTS="7z t7z"

Image Manipulation

Resizing JPG's and changing quality setting

The first line shows how to reduce and image to 25% and quality to 50% adding "_resized" to the results filename. The second command uses Perl to apply this same command to all JPG's in the current directory.

{{{1}}}

Apply an opaque background of a specified colour to a directory of transparent PNG's

  • This command requires ImageMagick to be installed
  • It loops through all PNG's in the CWD and puts them in a directory called processed which must exist
<bash>

perl -e 'qx "convert $_ -background #ff00ff -flatten foo/$_" for glob "*.png"' </bash>

See also

Network commands

Restart the network after changing configuration

<bash>

/etc/init.d/networking restart </bash>

List all the listening sockets and their ports and programs

<bash>

netstat -lp </bash>

Get current default gateway

<bash>

netstat -nr </bash>

The default gateway is on the last line, it should have the U and G flags set

Release DHCP lease

<bash>

dhclient -r </bash>

Obtain a new DHCP lease

<bash>

dhclient </bash>

Devices

mount

All files accessible in a Unix system are arranged in one big tree, the file hierarchy, rooted at /. These files can be spread out over several devices. The mount command serves to attach the file system found on some device to the big file tree.


<bash>

mount [/dev/device] [/media/directory] </bash>

fstab

Static information about the filesystems (fstab) is a configuration file that contains information of all the partitions and storage devices in your computer. It is a map of devices to the point in the filesytem where the device can be accessed, it contains information of where your partitions and storage devices should be mounted and how. It acts as a set of defaults for devices that are specified using the mount command where the file system directory is not specified. See W:Fstab#Example.


<bash>

cat /etc/fstab </bash>

Mount a .iso

See this HOWTO

Port forwarding

Port forwarding allows a remote client to gain access to a network so an intranet can be accessed.

ssh -fN -L[PORT]:appserver:[PORT] username@sshdserver

Then point your webbrowsers proxy server to appserver:[PORT] and access the intranet etc.

See also