Archive

Archive for the ‘shell’ Category

Linux Bash Command Chaining

July 9th, 2009 No comments

Zivo wrote a great post on the simple logic of chaining/ANDing/ORing Bash commands:

*snip*

Command Chaining:

TO run a -> b -> c

ls -lF /etc; pwd;who;ps


Logical ANDing:

Program b will execute only if program a was executed
a&&b&&c

Programs run mutually inclusive
Returns a exit status 0 and then run b exit status 0 and then run C

Logical ANDing – runs subsequent based on exit status of 0

ls -l /etc/resolv.conf && grep name /etc/resolv.conf


Logical ORing:

Run subsequent program based on failure of previous

ls -l /etc/resolve.conf || grep name /etc/resolv.conf

Example:

If the file text.txt doesnt exist you can create with ORing

ls -l test.txt || touch test.txt

Combining ANDing ORing

-bash-3.00$ ls -l text.txt || touch test.txt && ls -ltr test.txt
text.txt: No such file or directory
-rw-r--r-- 1 carlosap other 0 Aug 22 00:13 test.txt


BASH for LOOPS

text.txt
1
2
3

LOOPS SYNTAX:
for variable in list; do command variable; done


-bash-3.00$ for i in `cat test.txt`; do echo $i; done
1
2
3
-bash-3.00$ for i in `cat test.txt`; do echo test$i; done
test1
test2
test3

*snap*

Tags:

Recommended Putty Settings

May 25th, 2009 No comments

I really like PuTTY – it might not be the perfect terminal emulator, but it does its job quite well. But sometimes you need to fumble around a bit to find the perfect settings for yet another server.

However, I found these default settings with quite useful:

Window -> Appearance -> Font: Courier New or Lucida Console
Window -> Translation -> Character Set: UTF-8
Window ->Translation -> Line Drawing: Use Unicode Line drawing code points

Tags:

Copy files over SSH

December 13th, 2008 No comments

You have a SSH connection to a remote server, and you want to copy files back and forth but don’t know how? And you don’t want to fumble with scp?
No Problem!

There are quite a few file managers out there that allow you to work with remote file systems over SSH. My favourite is Midnight Commander, which is included in most Linux distributions out there. Just start it on your local machine (type mc in your terminal), select the menu “Left”, and click on “Shell link…”. Dialog will come up, enter your login details here, just as you would when using ssh (e.g. “user...@example.com”). You will be asked for your password, and voila – there you are!

Now you can browse the remote server on the left, and your local server on the right. Copying files back and forth should be no problem.

If you are looking for a better visual experience you might want to try muCommander.

Tags:

vi basics

October 30th, 2008 No comments

There are two competing editors in the *nix world: vi and Emacs. They look simple, but they are really mighty. And they have a reputation of being overly complex and unusable for non-nerds.

Currently I am using vi most of the time, but that’s just because I am playing with equipment that is running BusyBox now and then. I guess you are not surprised that I am telling you that using vi is not  very hard.

Enough chatting, let’s get our hands dirty!
There are hundreds of vi cheat sheets and tutorials out there. But let’s keep this one simple :)

Read more…

Tags:

Show open ports and process IDs in Solaris

October 15th, 2008 No comments

I needed a list of all open ports and their respective processes of a Solaris system one day. Unfortunately lsof was not available. After some searching I ran across this script (note that it requires ptree, so it runs on Solaris only – bad luck for you Linux/Mac/Cygwin guys):

Read more…

Tags:
Performance Optimization WordPress Plugins by W3 EDGE