Sie sind auf Seite 1von 13

Linux Troubleshooting Tricks

Research Computing Support Group


Division of Information Technology
http://www.rcsg.rice.edu/
<rcsg@rice.edu>
@ricercsg on Twitter
Chandler Wilkerson
chwilk@rice.edu

Set Up Your Environment

For bash users, some


great tweaks:
Edit ~/.bashrc to add
aliases and environment
variables you will use
often
Use env to see your
current environment

$ source ~/.bashrc

# Check for interactive session


[ -z "$PS1" ] && return
# Colorize various outputs
# see what i'm looking for
export GREP_OPTIONS=--color=auto
# Make ls colorize by file type
alias ls="/bin/ls -F --color=auto
alias ll="/bin/ls -Fla --color=auto
# FiX up less
export LESS="-FiX"
# make sure everything uses less
export PAGER="less -FiX"
# history options
# 1st, don't put successive, duplicate
# commands in history file
export HISTIGNORE="&"
# 2nd, append each shell's history to my
# main history file on exit
shopt -s histappend

TAB TAB (Completion)

Save keystrokes by using command completion


(TAB key)
Learn some basic bash substitutions

!! repeat the last command

!$ repeat the last command's last argument

!?pat repeat the last command that included pat

!# repeat the command at position # in your history

GREP
Options worth knowing

-A # print # lines after

-v reverse match

-B # print # lines before

-c just count matches

-C # print # lines around

-l print filenames only

-o Only print the match

-i case insensitive

Context (what to print)

-r recursive (search
all files in directory)

'file' is Your Friend

file makes a well-educated guess what a file is


The following example was taken from Blue
Biou (IBM POWER7 ppc64 architecture) spot
the problem.

# file *
bam_aux.o:
bam_import.o:
bam_index.o:
bam_lpileup.o:
bam_md.o:
bam.o:
bam_pileup.o:
bam_reheader.o:
bam_sort.o:

ELF
ELF
ELF
ELF
ELF
ELF
ELF
ELF
ELF

64-bit
64-bit
64-bit
64-bit
64-bit
64-bit
64-bit
64-bit
64-bit

LSB
LSB
LSB
LSB
LSB
LSB
LSB
LSB
LSB

relocatable,
relocatable,
relocatable,
relocatable,
relocatable,
relocatable,
relocatable,
relocatable,
relocatable,

x86-64,
x86-64,
x86-64,
x86-64,
x86-64,
x86-64,
x86-64,
x86-64,
x86-64,

version
version
version
version
version
version
version
version
version

1
1
1
1
1
1
1
1
1

(SYSV),
(SYSV),
(SYSV),
(SYSV),
(SYSV),
(SYSV),
(SYSV),
(SYSV),
(SYSV),

not
not
not
not
not
not
not
not
not

stripped
stripped
stripped
stripped
stripped
stripped
stripped
stripped
stripped

Handling Lots of Files

First piece of advice is don't generate lots of


files. It breaks file systems.
The ls command sorts by default. Use -u to
avoid the penalty when directories grow huge
Pipe unsorted ls output to other commands (like
grep) to pare down the list
You can then pipe through sort if need be once
you have filtered it down to a reasonable size.

-h is for Human
The following utilities offer the -h flag to output (or
accept input) in human readable format.

df

# where is my quota being used?

du

$ du -h $HOME | sort -h

ls

$ ls -lh

sort

Take Care With Symlinks

Beware of trailing slashes when using rm and


symlinks
Try the following in a test directory:

$ mkdir a
$ touch a/test.txt
$ ln -s a b
$ ln -s a c
$ rm -ir b
$ rm -ir c/

Know your Linux Distro

It helps to know some


RPM commands
even if you're not the
system admin
Want to find more
documentation on
ssh?

$ which ssh
/usr/bin/ssh
$ rpm -qf /usr/bin/ssh
openssh-clients-5.3p1-84.1.el6.x86_64
$ rpm -qd openssh-clients
/usr/share/man/man1/scp.1.gz
/usr/share/man/man1/sftp.1.gz
/usr/share/man/man1/slogin.1.gz
/usr/share/man/man1/ssh-add.1.gz
/usr/share/man/man1/ssh-agent.1.gz
/usr/share/man/man1/ssh-copy-id.1.gz
/usr/share/man/man1/ssh-keyscan.1.gz
/usr/share/man/man1/ssh.1.gz
/usr/share/man/man5/ssh_config.5.gz
$ man ssh_config
...

SSH Faster

Ssh transfers going slowly? Simplify the


encryption overhead.

$ scp -c arcfour localfile remote:remotefile

Using rsync?

$ rsync -e ssh -c arcfour

SSH Faster

Ssh transfers going slowly? Simplify the


encryption overhead.

$ scp -c arcfour localfile remote:remotefile

Using rsync?

$ rsync -e ssh -c arcfour

SSH Keys

ssh-keygen -t rsa

Use a password (and ssh-agent (Mac, Linux)

ssh-copy-id (Linux only)

Watch the permissions on ~/.ssh and $HOME

Use -A to forward (tunnel) your agent

SSH Options

Commonly used options can go in ~/.ssh/config

See the ssh_config man page for options

HashKnownHosts yes

# Obscures where you ssh

Host *.rice.edu
# Wildcard host stanza
User myNetID
# Avoids -l or myNetID@
ForwardX11Trusted yes # automatically include -Y

Das könnte Ihnen auch gefallen