edit bash_tricks
This commit is contained in:
parent
6f54bad403
commit
b7fa4ab8c7
@ -12,6 +12,11 @@ See changes in a directory, as it changes:
|
|||||||
|
|
||||||
`watch -d ls *directory*`
|
`watch -d ls *directory*`
|
||||||
|
|
||||||
|
Or use the `-g` flag to exit once the output changes.
|
||||||
|
This command will look at whether you're connected to the internet, and turn into a rainbow once the connection hits.
|
||||||
|
|
||||||
|
> watch -g ip address && clear && ip address | lolcat
|
||||||
|
|
||||||
## Automatic Renaming
|
## Automatic Renaming
|
||||||
|
|
||||||
There are a bunch of files:
|
There are a bunch of files:
|
||||||
@ -34,17 +39,19 @@ done
|
|||||||
|
|
||||||
IFS is the field separator. This is required to denote the different files as marked by a new line, and not the spaces.
|
IFS is the field separator. This is required to denote the different files as marked by a new line, and not the spaces.
|
||||||
|
|
||||||
|
(Alternatively, just install `renameutils` and do `rename Column Alice *`)
|
||||||
|
|
||||||
## Arguments and Input
|
## Arguments and Input
|
||||||
|
|
||||||
The `rm' program takes arguments, but not `stdin' from a keyboard, and therefore programs cannot pipe results into rm.
|
The `rm' program takes arguments, but not `stdin' from a keyboard, and therefore programs cannot pipe results into rm.
|
||||||
|
To fix this, use `xargs` to turn the stdin into an argument.
|
||||||
That said, we can sometimes pipe into rm with `xargs rm' to turn the stdin into an argument. For example, if we have a list of files called `list.txt' then we could use cat as so:
|
For example, if we have a list of files called `list.txt' then we could use cat as so:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cat list.txt | xargs rm
|
cat list.txt | xargs rm
|
||||||
```
|
```
|
||||||
|
|
||||||
... *However*, this wouldn't work if spaces were included, as rm would take everything literally.
|
Of course if spaces are included in the file, you would have to account for that.
|
||||||
|
|
||||||
## Numbers
|
## Numbers
|
||||||
|
|
||||||
@ -71,3 +78,22 @@ find . -type f -exec md5sum '{}' ';' | sort | uniq --all-repeated=separate -w 15
|
|||||||
```bash
|
```bash
|
||||||
cat /dev/urandom | tr -cd [:alnum:] | dd bs=1 count=200 status=none && echo
|
cat /dev/urandom | tr -cd [:alnum:] | dd bs=1 count=200 status=none && echo
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Temporary Working Directory
|
||||||
|
|
||||||
|
Try something out in a random directory in `/tmp` so the files will be deleted when you next shut down.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mktemp -d
|
||||||
|
```
|
||||||
|
|
||||||
|
That gives you a random directory to mess about in.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
dir=$(mktemp -d)
|
||||||
|
for x in {A..Z}; do
|
||||||
|
fortune > "$dir"/chimpan-$x
|
||||||
|
done
|
||||||
|
cd $dir
|
||||||
|
```
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user