Category Archives: shell

PHPHOST BLOG

Web Hosting Related Articles You May Need

[one-liner]: Improving the performance of SSH Tunnels using Alternative Ciphers; when displaying X11 Apps

Background

Have you ever used an ssh tunnel to try and remotely display an X windowed application and then wished you hadn’t, because the performance was so bad you’d be waiting till next week for the window to come up?

Read on because here’s how you can make this much more tolerable & usable.

Solution

There are 2 […]

Continue reading

Posted in one-liner, shell, ssh, Syndicated, tip, tips & tricks | Comments Off on [one-liner]: Improving the performance of SSH Tunnels using Alternative Ciphers; when displaying X11 Apps

Why are “executables” such as reboot, shutdown, and vgscan symlinks in the /sbin directory?

Background

If you’ve ever gone poking around in your Linux system’s /sbin directory the site of files like this might make you scratch your head.

1
2
3
4
5
6
7
8
lrwxrwxrwx 1 root root 3 Jun 7 2011 vgmerge -> lvm
lrwxrwxrwx 1 root root 3 Jun […]

Continue reading

Posted in linux, shell, Syndicated, sysadmin, tip, tutorials | Comments Off on Why are “executables” such as reboot, shutdown, and vgscan symlinks in the /sbin directory?

[one-liner]: Debugging Bash Scripts

Background

From time to time it’s useful if you can turn up the debugging messages that come from Bash, when working out either interactive or shell script problems. Here are 2 methods that can help in getting down to the details.

Solution

There are essentially 2 methods.

Method #1: -x method

When writing a shell script you’ll sometimes want to […]

Continue reading

Posted in bash, one-liner, script, shell, Syndicated, tips & tricks | Comments Off on [one-liner]: Debugging Bash Scripts

[one-liner]: How do you capture the status of a command ($?) in Bash, when run through a pipe?

Background

While answering questions on the stackexchage website Unix & Linux I saw the following question which was about something I’d encountered, but until today never knew how to accomplish, so I’m posting it here for my own reference in the future.

The question?

How do you get the exit status ( $? ) from the command haconf […]

Continue reading

Posted in bash, one-liner, script, shell, Syndicated, tips & tricks | Comments Off on [one-liner]: How do you capture the status of a command ($?) in Bash, when run through a pipe?

[one-liner]: Overview of Bash I/O Redirection

Background

I recently came across this question on the Stackexchange site Unix & Linux. This question was interesting in the sense that it covered much of the I/O redirection facilities that are available in the Bash Shell, so for posterity sake I’m adding my answer to this question here on my blog.

Solution

a number 1 = standard […]

Continue reading

Posted in bash, one-liner, script, shell, Syndicated, tips & tricks | Comments Off on [one-liner]: Overview of Bash I/O Redirection

[one-liner]: Redirecting an Already Running Program’s STDOUT to a File using dupx

Background

Recently I came across this really cool UNIX tool called dupx. I was looking for a way to connect to a program’s STDOUT and STDERR after I had already started it. This was a long running, think 30+ hours job, and I didn’t want to have to stop and restart it. As is the case […] Continue reading

Posted in centos, fedora, linux, one-liner, rhel, shell, Syndicated, sysadmin, tips & tricks | Comments Off on [one-liner]: Redirecting an Already Running Program’s STDOUT to a File using dupx

[one-liner]: Calculating & Sorting Disk Usage Using du

Background

Occasionally I want to calculate how much disk space is being consumed with a directory. Here are a couple of simple yet powerful one-liners that achieve this.

Solutions

method #1

This first choice is inefficient in the sense that it basically runs du twice. Once to generate a sorted list of the directories & files by size and […] Continue reading

Posted in bash, one-liner, shell, Syndicated, tip, tips & tricks | Comments Off on [one-liner]: Calculating & Sorting Disk Usage Using du

[one-liner]: Why is awk skipping the first line?

Background

I’ve used AWK for years but never had a reason to use it to split on anything except spaces until now. Hard to believe but I usually use sed to convert the separator characters to spaces.

1
2
# sed example
echo "this|is|a|string" | sed ‘s/|/ /g’

So I was trying to use AWK’s field separator variable, FS but […] Continue reading

Posted in awk, one-liner, shell, Syndicated, sysadmin, tips & tricks | Comments Off on [one-liner]: Why is awk skipping the first line?

[one-liner]: Making the Linux date Command Display the Month & Day in Single Digits

Background

Anyone that’s worked in a UNIX environment is probably somewhat familiar with the date command. Up until recently I had no reason to go beyond the typical use cases like the following:

1
2
3
4
5
6
7
# locale’s date & time
% date +%c
Fri 22 Jul 2011 10:22:29 PM EDT
 
# full date
% date +%F
2011-07-22

However, the problem came up where I needed […] Continue reading

Posted in linux, one-liner, shell, Syndicated, tips & tricks | Comments Off on [one-liner]: Making the Linux date Command Display the Month & Day in Single Digits

[one-liner]: Command-line Fu … Useful Linux Commands (repost)

Background

Came across these commands on another blog and wanted to create my own personal copy of these useful command-line examples.

Commands

1
2
3
4
% sshfs name@server:/path/to/folder /path/to/mount/point
# Mount folder/filesystem through SSH
# Install SSHFS from http://fuse.sourceforge.net/sshfs.html
# Will allow you to mount a folder security over a network.

1
2
3
4
5
% !!:gs/foo/bar
# Runs previous command replacing foo by bar every time that foo appears
# […] Continue reading

Posted in linux, one-liner, shell, Syndicated, sysadmin, tip, tips & tricks | Comments Off on [one-liner]: Command-line Fu … Useful Linux Commands (repost)