Linux

From Rohidekar

Jump to: navigation, search

Deprecated


Master version is here:

Contents

Java

  • convert Date to long
  • String to Date


JUnit example, with running
hello world

Keyboard Shortcuts

  • *Ctrl-[left mouse button]* - Main Options menu
  • *Ctrl-[right mouse button]* - VT Options menu

Makefile troubleshooting

cd No such file or directory

  • The CDPATH environment variable screws up changing directory
    • Note: If CDPATH is an environment variable rather than local variable (cdpath in csh is local) it is exported between different shells
    • Solution: unsetenv CDPATH

Apache

Start

apachectl start

Commands - text manipulation

Align to columns

 column -t myfile.txt 
  • Thanks to UNIX Power Tools for this tip.
  • Not sure how to align by tabs instead of spaces.
 column -t -s ","
  • align by comma instead of space

Commands

apropos

  • apropos - search for a word in manual pages. So if you were looking for a command that dealt with email, you could type apropos email and it would tell you all manual pages that featured that word (and by implication all packages that have that word in their manuals).


>apropos emacs
ctags [etags]        (1)  - generate tag file for Emacs, vi
emacs                (1)  - GNU project Emacs
etags                (1)  - generate tag file for Emacs, vi
gnuclient [gnuserv]  (1)  - Server and Clients for XEmacs
gnuserv              (1)  - Server and Clients for XEmacs
xcscope.el [xcscope] (1)  - xemacs cscope lisp support package
xemacs               (1)  - Emacs: The Next Generation
ctags [etags]        (1)  - generate tag file for Emacs, vi
emacs                (1)  - GNU project Emacs
etags                (1)  - generate tag file for Emacs, vi
gnuclient [gnuserv]  (1)  - Server and Clients for XEmacs
gnuserv              (1)  - Server and Clients for XEmacs
xcscope.el [xcscope] (1)  - xemacs cscope lisp support package
xemacs               (1)  - Emacs: The Next Generation


Command line arguments

!:0
    • previous command name
!:1
    • 1st arg of previous command
!:2
    • 2nd arg of previous command
!:
    • all args from previous command

diff the contents of 2 dirs

  • =diff /myfiles/ /yourfiles/=

disk usage

du -hs * .[a-zA-Z]* | sort -n

duplicate removal

sort -u

environment summary info

@

environment variables

env

files listing (recursive)

find

find

find . -regex '.*java' -type f
find . -name "*jar" -exec jar -tf {} \;
find . -name "EGO*"
find $EGO_TOP -name EGOVALUESETLISTPG.xml
find -maxdepth 2
find | xargs grep Excel

http://www.hccfl.edu/pollock/Unix/FindCmd.htm

Exclude file name

  • find -not -name "MyFile.xml"

http://www.linuxforums.org/forum/linux-programming-scripting/66523-how-do-you-exclude-files-find-command.html

Exclude path name

  • find -not -regex ".*\.snapshot.*"

Sorting files by size

find . -type f | xargs ls -s1 | sort -n

Handling whitespace in find output

# we need the -print 0 and -0 to handle spaces in find output
find . -type f -print0 | xargs -0 ls -s1 | sort -n | tail -10

http://www.mydatabasesupport.com/forums/shell/177324-find-xargs-how-do-i-handle-space-path.html

With jar

find -type f -name "*jar" -exec unzip -l {} \;

FTP

grep exclude pattern

grep -v

group members

ypmatch g680 group
getent group g680

key bindings

(tcsh)

bindkey
  • Gives a list of the key bindings

kill

  • xkill

ls - one file per line

l -1

mkdir - create parent directories as needed

mkdir -p /org/apache/jakarta
  • Useful when creating new packages in Java

mount

  • \\mycomputer\vol\home1\myusername
sudo mkdir /scratch/myusername
sudo mount mycomputer:/scratch/myusername /scratch/myusername
sudo mount mycomputer:/scratch/myusername mounted
sudo umount mounted
sudo mount -r mycomputer:/scratch/myusername myusername


perl regex

Strips all newlines out of myfile.txt

perl -pe 's/\n/ /g' myfile.txt

Creates a copy command for all files listed in newline terminated fashion in the given file.

perl -pe 's{^(.*)\n}{cp $1 /scratch/;}g' temp__2007-03-27__15-56-03.txt

sed

  • Newline is difficult to work with because sed is line based.
  • Use Perl regex instead

Shell Key bindings

  • Bash
inputrc
  • Tcsh - .cshrc - put a bindkey line in
  • Look at the man pages of the shell you want for more info
    • for control sequences such as C-c for intr (interrupt)
stty -a

shell prompt

PS1='(\u) \W - \s \$'

shell type you're using

echo $SHELL

Sort

Sorting files by size

find . -type f | xargs ls -s1 | sort -n

tar

Creates a file called bug.tar based on all files in current directory and those below

tar -cvf bug.tar *

xargs

How do I specify a fixed argument AFTER an xargs piped argument?

Compare this:

echo -e "file1\nfile2\nfile3" | xargs echo '{}' blah

with:

echo -e "file1\nfile2\nfile3" | xargs -i echo '{}' blah

What you require is -i to make '{}' work. xargs by default appends the input as a list of arguments. The manpage says:

      --replace[=replace-str], -I replace-str, -i[replace-str]
             Replace occurences of replace-str in the initial  arguments  with  names
             read  from standard input.  Also, unquoted blanks do not terminate argu-
             ments.  If replace-str is omitted, it defaults to "{}" (like  for  'find
             -exec').  Implies -x and -L 1.

http://lists.centos.org/pipermail/centos/2005-February/044530.html

How do you launch an xterm on a different display?

xterm -display 144.20.207.128:214.0 &

xterm colors

dircolors --help

xterm configuration

~/xdefaults

whatis

> whatis tcsh
tcsh                 (1)  - C shell with file name completion and command line editing
tcsh                 (1)  - C shell with file name completion and command line editing


Window Makers

FVWM (Free Virtual Window Manager)

  • FVWM in a Tarantella environment is launched via ==.xinitrc== and ==.xinitrc-fvwm==
Key bindings
..local/fvwm-2.4.18/share/fvwm/themes/default/bindings

Ice WM

Key bindings
~/.icewm/keys
    • Alt-F3 - task shift (equivalent to Alt-TAB in Windows)

Window Makers

KDE

Key Bindings

Misc

Unpack an RPM without installing

Disable Bell

xset b 0

Shells

Bourne Shells (sh, bash)

Environment Variable setting

EDITOR=vi
export EDITOR

Loops

Regular
array=([key1]=value1)
for key in key1
do
  echo ${key} ${array[$key]}
done
Map (associative / key-value)
arrayName=( "/etc/passwd" "/etc/group" "/etc/hosts" )

for i in "${arrayName[@]}"
do
  echo $i
done

TCSH

Can you make the output of command n the input to command (n+1)?

  • No
New idea: use last line (or n'th line) of output as input to new command.

I often find myself typing something like:

>locate lshort /usr/local/stow/share/texmf/doc/latex/general/lshort.dvi . . . /usr/local/store/share/texmf/doc/latex/general/lshort.dvi

>xdvi /usr/local/store/share/texmf/doc/latex/general/lshort.dvi

Now the way I accomplish writing the last line, is by moving the mouse over the last line, and the copy paste it. It would be very nice, if the shell could keep the last n lines of output in a buffer. This way one could avoid using the mouse by typing something like:

>xdvi <M-1>

which would insert the last line of output, similarly <M-2> could insert the second last line of output. (the exact commands used is of course configured via bindkey).

This could save me a couple of times to the mouse everyday - di010070@diku.dk

    The shell does not capture any output from commands it runs, so this is really more a feature for the terminal (be it hardware or software). --Kim 

http://www.tcsh.org/WishList

How do I combine multiple commands in an alias?

You need to enclose it in single quotation marks.

Example

alias   d                       'mkdir \!^;cd \!^'


How do I pass arguments to an alias?

Use \!^

Example

alias   d                       'mkdir \!^;cd \!^'


Wildcard name

find . -name "*.html"


http://www.devdaily.com/unix/edu/examples/find.shtml

Execute command on each file

find . -exec chmod 644 {} \;


http://www.devdaily.com/unix/edu/examples/find.shtml

How do I clear the directory stack?

set dirstack=()


TCSH Key bindings

TCSH Key bindings

SSH

passwordless login

  • Basically, you need ssh-copy-id

http://everydaylht.com/howtos/system-administration/loggin-in-via-ssh-without-a-password/

USB

How do I know which device file my thumb drive maps to?

Everywhere on the web I searched for how to do this, it told me that /dev/sda1 is the location to mount - but for whatever reason that wasn't the case for me. Here is the more reliable way to do it:

Go to:

 /dev/disks/by-label

List the symbolic link targets of the files in that directory:

 ls -l

Hopefully you'll recognize the label of your thumb drive. See what file that links to. In my case, it was sdb1 (I think sdb and sdb1 are the two front USB ports on the tower). So mount it as follows:

 mkdir ~/usb/
 sudo mount /dev/sdb1 ~/usb
Personal tools