# One-liners



## SirDice (Dec 10, 2008)

The things that make *nix famous. Crazy one-liners :e

Couple ones I found quite useful:


```
# tar -C /usr -cf - home | tar -C /storage/export -xvf -
```
Why not use cp or mv to move /usr/home to /storage/export/home? Weird things happen to hard and softlinks when you mv or cp. Try it and remember that a mv between different filesystems is actually a copy and delete.

A little variation on the theme:

```
# tar -C /usr -cf - home | ssh user@somemachine tar -C /storage/export -xvf -
```
But user@somemachine must have write access of course, so sometimes it's easier to pull instead of push:

```
# ssh user@somemachine tar -C /usr -cf - home | tar -C /storage/export -xvf -
```

You may want to add the *-z* switch to the tar commands. It will add compression but it depends on the type of data and your connection speed if it really improves transfer speeds.


----------



## vermaden (Dec 11, 2008)

For *ssh* options, add *-C* for slow connections (compresion) and *-c blowfish* so it will not use that much CPU time on slower machines.


----------



## hemi (Dec 17, 2008)

One of my personal favorites is one I worked up while trying to find a better font for my xterms. This will spew a bunch of xterms on to your screen (one for every monospace, scalable font recognized by X or whatever) with 'man ls' as the contents.


```
fc-list :spacing=mono:scalable=true family | sort | tr '\n' '\0' | xargs -0 -I FONT echo xterm -fg white -bg black -cr orange -T \'FONT\' -fa \'FONT\' -fs 12 -e man ls \& > xterm_test; sh xterm_test
```


----------



## estrabd (Jan 5, 2009)

Recursive search and replace in text file:

```
find . -name "*.txt" -type f -print | xargs perl -pi -e 's/xxx/aaa/g'
```

Rename files (and dirs):

```
find . -print | perl -ne 'chomp; next unless -e; $oldname = $_; s/aaa/bbb/; next if -e; rename $oldname, $_'
```

Zip up a directory and everything in it:

```
find ./dir_to_zip -print | xargs zip dir.zip
```

Summary: find and xargs are cool extremely useful.


----------

