Navigation
Related:
Themes:
Here follow Bash commands that I've found useful and needed at some point. The order has not a particular meaning
alias a='alias'
alias sa='alias > ~/.bash_aliases && alias >> ~/.bash_aliases_history'
find
find . -path ./misc -prune -o -name '*.txt' -print
Source: Stackoverflow
tail -F <logfile>
But maybe you should stop using tail. Neat article, explaining the advantages of using:
less +F <logfile>
For following one file at a time, the latter has become my preference now.
To put some output to the beginning of a file (here 'todo.txt'):
echo -e "task goes here\n$(cat todo.txt)" > todo.txt
echo 'task goes here' | cat - todo.txt > temp && mv temp todo.txt
Source: superuser
So, generally:
echo $task | cat - $file > temp && mv temp $file
find . -name "foo*"
find files in folder recursively (Stackoverflow)
tee
./script_that_gives_output | tee store.file
e.g.:
ls -a | tee store.file
Ref.: redirect output to file and stdout
>
and >>
echo hoi > file.xt
echo
Make a file executable:
chmod +x
with a shebang in the first line of the script
#!/bin/bash
You can execute the file with:
./<file>
Without the chmod -x
you can do:
source <file>
Provided the shebang is in place.
A one-liner script that echoes the datetime:
$ while true; do echo "$(date '+%D %T')"; sleep 1; done
Hence, this will show the following in the terminal:
02/21/17 06:00:57
02/21/17 06:00:58
02/21/17 06:00:59
02/21/17 06:01:01
02/21/17 06:01:02
02/21/17 06:01:03
...
ls
To show all files, one per line, grouped by directories and file type:
$ l -1X --group-directories-first
$ alias l1="l -1Xr"
source
command, to activate script:source qn-venv/bin/activate
ctrl+r: reverse -i search
echo 'echo $1+"a"' > myscript
source myscript tad
> tada
First, second, third input in resp.: $1, $2, $3 et cetera.